利用C语言创建windows窗口的程序解析

描述

//用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;

}

C语言

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分