c++ - 为什么我从 RegisterClassEx 收到错误代码 87(无效参数)?

标签 c++ winapi wchar-t

这是代码

#include <windows.h>
const wchar_t g_szClassName[] = L"myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{/*...*/
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, L"Window Registration Failed!", L"Error!",
        MB_ICONEXCLAMATION | MB_OK);
    return 0;
    }
    // Step 2: Creating the Window...
    return Msg.wParam;
}

此代码直接来自 Forgers Win32 教程(需要时使用 L"" 和 wchar_t)。但我无法使其在 WinXP SP3 x86 和 VC2008Express SP1 上运行。

最佳答案

例如,您没有设置样式成员(取自向导创建的代码):

wc.style = CS_HREDRAW | CS_VREDRAW;

关于c++ - 为什么我从 RegisterClassEx 收到错误代码 87(无效参数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7228661/

相关文章:

c++ - 与遗留 TCHAR 代码接口(interface)的正确样式

c++ - C/C++ 的广泛执行

c++ - 在 C++ 中混合重写和重载

c++ - 多线程事件调度

c++ - 使用 fstream 读取每个字符,包括空格和换行符

c++ - 带有非托管 SQLite 的混合 C++/CLI 代码

c++ - WSARecv() 可以立即返回数据吗?

c++ - is_constant_evaluated() 应该产生 constexpr 变量?

c - 为什么我的加密文本没有改变?

c++ - 比较 unicode 和 wchar_t C++ : `unable to find numeric literal operator ' operator ""F' `