流程
- WinMain函数编写
- 设计窗口类(WNDCLASS)
- 注册窗口类(RegisterClass)
- 创建窗口(CreateWindow)
- 显示并更新
- 消息循环
- 窗口过程函数(wndclass->lpfnWndProc)
代码
复制代码
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95#include <windows.h> #include <stdio.h> LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain(//the entry point of programme HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ) { WNDCLASS wndcls; //1.the feature of window wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//the black brush wipe the backgorund of window wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=LoadIcon(NULL,IDI_ERROR); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinSunProc;//the function of windows procedure wndcls.lpszClassName="MFC Procedure"; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wndcls);//2.register windclass HWND hwnd; hwnd=CreateWindow("MFC Procedure","新窗口创建",WS_OVERLAPPEDWINDOW, 0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd);//direct send WM_PAINT; MSG msg; //while(bRet=GetMessage(&msg,hWnd,0,0))!=0) //{ //if(bRest==-1){//handle the error} //else{} //} while(GetMessage(&msg,NULL,0,0))//avoid endless loop { TranslateMessage(&msg);//translate the message of key_buton to ASCII DispatchMessage(&msg); //repass message to system,then OP call functional for repaly } return 0; } LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { switch(uMsg) { case WM_CHAR: char szChar[20]; sprintf(szChar,"char is %d",wParam); MessageBox(hwnd,szChar,"weixin",0); break; case WM_LBUTTONDOWN: MessageBox(hwnd,"mouse clicked","weixin",0); HDC hdc; hdc=GetDC(hwnd); TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训")); ReleaseDC(hwnd,hdc); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hwnd,&ps); TextOut(hDC,0,0,"新星人类",strlen("新星人类")); EndPaint(hwnd,&ps); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,"是否真的结束?","MFC",MB_YESNO)) { DestroyWindow(hwnd);//send WM_DESTROY } break; case WM_DESTROY: PostQuitMessage(0);//send WM_QUIT and Return break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }
最后
以上就是迷路歌曲最近收集整理的关于第1章-MFC程序运行流程的全部内容,更多相关第1章-MFC程序运行流程内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复