//用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;
}
//入口函數(shù)
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.創(chuàng)建窗口
hwnd = CreateWindow("xingshuai", "我的窗口", WS_OVERLAPPEDWINDOW,
200, 200, 800, 600, NULL, NULL, hInstance, NULL);
//4.顯示并更新窗口
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//5.消息循環(huán)
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
-
WINDOWS
+關注
關注
3文章
3521瀏覽量
88317 -
C語言
+關注
關注
180文章
7594瀏覽量
135856
原文標題:C語言創(chuàng)建windows窗口
文章出處:【微信號:cyuyanxuexi,微信公眾號:C語言編程學習基地】歡迎添加關注!文章轉載請注明出處。
發(fā)布評論請先 登錄
相關推薦
評論