请问我这个拿C++的WinAPI编的程序为什么运行无效果?一个没有控制台和窗口,什么都没有,没反应?
感谢各位大神了!!!
IDE:Visual Studio 2017
#include <Windows.h>
LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEXW wcx;
wcx.cbSize = sizeof(WNDCLASSEXW);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = NULL;
wcx.hCursor = LoadCursor(NULL,IDC_ARROW);
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcx.lpszMenuName = NULL;
wcx.lpfnWndProc = WinProc;
ATOM win = RegisterClassExW(&wcx);
HWND hWnd;
hWnd = CreateWindowW(L"MainWinClass", L"PMDG737-800模拟仓控制终端", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUPWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, (HWND)NULL, (HMENU)NULL, hInstance, (LPVOID)NULL);
if (!hWnd) {
MessageBoxW(NULL, L"窗口创建失败!", L"错误", 0);
return 0;
}
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg,NULL,NULL,NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}