CreateWindow():不允许使用类型名称

CreateWindow(): Type name is not allowed

本文关键字:类型 不允许 CreateWindow      更新时间:2023-10-16

我正在编写一个C++程序,我想在其中使用CreateWindow()函数创建一个窗口,但我无法使其工作。我无法编译该程序,Visual Studio在错误列表中给我的唯一信息是"不允许使用类型名"。如何解决此问题?我还没能自己决定如何修复它。这是程序的代码:

#include "stdafx.h"
#include <Windows.h>
int main()
{
    int screenWidth = GetSystemMetrics(SM_CXSCREEN);
    int screenHeight = GetSystemMetrics(SM_CYSCREEN);
    HWND window = CreateWindow("Melter", NULL, WS_POPUP, 0, 0, screenWidth, screenHeight, HWND_DESKTOP, NULL, HINSTANCE, NULL);
    return 0;
}

要从控制台应用程序创建窗口,需要做一些简单的事情。首先,您必须使用样式参数(一个模块句柄)通过RegisterClass注册自己的窗口类最重要的是窗口程序。您可以通过CCD_ 3获得模块句柄,返回用于创建调用进程的文件的句柄。您的窗口程序定义你的技能。这是一个处理发送到窗口的消息的函数。有了这个窗口类和模块句柄,您就可以用CreateWindow创建您的窗口。创建窗口后,必须使用ShowWindow进行显示。最后,您需要一个窗口的消息循环:

#include <Windows.h>
// Window procedure which processes messages sent to the window
LRESULT CALLBACK WindowProcedure( HWND window, unsigned int msg, WPARAM wp, LPARAM lp )
{
    switch(msg)
    {
        case WM_DESTROY: PostQuitMessage(0); return 0;
        default: return DefWindowProc( window, msg, wp, lp );
    }
}
int main()
{
    // Get module handle
    HMODULE hModule = GetModuleHandle( 0 );
    if (!hModule)
        return 0;
    // Register window class
    const char* const myWindow = "MyWindow" ;
    //const wchar_t* const myWindow = L"MyWindow"; // unicode
    WNDCLASS myWndClass = { 
        CS_DBLCLKS, WindowProcedure, 0, 0, hModule,
        LoadIcon(0,IDI_APPLICATION), LoadCursor(0,IDC_ARROW),
        CreateSolidBrush(COLOR_WINDOW+1), 0, myWindow };
    if ( !RegisterClass( &myWndClass ) )
        return 0;
    // Create window
    int screenWidth = GetSystemMetrics(SM_CXSCREEN)/2;
    int screenHeight = GetSystemMetrics(SM_CYSCREEN)/2;
    HWND window = CreateWindow( myWindow, NULL, WS_OVERLAPPEDWINDOW, 0, 0, screenWidth, screenHeight, HWND_DESKTOP, NULL, hModule, NULL);
    if( !window )
        return 0;
    // Show window
    ShowWindow( window, SW_SHOWDEFAULT );
    // Message loop
    MSG msg ;
    while( GetMessage( &msg, 0, 0, 0 ) )
        DispatchMessage(&msg);
    return 0;
}