• Advertisement
Sign in to follow this  

window color

This topic is 4434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

dose Window Background support RGB color, or is only support HBRUSH color ? if it support RGB color how can I do it ?

Share this post


Link to post
Share on other sites
Advertisement
Don't forget to delete the brush afterwards. I think Windows XP might clean up after your application terminates, but Windows 9x doesn't. Regardless, it's good practice to release the resources you aquire manually.

Share this post


Link to post
Share on other sites
I got another question, How to clear window, for example I draw something on Window, but now I want to clear it, which WinAPI function should I use?

Share this post


Link to post
Share on other sites
-edit- I had to modify my original code because I realized there was a mistake in WM_PAINT. It's not the best solution and is likely to introduce other unwanted effects, like everything else in Win32. One of the most frustrating things of working with the API is that if you change one thing, something else might not work, and if you change that something else, something else, also might not work. So be very vigilant. -edit-

Call, InvalidateRect(hwnd, NULL, TRUE); The symbolic constant TRUE causes your program to recieve a WM_ERASEBKGND message. But you also have to keep in mind that you'll also recieve a WM_PAINT message. Actually, you first will recieve a WM_PAINT but during the call to BeginPaint, this function will check if the member ps.fErase of the PAINTSTRUCT structure is set. If it is set ( != 0 ), then BeginPaint will send a WM_ERASEBKGND message. If you only want to clear the background and not redraw, you can do something like this:



static PAINTSTRUCT ps;
static BOOL bool_paint = FALSE;

case WM_PAINT:

hdc = BeginPaint(hwnd, &ps);

if ( bool_paint != FALSE )
{

// paint stuff here

}

EndPaint(hwnd, hdc);
return 0;

case WM_EARSEBKGND:
hdc = GetDC(hwnd);

//erase background

if ( ps.fErase != FALSE )
bool_paint = FALSE;

ReleaseDC(hwnd, hdc);
return 1;


InvalidateRect, like shown above, sets the clipping region to the whole client area, this means that if this function is called, then BeginPaint will return a handle to the whole client area (you'll be able to paint anywhere in your client area). Let me also point out something else you should be aware of if you go this route. If you do not handle WM_ERASEBKGND yourself, The only erasing that's going to be done here is in the clipped region, same clipped region BeginPaint recieves. For example, if a another window partially overlaps your window, WM_ERASEBKGND will only erase that part. So if you want to erase the whole client area, regardless of the current cliped region, you would need to handle WM_ERASEBNGD yourself and use GetDC in this handler. <-- unnecessary.

If you want to avoid going through all this trouble and you want to erase the background from outside of WM_PAINT, you can just do something like this:


hdc = GetDC(hwnd);

RECT rect;
GetClientRect(hwnd, &rect);
FillRect(hwnd, &rect, GetCurrentObject(hdc, OBJ_BRUSH));

ReleseDC(hwnd, hdc);
return 0;





xeddiex.

[Edited by - xeddiex on January 2, 2006 11:10:19 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement