windows和应用的交互都是用消息机制的。win系统和应用之间的关系如下:
在消息队列中存储要和用户应用直接的交互信息,消息队列是一个队列,是先进先出的机制。
其中消息的内容为:
1
2
3
4
5
6
7
8 |
typedef
struct tagMSG { // msg HWND
hwnd; //这是句柄,就是资源的标识,比如说这是标识哪个窗口 UINT
message; //这是一个无符号整型,标识是用户的哪种动作,比如按下鼠标左键,就是WM_LBUTTONDOWN WPARAM
wParam; //附加信息,比如按下键盘A,附加就是A的ascii码 LPARAM
lParam; //也是附加消息 DWORD
time ; //消息的时间 POINT pt; //光标的位置,就是鼠标的位置 } MSG; |
1
2
3
4
5
6
7 |
Windows程序的入口:(WinMain) int WINAPI WinMain( HINSTANCE
hInstance, // handle to current instance 实例资源的标识 HINSTANCE
hPrevInstance, // handle to previous instance 上一个实例资源的标识 LPSTR
lpCmdLine, // pointer to command line 命令 int
nCmdShow // show state of window 显示的状态,有显示、隐藏、最大化等。 ); |
1
2
3
4
5
6
7
8
9
10
11
12 |
typedef
struct _WNDCLASS { UINT
style; //窗口类型 WNDPROC lpfnWndProc; //窗口过程,是一个回调函数 int
cbClsExtra; //附加值 默认0 int
cbWndExtra; //附加内存 默认0 HANDLE
hInstance; //实例标识 HICON
hIcon; //窗口图标,左上角的图标 HCURSOR
hCursor; //光标,鼠标的类型 HBRUSH
hbrBackground; //画笔颜色 LPCTSTR
lpszMenuName; //菜单的名称 LPCTSTR
lpszClassName; //类的名字 } WNDCLASS; |
窗口类型:(
UINT style;
)
WNDPROC
lpfnWndProc
)ATOM RegisterClassEx(
CONST WNDCLASSEX *lpwcx // address of structure with class data
);
2.然后调用CreateWindow创建一个窗口。
1
2
3
4
5
6
7
8
9
10
11
12
13 |
HWND
CreateWindow( LPCTSTR
lpClassName, // pointer to registered class name LPCTSTR
lpWindowName, // pointer to window name DWORD
dwStyle, // window style int
x, // horizontal position of window int
y, // vertical position of window int
nWidth, // window width int
nHeight, // window height HWND
hWndParent, // handle to parent or owner window HMENU
hMenu, // handle to menu or child-window identifier HANDLE
hInstance, // handle to application instance LPVOID
lpParam // pointer to window-creation data ); |
3:显示窗口:ShowWindow
1
2
3
4 |
BOOL
ShowWindow( HWND
hWnd, // handle to window int
nCmdShow // show state of window ); |
4:刷新窗口:
UpdateWindow
最后刷新窗口。
visual c++基础(windows窗口程序解析),布布扣,bubuko.com
原文:http://www.cnblogs.com/a-bird/p/3647343.html