RegisterClassEx()函数返回0是哪里出问题了

HarryPan的庭院一角 2021-04-06 06:36:07
WNDCLASSEX wcex;
HWND hWnd;
MSG msg;
TCHAR szWindowClass[] = L"Example";
TCHAR szTitle[] = L"My Windows";

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 0;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

if (!RegisterClassEx(&wcex)) {
MessageBox(NULL,_T("窗口类注册失败!"), _T("窗口注册"), NULL);
return 1;
}

代码是按照书上的打的,对照了一遍没发现错误,在VS2019和DevC++运行都会显示窗口类注册失败,RegisterClassEx函数返回值都是0,请问是哪里出问题了
...全文
305 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2021-04-08
  • 打赏
  • 举报
回复

BOOL InitApplication(HINSTANCE hinstance) 
{ 
    WNDCLASSEX wcx; 
 
    // Fill in the window class structure with parameters 
    // that describe the main window. 
 
    wcx.cbSize = sizeof(wcx);          // size of structure 
    wcx.style = CS_HREDRAW | 
        CS_VREDRAW;                    // redraw if size changes 
    wcx.lpfnWndProc = MainWndProc;     // points to window procedure 
    wcx.cbClsExtra = 0;                // no extra class memory 
    wcx.cbWndExtra = 0;                // no extra window memory 
    wcx.hInstance = hinstance;         // handle to instance 
    wcx.hIcon = LoadIcon(NULL, 
        IDI_APPLICATION);              // predefined app. icon 
    wcx.hCursor = LoadCursor(NULL, 
        IDC_ARROW);                    // predefined arrow 
    wcx.hbrBackground = GetStockObject( 
        WHITE_BRUSH);                  // white background brush 
    wcx.lpszMenuName =  "MainMenu";    // name of menu resource 
    wcx.lpszClassName = "MainWClass";  // name of window class 
    wcx.hIconSm = LoadImage(hinstance, // small class icon 
        MAKEINTRESOURCE(5),
        IMAGE_ICON, 
        GetSystemMetrics(SM_CXSMICON), 
        GetSystemMetrics(SM_CYSMICON), 
        LR_DEFAULTCOLOR); 
 
    // Register the window class. 
 
    return RegisterClassEx(&wcx); 
} 
schlafenhamster 2021-04-07
  • 打赏
  • 举报
回复
WNDCLASSEX wndclass; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; wndclass.lpfnWndProc = WindowProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = GetModuleHandle(0); wndclass.hIcon = 0; wndclass.hCursor = 0; wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndclass.lpszMenuName = 0; wndclass.lpszClassName = "DTWIN"; wndclass.hIconSm = 0; RegisterClassEx(&wndclass); DWORD dwStyle = WS_VISIBLE | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; g_hWnd = CreateWindowEx(0, // extended window style "DTWIN", // pointer to registered class name "X-RAY", // pointer to window name dwStyle, // window style 500, // horizontal position of window 0, // vertical position of window WINDOW_WIDTH, // window width WINDOW_HEIGHT, // window height 0, // handle to parent or owner window 0, // handle to menu, or child-window identifier g_hInst, // handle to application instance 0 ); if(g_hWnd) { ShowWindow(g_hWnd, SW_SHOW); UpdateWindow(g_hWnd); .............................
zgl7903 2021-04-06
  • 打赏
  • 举报
回复
87 ERROR_INVALID_PARAMETER The parameter is incorrect. 设置断点,单步运行,查看 下是否有资源没有加载成功?
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
GetLastError() 查看错误代码是?
出现了点奇怪的问题。。。为了方便看GetLastError,我就把最后一个if改成了下面这个样子 if (!RegisterClassEx(&wcex)) { ATL::CString s; s.Format(_T("%d"), GetLastError()); MessageBox(NULL,s, _T("窗口注册"), NULL); return 1; } 然后这个程序有概率能运行了。。。也有概率会错误,错误代码是87,如果是原来的样子则还是一直不能运行
zgl7903 2021-04-06
  • 打赏
  • 举报
回复
GetLastError() 查看错误代码是?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧