我尝试做的 WinMain 出了点问题。我在 Windows C++ 编程方面完全是菜鸟,我尝试学习。我跟着导师来帮助我。但看起来不起作用!这是我的代码..
#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL, "WindowClass1", "Our First Windowed app", WS_OVERLAPPEDWINDOW, 300, 300, 500, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOW);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
//return 0;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
}
当我编译时,我没有错误,但是当我运行应用程序时,我的任务栏中只有应用程序图标,仅此而已。在任务管理器中,我看到了 2 个应用程序实例。
什么和我错了?
非常感谢你的帮助!