//用VC6.0或者VS的学员,请选择WIN32 APPLICATION
#include
#include
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 50, "欢迎来到邢帅公开课堂!",
strlen("欢迎来到邢帅公开课堂!"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if(MessageBox(hwnd, "是否真的退出?", "询问", MB_YESNO) == IDYES)
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
return 0;
}
//入口函数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
//1.设计窗口类
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
wc.lpszMenuName = NULL;
wc.lpszClassName = "xingshuai";
//2.注册窗口类
RegisterClass(&wc);
//3.创建窗口
hwnd = CreateWindow("xingshuai", "我的窗口", WS_OVERLAPPEDWINDOW,
200, 200, 800, 600, NULL, NULL, hInstance, NULL);
//4.显示并更新窗口
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//5.消息循环
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
-
WINDOWS
+关注
关注
3文章
3524浏览量
88376 -
C语言
+关注
关注
180文章
7597浏览量
136051
原文标题:C语言创建windows窗口
文章出处:【微信号:cyuyanxuexi,微信公众号:C语言编程学习基地】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论