我是靠谱客的博主 微笑人生,这篇文章主要介绍windows应用程序【二】创建窗口,现在分享给大家,希望可以做个参考。

我们在创建窗口时需要的过程 

关于消息循环

因为处理器同时只能执行一个程序 因此我们需要操作系统去调度程序 因此我们只是将消息传给操作系统 等待回应从而由操作系统来显示我们需要的窗口

wndproc()

窗口过程负责用来响应某一类窗口收到的各种Windows消息

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szWndClassName[] = "hellowin"; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szWndClassName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, "注册失败", "错误", MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szWndClassName, // window class name "窗口标题", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) //消息队列 { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; //WM_QUIT } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("在屏幕中心输出文字"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }

最后对于我们为什要对一个窗口定义很多遍

第一遍第一类时类似于定义了一个基类 也就像确定了你是大学生具有所有大学生的特点

但是第二次创建窗口时 会说明你是哪个专业的 性格是什么 

最后

以上就是微笑人生最近收集整理的关于windows应用程序【二】创建窗口的全部内容,更多相关windows应用程序【二】创建窗口内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部