CreateWindowEx失败,GetLastError返回0;(CreateWindowEx fails with GetLastError returning 0; DefWindowProc

编程入门 行业动态 更新时间:2024-10-27 13:29:55
CreateWindowEx失败,GetLastError返回0;(CreateWindowEx fails with GetLastError returning 0; DefWindowProc is called in WindowProc [closed])

我刚刚遇到问题,同时使用WinAPI创建了一个窗口,这让我感到非常尴尬。

对CreateWindowEx的调用失败,返回0.之后立即调用的GetLastError也返回0。

当我在DefWindowProc上设置断点时,我的调试器确认它正在被调用,因为它应该是。

我在下面列出了一个最小的例子。 为什么对CreateWindowEx的调用失败?

的WndProc

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_DESTROY: PostQuitMessage(EXIT_SUCCESS); return 0; } // LRESULT WINAPI DefWindowProc(HWND, UINT, WPARAM, LPARAM); return DefWindowProc(hWnd, msg, lParam, wParam); }

对CreateWindowEX的调用

hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, // dwExStyle CLASS_NAME, // lpClassName WINDOW_NAME, // lpWindowName WS_OVERLAPPEDWINDOW, // dwStyle CW_USEDEFAULT, 0, // x, y CW_USEDEFAULT, 0, // width, height NULL, // hWndParent NULL, // hMenu hInstance, // hInstance NULL // lpParam ); if (NULL == hWnd) { //GetLastError(); return 1; }

I just had a problem, while creating a window with WinAPI, which took me an embarrassing long time to solve.

The call to CreateWindowEx failed, returning 0. GetLastError, called immediately afterwards, also returned 0.

When I set a breakpoint on DefWindowProc, my debugger confirmed that it was being called, as it should be.

I've included a minimal example below. Why is the call to CreateWindowEx failing?

WndProc

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_DESTROY: PostQuitMessage(EXIT_SUCCESS); return 0; } // LRESULT WINAPI DefWindowProc(HWND, UINT, WPARAM, LPARAM); return DefWindowProc(hWnd, msg, lParam, wParam); }

The call to CreateWindowEX

hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, // dwExStyle CLASS_NAME, // lpClassName WINDOW_NAME, // lpWindowName WS_OVERLAPPEDWINDOW, // dwStyle CW_USEDEFAULT, 0, // x, y CW_USEDEFAULT, 0, // width, height NULL, // hWndParent NULL, // hMenu hInstance, // hInstance NULL // lpParam ); if (NULL == hWnd) { //GetLastError(); return 1; }

最满意答案

我不小心切换了传递给DefWindowProc的wParam和lParam值。

以正确的顺序给出函数参数解决了我的问题。

return DefWindowProc(hWnd, msg, wParam, lParam);

I accidentally switched the wParam and lParam values I was passing to DefWindowProc.

Giving the function arguments in the proper order solved my problem.

return DefWindowProc(hWnd, msg, wParam, lParam);

更多推荐

本文发布于:2023-08-06 21:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455376.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:fails   returning   CreateWindowEx   GetLastError   WindowProc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!