我需要用 C 编写一些程序,但我无法让窗口工作。它提出了大约 30 个错误,主要是说;当有一个,没有存储类或类型说明符,以及预期的声明时,应该是预期的,不确定这些是什么意思。我看过两个教程,它们看起来都非常相似,而我的看起来一样,所以不确定这些缺失的东西是什么。
这是我的代码
#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hThisInst,
HINSTANCE hPrevInst,
LPSTR lpszArgs,
int nWinMode);
{
WNDCLASS wcls;
HWND hwnd;
MSG msg;
LPCWSTR szClassName = L"ThreadsProgram";
LPCWSTR szWinName = L"My Threads Program"
//Register Class
wcls.style =0;
wcls.lpfnWndProc =WindowFunc;
wcls.cbClsExtra =0;
wcls.cbWndExtra =0;
wcls.hInstance =hThisInst;
wcls.hIcon =LoadIcon(NULL, IDI_APPLICATION);
wcls.hCursor =LoadCurser(NULL, IDC_ARROW);
wcls.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wcls.lpszMenuName =NULL;
wcls.lpszClassName =szClassName;
if(!RegisterClass(&wcls))
{
MessageBox(NULL, "Window Registration Failed!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//Make Window
hwnd = CreateWindow(szClassName,
szWinName,
WS_OVERLAPPINGWINDOW,
100,
100,
400,
400,
HWND_DESKTOP,
NULL,
hThisInst,
NULL);
//Show Window
if(hwnd == NULL)
{
MessageBox(NULL, "Window Failed!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
//Main Message Loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}