Originally Posted by
novacain
That is because each paint message you are creating, using and destroying the memory DC.
You should;
Create the memory DC once, when the form is created.
Destroy the memory DC (and/or its selected GDI objects) as few times as possible, when the form closes and resizes.
Most importantly your paint should only be a BitBlt(), of the memory DC to the DC from the paintstruct using the rect in the paintstruct.
When some event (timer, user input, etc) requires a screen change you redraw the memory DC and generate a paint message.
The paint message should be the minimum size / rect possible and should be sent directly to the forms callback (using UpdateWindow()).
I have previously posted full code.
EDIT: Not sure if it still applies to latest .NET IDEs...
When you create a DC it has default GDI objects (ie BITMAP)
When you SelectObject() your created BITMAP it pushes out the default one (as the return from SelectObject()).
You should catch this return from SelectObject() because the created BITMAP (and other created GDI objects) may not delete while selected into a DC .
It is good practice to return the created DC to its default state by using SelectObject() to return the default GDI objects you pushed out (with created ones).
i did what you said:
Code:
static LRESULT CALLBACK WndProcForm(HWND HandleWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
static POINT PreviousLocation, Location;
static bool Tracking = false;
static MouseButtons MBButtons;
static bool blControl = false;
static bool blShift = false;
static bool blResize = false;
static int xPos = 0;
static int yPos = 0;
static UINT_PTR timerid=0;
static UINT_PTR JoystickTimer=1;
static bool blnDrag = false;
static bool KeyPressed=false;
static int KeyDownCount=0;
HDC hdcimage = CreateCompatibleDC(NULL);
HBITMAP hbitmap=NULL;
//UINT JoystickCount =0;
//..............
//Working with messages
switch(msg)
{
case WM_ERASEBKGND:
return (LRESULT)1;
case WM_PAINT:
{
if (inst->Paint==NULL) break;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(inst->hwnd, &ps);
int width=ps.rcPaint.right-ps.rcPaint.left;
int height =ps.rcPaint.bottom-ps.rcPaint.top;
hbitmap=CreateBitmap(width,height,1,32,NULL);//create the bitmap with icon size
SelectObject(hdcimage, hbitmap);
FillRect(hdcimage,&ps.rcPaint,CreateSolidBrush(inst->clrBackColor));
inst->Paint(inst->hwnd,hdcimage);
BitBlt(ps.hdc,0,0,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,hdcimage,0,0,SRCCOPY);
EndPaint(inst->hwnd, &ps);
}
break;
case WM_DESTROY:
{
DeleteObject(hbitmap);
DeleteDC(hdcimage);
joyReleaseCapture(JOYSTICKID1);
--FormCount;
if(FormCount == 0)
End();
}
break;
}}
the flicker continues with child controls