Sign in to follow this  

why should direct2d program delete WNDCLASSEX's hbrBackground statement

This topic is 1717 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

i test that if keeping the hbrBackground statement, when the program starts or resets from device lost, that background color will appear clearly

 

delete that statement is easy, but why keeping that statement is okay for the general direct3d program except fullscreen app

Share this post


Link to post
Share on other sites

It can be a hair more efficient, since there is nothing to repaint.

 

When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaint function.

Share this post


Link to post
Share on other sites

It can be a hair more efficient, since there is nothing to repaint.

 

When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaint function.

 

 

thanks a lot, i find it's the problem of WM_PAINT

 

but why in almost every example, direct2d always renders in WM_PAINT and direct3d renders when no message processing

Share this post


Link to post
Share on other sites

The background brush of the window class is used by the default message processor to repaint the background in response to WM_ERASEBKGND. If you are doing all your painting in WM_PAINT, or continuously in the render loop, then yes, you will not need a background brush. Note that if you use GetStockObject( BLACK_BRUSH ) to set the brush of the window class, then you won't need to delete the brush, because stock objects are shared between apps.

 

but why in almost every example, direct2d always renders in WM_PAINT and direct3d renders when no message processing

 

Well, it depends on how you want your application to behave, it has nothing to do with the application using D2D or D3D. If you want the application to render continuously, then you do all the rendering in the message loop when there are no messages. This is used when the contents displayed by the application is dynamic and changes frequently. If the contents change only when the user does something to change it (like painting programs for example), then the application will update its display only when needed, and in response to WM_PAINT.

Edited by Amr0

Share this post


Link to post
Share on other sites

The background brush of the window class is used by the default message processor to repaint the background in response to WM_ERASEBKGND. If you are doing all your painting in WM_PAINT, or continuously in the render loop, then yes, you will not need a background brush. Note that if you use GetStockObject( BLACK_BRUSH ) to set the brush of the window class, then you won't need to delete the brush, because stock objects are shared between apps.

 

thanks a lot

 

is this true, 'if not processing WM_PAINT, then the defalut will not do WM_ERASEBKGND generally, but still do WM_ERASEBKGND for fullscreen app'

Share this post


Link to post
Share on other sites

I have never heard or experienced a difference between regular windows and fullscreen windows in the way that paint messages are processed, if that's what you're asking. Generally the window will receive a WM_ERASEBKGND message and then a WM_PAINT message. In the case of D2D and D3D applications, all painting is done in one step (typically the Render() function), so you should set the window class brush to NULL (or return 1 in response to WM_ERASEBKGND without actually doing anything), and call your Render() function in response to WM_PAINT (but you will need to call BeginPaint() and EndPaint() to tell the OS that the window has been painted). This is of course only if your application does not use continuous rendering. If it uses continuous rendering, then you don't need to bother with these paint messages and just set the class background brush to NULL and do all the rendering in the message loop.

Share this post


Link to post
Share on other sites

I have never heard or experienced a difference between regular windows and fullscreen windows in the way that paint messages are processed, if that's what you're asking. Generally the window will receive a WM_ERASEBKGND message and then a WM_PAINT message. In the case of D2D and D3D applications, all painting is done in one step (typically the Render() function), so you should set the window class brush to NULL (or return 1 in response to WM_ERASEBKGND without actually doing anything), and call your Render() function in response to WM_PAINT (but you will need to call BeginPaint() and EndPaint() to tell the OS that the window has been painted). This is of course only if your application does not use continuous rendering. If it uses continuous rendering, then you don't need to bother with these paint messages and just set the class background brush to NULL and do all the rendering in the message loop.

 

i mean continuous rendering

 

i discover that for fullscreen app, even not processing WM_PAINT, WM_ERASEBKGND still will be called, and WM_ERASEBKGND will not be called for non-fullscreen app

Share this post


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