创建窗口参数类型错误

CreateWindow argument type error

本文关键字:错误 类型 参数 窗口 创建      更新时间:2023-10-16

我刚刚开始玩C++并创建窗口(在窗口上)。我正在使用CreateWindow函数,但收到错误

Error   2   error C2664: 'HWND CreateWindowExA(DWORD,LPCSTR,LPCSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)' : cannot convert argument 9 from 'const int' to 'HWND'

这是有问题的代码

//Create the window
hwnd = CreateWindow(
    "HelloDirectXClass",//Class name, defined above
    "Hello DirectX",//Top bar title
    WS_OVERLAPPED | WS_SYSMENU, WS_CAPTION,//Window style, using default
    GetSystemMetrics(SM_CXSCREEN) / 2 - WIDTH / 2,//Position relitive to top left corner, X CXSCREEN notice the CX<--for X or width
    GetSystemMetrics(SM_CYSCREEN) / 2 - HEIGHT / 2,//Position relitive to top left corner, Y CYSCREEN notice the CY<--for Y or height
    WIDTH,
    HEIGHT,
    (HWND)NULL,//Setting window parent
    (HMENU)NULL,
    hInstance,//Window instance defined above
    (LPVOID)NULL);

通过查看错误,我会发现它试图说它无法将函数中的参数 9 (HMENU)NULL 从整数转换为HWND类型。这没有任何意义,因为文档说 arg 9 应该像我一样HMENU

这是一个完整的代码转储

这是

你的错误

WS_OVERLAPPED | WS_SYSMENU, WS_CAPTION,

将此字符:WS_CAPTION前的,替换为|