WM_PAINT function, how to call again?

This is a discussion on WM_PAINT function, how to call again? within the C++ Programming forums, part of the General Programming Boards category; Ok here is the situation. I loaded a bitmap to the screen using windows GDI. I did this in the ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    26

    WM_PAINT function, how to call again?

    Ok here is the situation. I loaded a bitmap to the screen using windows GDI. I did this in the WM_PAINT function. Now what I want to do is when a user clicks on a file menu, the screen must become all clear. My question is how do I call the WM_PAINT function again to clear the screen? If I just write:

    Code:
    case ID_FILE_NEW:
    
                         WM_PAINT;
    		{
    			// Just a note, never use a MessageBox from inside WM_PAINT
    			// The box will cause more WM_PAINT messages and you'll probably end up
    			// stuck in a loop
    
    			BITMAP bm;
    			PAINTSTRUCT ps;
    
    			HDC hdc = BeginPaint(hwnd, &ps);
    
    			HDC hdcMem = CreateCompatibleDC(hdc);
    			HBITMAP hbmOld = SelectObject(hdcMem, Logobmp);
    
    			GetObject(Logobmp, sizeof(bm), &bm);
    
    			BitBlt(hdc, 100, 50, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
                BitBlt(hdc, 0, 0, 800, 600,hdc, 0, 0, WHITENESS);
    			SelectObject(hdcMem, hbmOld);
    			DeleteDC(hdcMem);
    			EndPaint(hwnd, &ps);
    		}
    nothing happens, the white background does't copy over the picture. However if I write the same code in the WM_PAINT function than it does.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    WM_PAINT is a message sent to your window, where you handle it is a case in a switch statement not a function allthough you could call a function in the WM_PAINT case.
    You can either send the WM_PAINT message yourself with SendMessage or call UpdateWindow. You can also call InvalidateRect on your window but that might not send WM_PAINT right away.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    26
    hmm, is it possible to call an if statement within WM_PAINT such as:

    Code:
    case WM_PAINT:
    		{
    			// Just a note, never use a MessageBox from inside WM_PAINT
    			// The box will cause more WM_PAINT messages and you'll probably end up
    			// stuck in a loop
    
    			BITMAP bm;
    			PAINTSTRUCT ps;
    
    			HDC hdc = BeginPaint(hwnd, &ps);
    
    			HDC hdcMem = CreateCompatibleDC(hdc);
    			HBITMAP hbmOld = SelectObject(hdcMem, Logobmp);
    
    			GetObject(Logobmp, sizeof(bm), &bm);
    
    			BitBlt(hdc, 100, 50, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    			if (ClrScreen >= 0){
                 BitBlt(hdc, 0, 0, 800, 600,hdc, 0, 0, WHITENESS);
                 }
                              
    
    			SelectObject(hdcMem, hbmOld);
    			DeleteDC(hdcMem);
    
    			EndPaint(hwnd, &ps);
    		}
    		break;
    And than set the int ClrScreen to something greater than 0 and call WM_PAIT again:

    Code:
    case ID_FILE_NEW:
                         ClrScreen = 1;
                         PostMessage(hwnd, WM_PAINT, 0, 0);
    However this doesn't work either for some reason.

    EDIT: got it working with InvalidateRect(hwnd, NULL, FALSE ); instead of postmessege
    Last edited by Brigs76; 04-19-2005 at 04:18 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21