|
-
November 10th, 2005, 07:43 AM
#1
GDI - Repaint
Hi everyone,
While I was using GDI, i noticed that when the window is minimized, resized or has a child window that covers it, the drawing disappears. Is there a way to solve this problam, redraw the painting?
Thanks in advance.
-
November 10th, 2005, 07:59 AM
#2
Re: GDI - Repaint
Windows will send a WM_PAINT message to a window when it needs to repaint itself. In Windows (prior to Windows Vista), the screen is represented by 1 big pixel buffer. When you move a window on top of another window, the pixels of the background window are lost. When you make the background window visible again, Windows will send a WM_PAINT message to the window so it can redraw itself.
That is the reason why all drawing should be done in your WM_PAINT handler and not somewhere else.
-
November 10th, 2005, 08:12 AM
#3
Re: GDI - Repaint
 Originally Posted by Marc G
Windows will send a WM_PAINT message to a window when it needs to repaint itself. In Windows (prior to Windows Vista), the screen is represented by 1 big pixel buffer. When you move a window on top of another window, the pixels of the background window are lost. When you make the background window visible again, Windows will send a WM_PAINT message to the window so it can redraw itself.
That is the reason why all drawing should be done in your WM_PAINT handler and not somewhere else.
It would have been fine, but in my program I have buttons with a dynamic text. How do I trace if they're getting a WM_PAINT message?
-
November 10th, 2005, 08:44 AM
#4
Re: GDI - Repaint
Are you drawing anything yourself? If so, where do you do your drawing? Can you post some code?
-
November 10th, 2005, 11:28 AM
#5
Re: GDI - Repaint
Sure.
I Put this code, to draw all my buttons (I'm making a sudoku solving program) in the WM_CREATE of the main window:
Code:
for (count = 1 ; count <= 81 ; count++)
{
button[count].hButton = CreateWindowEx(WS_EX_CLIENTEDGE
, "BUTTON", "", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,
(i * 55 - 55), (j * 55 - 55), //xy position, not very importent
52, 52, ProcWnd, (HMENU)(500 + count), GetModuleHandle(NULL), NULL);
//assign HDC
button[count].hdc = GetDC(sudoku.button[count].hButton);
}
-
November 10th, 2005, 01:14 PM
#6
Re: GDI - Repaint
Why are you storing all those DC's?
What do you do with them?
-
November 10th, 2005, 01:19 PM
#7
Re: GDI - Repaint
 Originally Posted by Marc G
Why are you storing all those DC's?
What do you do with them?
I send them to a function that draws them every change occures, It's like would should be in the WM_PAINT message, but since I can't track it, the drawing funciton is called every time a change is made in the button's information (According to the program's calculations, I don't think it's relevent to go into it).
-
November 10th, 2005, 01:30 PM
#8
Re: GDI - Repaint
I tried to insert this code in the main message loop:
Code:
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
MainLoop(); //do the main loop of the program
TranslateMessage(&Msg); //translate the message so that WndProc can understand
/////////////////Supposed to take care of the button drawing issue
for (i = 1 ; i <= 81 ; i++)
if ( (Msg.hwnd == button[i].hButton) && (Msg.message == WM_PAINT))
drawButton(button[i].hdc, i);
/////////////////
DispatchMessage(&Msg); //send the message to WndProc
}
But it still doesn't draw it. Perhaps it just doesn't really send the WM_PAINT message to the buttons.
-
November 10th, 2005, 01:35 PM
#9
Re: GDI - Repaint
You are not reading my replies.
All drawing in Windows should happen in response to WM_PAINT.
So, if you want to redraw a button, you simply call InvalidateRect which will indirectly call your WM_PAINT handler.
-
November 10th, 2005, 01:45 PM
#10
Re: GDI - Repaint
I finally Got it! Thank you very much for your help!
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
|