- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to paint the background of the main window as follows:
wc%hbrBackground = NULL ! in WinMain before registering the class
case (WM_ERASEBKGND) ! in the MainWndProc
iret = DeleteObject(hBrush)
hBrush = CreateSolidBrush(myColor) ! myColorassigned elsewhere
wc%hbrBackground = hBrush
MainWndProc = 0
return
I can paint the window background using either FillRect or FillRgn, but I would like to learn how to useWM_ERASEBKGND and wc%hbrBackground in the MainWndProc to do so. Thanks in advance.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Usually, you don't need to handle WM_ERASEBKGND. It goes like this: every time a window has to be repainted, you get a WM_ERASEBKGND followed by WM_PAINT. If you just forward WM_ERASEBKGND to DefWindowProc, it willdo a(internally) FillRect(GetClassLong(hWnd, GCL_HBRUSH)), effectively erasing the background. If GetClassLong(hWnd, GCL_HBRUSH) (=wc%hbrBackground) is empty, it does nothing. Thus, if you don't do it yourself, DefWindowProc will do it for you.
However... if your WM_PAINT block fills entire client area, you really don't need any background erasing; that means you can leave wc%hbrBackground=NULL and not handle WM_ERASEBKGND, as it would be a pure waste of time & source of flickering to erase something (on WM_ERASEBKGND) and then refill it immediately with something else (on WM_PAINT)
Note that any background erasing/redrawing causes an ugly flicker while the window is resized. To avoid flickering, you should use double-buffering. See XDblBuffer and XDblBuffer2 samples on my home page.
Thus, one seldom wants to handle WM_ERASEBKGND. I guess it could be useful e.g. in a situations where you want a complex non-scrollable background and a scrollable text over it (like in some web pages).
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ithought there might be a benifit to processing the WM_ERASEBKGND rather than using the FILLRECT function in WM_PAINT. With the info you provided, I will do some digging into the SDK and try to understand the process a little better. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can someone tell me what an SDK (mentioned in the previous post)is and what one uses it for? I know that it stands for Software Development Kit. Are SDKs different from the Windows API? Are they just special-purpose APIs for particular components? Can anyone give me a simple example?
Mike S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(Platform) SDK refers to what we usually know as "Windows API". Roughly, SDK documentation = Win32 Help = MSDN (which contains more than that).
Platform SDK can be downloaded (AFAIK freely, but it's HUGE, so better order a CD) from MS web site -- it includes at least updated .h and .lib files, (I think documentation & basic tools, but I've never tried it myself). There is "Core SDK" (basically what we know as core Windows API) and few smaller SDKs (Internet etc.).
Microsoft issues new SDK releases with every new major system update (Windows or IE release, usually). The basic stuff doesn't change, and new stuff is usually protected with #ifdefs.It's all C, of course. MS VC++ can use these headers and tools transparently, and us Fortraneers have to wait for Intel to catch up with .h file translations.
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page