CreateWindow参数类型错误

时间:2014-01-07 23:28:40

标签: c++ directx hwnd

我刚刚开始使用C ++和创建窗口(在Windows上)。我正在使用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);

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

Here是一个完整的代码转储

1 个答案:

答案 0 :(得分:2)

这是你的错误

WS_OVERLAPPED | WS_SYSMENU, WS_CAPTION,

在使用,

WS_CAPTION之前替换此字符:|