为什么我从RegisterClassEx获得错误码87(无效参数)?

时间:2022-06-10 22:44:41

Here's the code

这是代码

#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;
}

This code is straight from Forgers Win32 Tutorial (with L"" and wchar_t where needed). Yet I can't make it work on WinXP SP3 x86 and VC2008Express SP1.

这段代码直接来自伪造者Win32教程(在需要的地方有L"和wchar_t)。但是我不能让它在WinXP SP3 x86和VC2008Express SP1上运行。

1 个解决方案

#1


2  

You didn't set style member, for instance (taken from wizard created code):

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

wc.style = CS_HREDRAW | CS_VREDRAW;

#1


2  

You didn't set style member, for instance (taken from wizard created code):

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

wc.style = CS_HREDRAW | CS_VREDRAW;