我是 C++ 和 WinApi 的新手。我无法在 WinApi 中创建一个简单的窗口。CreateWindow() 函数返回 null。GetLastError() 函数返回错误 1813。但在创建窗口之前 GetLastError() 返回 0。对不起我的英语。这是我的完整代码:
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
LPCWSTR szWindowClass = TEXT("WndClass");
LPCWSTR szTitle = TEXT("Main window");
DWORD dwError;
WNDCLASS wc;
wc.style = CS_OWNDC;
wc.hInstance = hInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szWindowClass;
wc.lpszMenuName = L"MenuName";
dwError = GetLastError(); //0
RegisterClass(&wc);
dwError = GetLastError();//0
HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);//NULL
dwError = GetLastError();//1813 =(
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return 0;
}