-
November 19th, 2010, 05:12 AM
#1
Calling WM_PAINT or its equivalent with a Button Control
In this pseudo code I am trying to display a selected bitmap by clicking on a button...
Code:
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BTN_ROLL:
{
case WM_PAINT:
{
if(condition...)
hDC = BeginPaint(hwndDlg, &Ps);
bmpFull = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
MemDCFull = CreateCompatibleDC(hDC);
SelectObject(MemDCFull, bmpFull);
BitBlt(hDC, 50, 50, 112, 112, MemDCFull, 0, 0, SRCCOPY);
DeleteDC(MemDCFull);
DeleteObject(bmpFull);
EndPaint(hwndDlg, &Ps);
return TRUE;
}
}
}
I am pretty sure this cannot function that way. Would WM_PRINT or WM_PRINTCLIENT be of more use? They are mentioned as alternatives to WM_PAINT in the following quote from MSDN:
"The WM_PAINT message is generated by the system and should not be sent by an application. To force a window to draw into a specific device context, use the WM_PRINT or WM_PRINTCLIENT message. Note that this requires the target window to support the WM_PRINTCLIENT message. Most common controls support the WM_PRINTCLIENT message."
ANy tips or more realistic code examples are welcome...
-
November 19th, 2010, 07:37 AM
#2
Re: Calling WM_PAINT or its equivalent with a Button Control
Maybe I am asking the wrong question...
How do I get a Button Control to trigger a bitmap to be displayed in a dialog?
I can display a bitmap but only in a default type way, which means I cannot figure out how to make a bitmap appear following a mouse click on a Button in a specified location - or be dynamic so to speak.
So any tips on what Message to send or the configuration of the case structure would be really excellent.
-
November 19th, 2010, 10:28 AM
#3
Re: Calling WM_PAINT or its equivalent with a Button Control
what is the "case WM_PAINT:" doing in your button handler? It should be a separate case on the same level as WM_COMMAND. What you need to do is ONLY paint in the WM_PAINT handler (the correct one). Use a flag that can be set in your button handler that tells your WM_PAINT routine what bitmap to paint, then call Invalidate() to force a repaint.
-
November 19th, 2010, 11:19 AM
#4
Re: Calling WM_PAINT or its equivalent with a Button Control
hoxsiew...
I know my example is incorrect - I posted it like that to show the problem I was trying to convey, not how I expected it to actually work...
BUT - I think I have a better idea of how to work through it from your suggestion of using a flag in the button handler.
If you have the time, could you please elaborate on how to implement the flag? Possibly with some example code?
Thanks for your reply BTW
-
November 19th, 2010, 12:16 PM
#5
Re: Calling WM_PAINT or its equivalent with a Button Control
Well, using your code above, try something like this:
Code:
static int flag=0;
//...
switch(msg){
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDC_BTN_ROLL:
flag=1;
InvalidateRect(hwnd, NULL, TRUE);
return TRUE;
}
case WM_PAINT:
hDC = BeginPaint(hwndDlg, &Ps);
if(flag){
bmpFull = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
}else{
bmpFull = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
}
MemDCFull = CreateCompatibleDC(hDC);
SelectObject(MemDCFull, bmpFull);
BitBlt(hDC, 50, 50, 112, 112, MemDCFull, 0, 0, SRCCOPY);
DeleteDC(MemDCFull);
DeleteObject(bmpFull);
EndPaint(hwndDlg, &Ps);
return TRUE;
}
-
November 19th, 2010, 11:43 PM
#6
Re: Calling WM_PAINT or its equivalent with a Button Control
Thanks hoxsiew,
Now that I have a really good idea on how to load different bitmaps, the next matter is how can I load bitmaps to multiple locations following the code you supplied?
edit:
I tried this and it seems to be a start:
Code:
if(flag)
BitBlt(hDC, 50, 50, 112, 112, MemDCFull, 0, 0, SRCCOPY);
else
BitBlt(hDC, 80, 50, 112, 112, MemDCFull, 0, 0, SRCCOPY);
what do you think?
Last edited by Morbane; November 19th, 2010 at 11:48 PM.
-
November 20th, 2010, 09:30 AM
#7
Re: Calling WM_PAINT or its equivalent with a Button Control
IS it possible, using these examples, to have multiple bitmaps in multiple locations, all able to be changed?
-
November 20th, 2010, 03:14 PM
#8
Re: Calling WM_PAINT or its equivalent with a Button Control
Sorry, but the answer is pretty apparent as for me: everything's possible in case you follow design principles and programming instructions. Though not sure about "using these examples" as long as there's absolutely nothing special in the last hoxsiew's snippet, therefore there's no any ground for doubts.
PS. It's very important to understand what lines make an elementary template for a single bitmap to apply this approach to multiple region updates.
PPS. Let's remember that any engineering solution is just a combination of elementary tasks put together proper way, at proper time, in proper order.
Last edited by Igor Vartanov; November 20th, 2010 at 03:27 PM.
Best regards,
Igor
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
|