开发者

WinAPI ShowWindow fails even though CreateWindowEx seemingly succeeds

I am having trouble using CreateWindowEx. If I set the final parameter (LPVOID lpParam) to NULL and use the returned window handle in a call to ShowWindow, the window displays everything fine. However, I need to pass in a pointer to the class that I will be modifying based off of some of the operating system messages that I intercept. When I try to do that, by specifying the lpParam as this, my returned handle is apparently garbage because passing it into ShowWindow causes: "An unhandled exception was encountered during a user callback."

I have no idea how to debug this, so I am stuck.

The address that is pointed to remains the same between passing it in and pulling it back out.

I did not define a WM_PAINT case.

WM_CREATE handler:

case WM_CREATE:
{

            // get screen resolution
            HWND desktop = GetDesktopWindow();
            RECT R;
            GetWindowRect(desktop, &R);
            int width = R.right - R.left;
            int height = R.bottom - R.top;

            HWND loading_image;
            loading_image = CreateWindowEx(0,L"Static",L"Image", SS_CENTERIMAGE | SS_BITMAP | WS_CHILD | WS_VISIBLE,0,0,width,height,hwnd,(HMENU)ID_IMAGE3,g_hInst,NULL); 
            SetClassLong(loading_image,GCL_STYLE,CS_HREDRAW | CS_VREDRAW);
            HBITMAP bitmap = (HBITMAP)LoadImage(NULL,L"loadingscreen.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            SendMessage(loading_image,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)bitmap);

            progre开发者_如何转开发ssbar = CreateWindowEx(0, PROGRESS_CLASS, (LPTSTR)NULL, WS_CHILD | PBS_SMOOTH | WS_VISIBLE, width/2-400,100,800,20,hwnd,(HMENU)0,g_hInst,NULL);
            SendMessage(progressbar,PBM_SETSTEP,20,NULL);

            CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
            app = (D3DApp*)cs->lpCreateParams;
            return 0;
}

The WindowProc call goes bad on a 70 msg (WM_WINDOWPOSCHANGING). It doesn't go bad on prior messages: WM_NCCALCSIZE, WM_CREATE, WM_PARENTNOTIFY, WM_SIZE, WM_SIZE, or WM_SHOWWINDOW, although WM_SHOWWINDOW is handled just before WM_WINDOWPOSCHANGING, so I'm guessing WM_WINDOWPOSCHANGING is just a result of WM_SHOWWINDOW getting passed.


Put a breakpoint on CreateWindowEx. Write down the pointer you're passing in.

Put a breakpoint on your WindowProc function. Check that the pointer it extracts from your private window data (that's where you're storing the pointer, right?) is the same one passed in. You are using SetProp and GetProp (see topic Window Properties on MSDN) instead of SetWindowLongPtr, right?

On entry to your WindowProc, print out the message number so you can see which message is being processed when it crashes (you can use a tracepoint for this if your debugger supports them, or add a printf call to your code and recompile.


Maybe you have your answer already, but I think the culprit is in:

SetClassLong(loading_image,GCL_STYLE,CS_HREDRAW | CS_VREDRAW);

Why do you need to do this?


Did you realize that CreateWindowEx sends messages before it returns? That means that your WindowProc must handle them. You don't show that code, but it's a common mistake to call CreateWindowEx too early.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜