WinApi controls cleared together with screen in DirectX

Started by
3 comments, last by savail 11 years, 12 months ago
Hey,
So I'm not creating a game but a map editor for my game and this is my main message loop:
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

if(!Render())
{
MessageBox(NULL, "Failed to render", "Error", MB_OK | MB_ICONEXCLAMATION);
break;
}
}

Here is my Render() function:
bool Graphics::Render()
{
HRESULT hr = Input::Obj().d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
if(FAILED(hr)) return false;

hr = Input::Obj().d3dDevice->Present(NULL, NULL, NULL, NULL);
if(FAILED(hr)) return false;

return true;
}


I have created a scrollbar also on my window and when I'm putting my function Render() to my main message loop as above the scrollbar is being cleared all the time. How to make scrollbar refresh together with clearing a screen?
Advertisement
Is the scroll bar parented to the same window that draw to with D3D? If so, it's not going to work. D3D assumes that it owns the entire client area of the window and won't play nice with other controls trying to render to the same client area. You should put your scroll bars beside the D3D window, perhaps parented to same window that the D3D window is parented to.

Also you should change your message loop so that you pump all queued messages before rendering. Otherwise you can end up with messages building up in the queue quicker than you pull them out.
hmm so how should the common message loop for normal programs(not games) look? Where rendering should be done? I can't find a good example, every refer to game message loop ;/.
And yea the scrollbar is parented to the same window where D3D draws. I'm not sure if I understood well the matter connected with scrollbar, should I put the scrollbars on another window? Could you explain it wider?
For the D3D render area make another control of type STATIC. Then you use the HWND of that static control for the D3D creation. Then the scrollbar is parented to the main window, and the static is also parented to the main window, but D3D won't clear the main window, just the static control.
hmm quite interesting solution, thanks I'll try it soon

This topic is closed to new replies.

Advertisement