Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Direct2D will not draw in Window

$
0
0

All, 

I am working with the demo from Direct2D and just simply trying to rearrange the code to allow the introduction of PeekMessage so I can draw in realtime, rather than on receiving a particular message. I'm quite new to C++ and the API.

In the example, the following code is called on the WM_DISPLAYCHANGE message:

WndProc snippet:

LRESULT result = 0;

if (message == WM_CREATE)    
{        
     LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;        
     AC_Main *pAC_Main = (AC_Main *)pcs->lpCreateParams;

     ::SetWindowLongPtrW(
            hwnd,            GWLP_USERDATA,            PtrToUlong(pAC_Main)            );        result = 1;    }    else    {        AC_Main *pAC_Main = reinterpret_cast<AC_Main *>(static_cast<LONG_PTR>(            ::GetWindowLongPtrW(                hwnd,                GWLP_USERDATA                )));        bool wasHandled = false;        if (pAC_Main)        {            switch (message)            {            case WM_DISPLAYCHANGE:                {                    PAINTSTRUCT ps;                    BeginPaint(hwnd, &ps);                    pAC_Main->gfx.OnRender(ps, hwnd);                    EndPaint(hwnd, &ps);                }                result = 0;                wasHandled = true;                break;

I am trying to move this: 

                    PAINTSTRUCT ps;                    BeginPaint(hwnd, &ps);                    pAC_Main->gfx.OnRender(ps, hwnd);                    EndPaint(hwnd, &ps);

...into something like this:

while(TRUE)
{
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
	TranslateMessage(&msg);
	DispatchMessage(&msg);
    }

    if( msg.message == WM_QUIT )
    {
        break;
    }
    else
    {
    PAINTSTRUCT ps;
    BeginPaint(hwnd, &ps);
    gfx.OnRender(ps, hwnd);
    EndPaint(hwnd, &ps);
    }		
}

So far the code compiles and runs, but the window draws simply black. I know the code is executing, but I can't work out why it's not drawing properly? Any thoughts? I'm tearing my hair out here and it's probably very obvious.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>