-
December 15th, 2012, 05:55 PM
#1
[RESOLVED] A little help! WM_PAINT + BMP
Hiho,
I just want to put a background image in my app, apparently works well but not, after a few clicks to resize it, my pc slow down, and I do not see the problem or may be my code wrong...accept help and suggestions! && light my way!
Code:
//Warnings 0
//GetLastError No Error
RECT rc;
GetClientRect (wp_hwnd, &rc);
HDC hdc_dst = GetDC (wp_hwnd);
HDC hdc_src = CreateCompatibleDC (hdc_dst);
HBITMAP bg_image = LoadBitmap (GetModuleHandle(NULL), MAKEINTRESOURCE (IDM_BGBMP));
BITMAP bm;
PAINTSTRUCT ps;
switch (wp_msg)
{
case WM_PAINT:
BeginPaint (wp_hwnd, &ps);
GetObject (bg_image, sizeof (bm), &bm);
SelectObject (hdc_src, bg_image);
StretchBlt (
hdc_dst,
0,0,
rc.right, rc.bottom,
hdc_src,
0, 0,
bm.bmWidth, bm.bmHeight,
SRCCOPY);
DeleteObject (&bg_image);
ReleaseDC (wp_hwnd, hdc_dst);
DeleteDC (hdc_src);
DeleteObject (&bm);
EndPaint(wp_hwnd, &ps);
break;
case WM_SIZE:
SendMessage (wp_hwnd,WM_PAINT,0,0);
break;
-
December 15th, 2012, 10:59 PM
#2
Re: A little help! WM_PAINT + BMP
Originally Posted by v_nom70
Hiho,
I just want to put a background image in my app, apparently works well but not, after a few clicks to resize it, my pc slow down, and I do not see the problem or may be my code wrong...accept help and suggestions! && light my way!
You should really check your return values for those functions you're calling. You're just assuming they work without seeing if any of them return an error.
Code:
DeleteObject (&bg_image);
Why are you passing the address of an HBITMAP to DeleteObject?
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
If you checked the return value of DeleteObject, does it return 0 or non-zero? If it is zero, then you would have discovered the problem is with this function.
Regards,
Paul McKenzie
-
December 16th, 2012, 04:41 AM
#3
Re: A little help! WM_PAINT + BMP
BITMAP is just a structure intended to get bitmap info. This is not a GDI object, so DeleteObject(&bm) makes no sense. The deleted object should be HBITMAP bg_image. But with this you have another problem: you never unselect it prior to deleting hdc_src. However you must do that:
Code:
HBITMAP hbmOld = SelectObject(hdc_src, bg_image);
. . .
SelectObject(hdc_src, hbmOld); // unselecting bg_image
// now you're allowed to delete
DeleteObject(bg_image);
DeleteDC(hdc_src);
Best regards,
Igor
-
December 16th, 2012, 09:50 AM
#4
Re: A little help! WM_PAINT + BMP
mmm ok's im testing now... thanks guys.
-
December 27th, 2012, 11:36 AM
#5
Re: A little help! WM_PAINT + BMP
Do you really need to load your image in response to EVERY windows message you get? (hint – no, you don’t).
Since you only attempt to delete this HBITMAP while processing WM_PAINT message, all other ones are leaking.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 3rd, 2013, 05:52 PM
#6
Re: A little help! WM_PAINT + BMP
2 OP:
You should not (must not!) send WM_PAINT message (in response on the WM_SIZE)
Instead you should (if you really need to) call InvalidateRect which will cause Windows to send WM_PAINT message to your window.
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|