I want to show a line in a window
-
by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?
-
by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?
What problem with this code? and i said you about WM_CREATE & WM_PAINT
_**
**_
WhiteSky
-
by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?
bloodwinner wrote:
case WM_CREATE to realise it
WM_CREATE: The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible. WM_PAINT: The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window ie when we want to draw something on the window.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
What problem with this code? and i said you about WM_CREATE & WM_PAINT
_**
**_
WhiteSky
there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.
-
there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.
Because when it receives the WM_PAINT message, the window will be redrawn and thus if you don't redraw your line too, it will be erased.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?
Run notepad, and calculator. Drag the notepad over the calculator. Move it away. Why does the calculator redraw itself ? The answer is, it generates a WM_PAINT message, windows uses this to tell a window to repaint itself. If you draw outside WM_PAINT, then your window will lose what you draw when it redraws itself.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.
And From the MSDN: WM_CREATE: This message is sent when an application requests that a window be created
_**
**_
WhiteSky
-
by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?
Because when Windows wants to repaint a window, because an obscured part was exposed or for another reason, it sends a
WM_PAINT
message to the window to get it to repaint itself. If you put the rendering code elsewhere you'll see the rendering but when a part of the window is obscured and then exposed (or for some other reason needs to be re-rendered) theWM_PAINT
handler will regenerate the image but it will not include the line. Aside from this I suspect theWM_CREATE
handler is too early anyway. This situation is set to change with Vista's DWM but still theWM_PAINT
handler will remain the correct place to perform most rendering operations.Steve