Discussion:
redraw entire content
(too old to reply)
steve
2011-02-23 00:04:33 UTC
Permalink
Hey Guys,
okay, still learning...,

let's assume I open a single gui window and draw some text on it via
WM_PAINT, (which is in my wndproc() function), like below:

[code]
case WM_PAINT:
hdc = GetDC(hwnd);
BeginPaint(hwnd, &ps);

GetClientRect(hwnd, &rect);
DrawText(hdc, "Hello World!.", -1, &rect, DT_SINGLELINE |
DT_CENTER | DT_VCENTER);

EndPaint(hwnd, &ps);
ReleaseDC(hwnd, hdc);
break;
[/code]

then, else where, (in another function) I issue a gdi line-draw
command like so:

[code]
void DrawLine(HWND hwnd)
{
int x1=50, y1=50, x2=50, y2=150;
HDC myhDC;

myhDC = GetDC(hwnd);

MoveToEx(myhDC, x1, y1, NULL);
LineTo(myhDC, x2, y2);

ReleaseDC(hwnd, myhDC);
}
[/code]

In the center of my window I have text that reads "Hello World!" and
near the upper left corner, I have a 100 pixels long line.
I can drag my window all over the screen and my two objects remain in
tact.
However, if I cover my window with another window, only the text
remains when I toggle back to my window. The gdi line is no longer
displayed.

How would I get windows to redraw the entire contents of the window,
including the gdi line I have drawn ?
David Lowndes
2011-02-23 00:56:44 UTC
Permalink
Post by steve
hdc = GetDC(hwnd);
BeginPaint(hwnd, &ps);
BeginPaint returns you the HDC you're supposed to use - there's no
need to use GetDC/ReleaseDC in a WM_PAINT handler.
Post by steve
However, if I cover my window with another window, only the text
remains when I toggle back to my window. The gdi line is no longer
displayed.
How would I get windows to redraw the entire contents of the window,
including the gdi line I have drawn ?
You need to do all the drawing in the WM_PAINT handler. If you want to
also draw from some other event, you need to duplicate that in the
WM_PAINT hander.

Dave
steve
2011-02-23 17:31:41 UTC
Permalink
Post by David Lowndes
You need to do all the drawing in the WM_PAINT handler. If you want to
also draw from some other event, you need to duplicate that in the
WM_PAINT hander.
Dave
Hmmm..., thanks Dave.
steve
2011-02-23 21:57:17 UTC
Permalink
Post by David Lowndes
You need to do all the drawing in the WM_PAINT handler. If you want to
also draw from some other event, you need to duplicate that in the
WM_PAINT hander.
Dave
Actually..., I've just been reading about "double buffering".
It seems that I can do all my drawing in the background, onto a
primary screen buffer and then, in WM_PAINT, BitBlt the buffer onto
the foreground display area.
That would allow me to have seperate drawing functions and then
invalidate and update the display area at will.

Loading...