CreateWindow():不允许使用类型名称
CreateWindow(): Type name is not allowed
我正在编写一个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;
}
相关文章:
- 为什么 c++(g++) 不允许模板返回类型和函数名称之间有空格?
- C++从外部类继承的嵌套类;不允许使用不完整的类型
- E0322:不允许使用抽象类类型 " " 的对象
- 为什么C++不允许两个同名的函数/类模板,区别仅在于非类型模板参数(整型)的类型?
- 不允许将SDL_Cursor与unique_ptr:error不完整类型一起使用
- HTTP POST 请求不允许我定义上下文类型
- 内建数组出现不允许的类型不完整错误
- 为什么 std::array 的演绎指南不允许不同的类型?
- 为什么标准不允许通过引用捕获不完整的异常类型?
- 数组错误(不允许类型不完整)
- 为什么函数返回类型中不允许参数推导?
- std::function 中不允许引用返回类型吗?
- 类中不允许使用不完整的类型,但在类模板中允许使用不完整的类型
- 为什么协程不允许使用占位符返回类型?
- 错误消息:不允许抽象类类型 "X" 的对象:纯虚拟"Y"没有覆盖器
- 错误:不允许使用抽象类类型的对象
- 奇怪的不完整类型不允许错误
- 不完整的类型不允许错误
- c++不完全类型不允许在类内部使用
- 不完全类型不允许出现错误和元组