vs2017 c++写窗口 运行无错误,但不显示窗口 为什么? 25

#include"windows.h"#include"stdio.h"LRESULTCALLBACKWindowProc(HWNDhwnd,UINTuMsg,WPARA... #include "windows.h"
#include "stdio.h"
LRESULT CALLBACK WindowProc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbClsExtra = 0;
wndcls.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WindowProc;
wndcls.lpszClassName ="yulong2018";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;

RegisterClass(&wndcls);

HWND hwnd;
hwnd = CreateWindowA("yulong2018", "我的窗口", WS_OVERLAPPEDWINDOW, 0, 0, 600, 400,
NULL,NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}
return msg.wParam;
}

LRESULT CALLBACK WindowProc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
TCHAR szHello[32] = "创建一个简单窗口。";
switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf_s(szChar, "char code is %d", wParam);
MessageBoxA(hwnd, szChar, "char", 0);
break;
case WM_LBUTTONDOWN:
MessageBoxA(hwnd, "mouse cliked", "message", 0);
HDC hdc;
hdc=GetDC(hwnd);
TextOutA(hdc, 0, 50, "my window",strlen("my window"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
HDC hdv;
PAINTSTRUCT ps;
hdv=BeginPaint(hwnd, &ps);
RECT rt;
GetClientRect(hwnd, &rt);
DrawText(hdv, szHello, strlen(szHello), &rt, DT_CENTER);

EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBoxA(hwnd, "do you quit ?", "message", MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;

}
展开
 我来答
落影璃
2018-05-11
知道答主
回答量:6
采纳率:0%
帮助的人:4.4万
展开全部
加句system("pause");试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式