Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flickering window region

Status
Not open for further replies.

wanmaster

Programmer
Nov 20, 2000
94
NL
Hi,

I've got a graphical problem using a window region. The application I'm making is a sort of screenmate. It's a ball (the elliptic rgn) with a "3d-picture" that bounches on the window's taskbar. You can pick it up en throw it around.

This all works fine, the only problem is that it flickers.
It makes the image blurry and sometimes you can see the window's original rectangle.

The code is really simple (in order of execution):

- winmain, register wnd class, create wnd etc.
- create & apply region (80x80 px), show window
- main loop:
- update position (based on velocity, gravity etc.)
- move window to new position

and in windowproc
- WM_PAINT: bitblt bmp (dc created using createcompatible dc & select bmp into new dc, no rocket science here..)

I first wrote it in vb, but I ended up using so many winapi calls and subclassingmy own window, I decided to switch to c++. The vb-code didn't work much better anyway.

I hope someone can give some advice or tips..
(and please tell me if you need more information about the code).

Remedy
 
I'll give you the complete windowproc:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

PAINTSTRUCT ps;
HDC hdc; //window dc
static HBITMAP hbmp; //handle to (resource) bitmap
static HDC hdcComp; //dc for copying bitmap

switch (message)
{

case WM_ERASEBKGND:
return (LRESULT)1; //override (don't need to erase background)
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
BitBlt(hdc, 0, 0, B_DIMENSION, B_DIMENSION, hdcComp, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
break;
case WM_CREATE:
hbmp = LoadBitmap(hInst, (LPCTSTR)IDB_MB); //load bitmap (get handle)
hdc = GetDC(hWnd); //get window dc
hdcComp = CreateCompatibleDC(hdc); //create compatible dc
SelectObject(hdcComp, hbmp); //select bitmap into comp. dc
ReleaseDC(hWnd, hdc); //release window dc
break;
case WM_MOUSEMOVE:
if (wParam==1 && !bMenu) //left mouse button
{
bDrag = true;
ResetPosition();
ReleaseCapture();
SendMessage(hWndMain, WM_NCLBUTTONDOWN, HTCAPTION, 0);
bDrag = false;
SetDragPosition();
}
break;
case WM_MOVE:
if (bDrag) SetBallDrag(lParam); //keep track of dragging
return DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_RBUTTONDOWN:
if (!bMenu)
{
bMenu = true;
ShowPopupMenu();
bMenu = false;
}
break;
case WM_DESTROY:
TermBall(); //destroy region etc..
DeleteDC(hdcComp); //destroy comp. dc
DeleteObject(hbmp); //destroy hBmp
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
 
remedy,

I didn't get this from your first post until your code woke me up, I guess, or I'm just dull maybe ;0)

>> - main loop:
>> - update position (based on velocity, gravity etc.)
>> - move window to new position

This approach is going to flicker etc.

You need to actually paint within a window to different positions rather than having the OS move a window.

DirectX would be another way to go as well.

Hope this helps
-pete
 
That's not possible. It can't be a full-screen app. It must be a window that moves around, interacts with other windows and leaves the other windows accessible. If it would be something like a screensaver, your suggestion would be right.

So thanks, but I'm afraid it won't solve the problem..

Remedy
 
Based on those requirements you might want to nose around MSDN looking for Microsoft Agent information.

Good luck
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top