Updating a Window after sending WM_PAINT

Started by
12 comments, last by Rodaxoleaux 12 years, 7 months ago
Is there any way to update a window after sending WM_PAINT besides ShowWindow(hwnd, NULL) then ShowWindow(hwnd,SW_SHOW)?
Advertisement
The GetDC & ReleaseDC procedures let you paint where&when ever you want,

So, you are not restricted to paint|repaint only when WM_PAINT messages occur.
You can use some sort of timer mechanism ( &| other event triggers ) to update your view.
One of the redraw functions (UpdateWindow, RedrawWindow, InvalidateRect) is what you probably want.

Also, note that you should never send WM_PAINT to a window. The OS sends that for you, usually in response to one of the above functions or some other "smart" factor that knows you need to repaint your window. See WM_PAINT.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Ok, that works, but if I erase some of the string and try to type more, it'll keep the string that's already there, and write behind it.
I have no clue what you're talking about...

Maybe you should describe what you are doing, and optimally post your code?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Basically, I'm creating a sort-of terminal window with user input for typing commands, etc. the current user-inputted data is stored in a string, and the string is drawn to the window as so in the message handling function:
LRESULT CALLBACK Messages(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
switch (Msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_HOTKEY:
WindowState = !WindowState;
ToChangeWindow = true;
break;

case WM_PAINT:

hDC = GetDC(hwnd);
SetBkMode(hDC,TRANSPARENT);
SetTextColor(hDC,RGB(255,255,255));
TextOut(hDC,10,30,(LPSTR)currentCommand.c_str(),currentCommand.length());
ReleaseDC(hwnd,hDC);

break;

default:
return DefWindowProc(hwnd, Msg, wParam, lParam);
}

return 0;
}


I can type it just fine and it will output what I want, but when I delete a character from the string (Backspace), it deletes a character fine, but it doesn't update the window and instead draws behind the already outputted text.
Think about what SetBkMode(hDC, TRANSPARENT); does ;-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Didn't know that it just leaves the background. Thanks but it still produces the same result after changing to OPAQUE and setting the background color. What else could cause it? It always seems to work if I hide and reshow the window whenever backspace is pressed but... that seems rather inefficient..
What code are you using to ask the window to erase its background?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I tried sending WM_ERASEBKGND and using FillRect() but that doesn't help. Although honestly, since this is my first time working with Win32, I thought it did it itself.

case WM_PAINT:

hDC = GetDC(hwnd);
SetBkMode(hDC,OPAQUE);
SetBkColor(hDC,RGB(253, 208, 23));
SetTextColor(hDC,RGB(255,255,255));
TextOut(hDC,10,30,(LPSTR)currentCommand.c_str(),currentCommand.length());
ReleaseDC(hwnd,hDC);

RECT r;
GetWindowRect(hwnd,&r);

FillRect(hDC,&r,orangish);

break;

This topic is closed to new replies.

Advertisement