孙鑫VC++讲座笔记

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论



7,Windows提供的窗口类:
typedef struct _WNDCLASS {
UINT style; //窗口的类型
WNDPROC lpfnWndProc; //窗口过程函数指针(回调函数)
int cbClsExtra; //窗口类附加字节,为该类窗口所共享。通常0。
int cbWndExtra; //窗口附加字节。通常设为0。
HANDLE hInstance; //当前应用程序事例句柄。
HICON hIcon; //图标句柄 LoadIcon();
HCURSOR hCursor; //光标句柄 LoadCursor();
HBRUSH hbrBackground; //画刷句柄 (HBRUSH)GetStockObject();
LPCTSTR lpszMenuName; //菜单名字
LPCTSTR lpszClassName; //类的名字
} WNDCLASS;

8,窗口类注册:
ATOM RegisterClass(
CONST WNDCLASS *lpWndClass // address of structure with class
// data
);

9,创建窗口:
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
);

10,显示和更新窗口窗口:
BOOL ShowWindow(
HWND hWnd, // handle to window
int nCmdShow // show state of window
);
BOOL UpdateWindow(
HWND hWnd // handle of window
);

11,消息循环:
MSG msg;
while(GetMessage(&msg,...)) //从消息队列中取出一条消息
{
TranslateMessage(&msg); //进行消息(如键盘消息)转换
DispatchMessage(&msg); //分派消息到窗口的回调函数处理,(OS调用窗口回调函数进行处理)。
}

其中:
//**The GetMessage function retrieves a message from the calling thread's message queue and places it in the specified

structure.
//**If the function retrieves a message other than WM_QUIT, the return value is nonzero.If the function retrieves the WM_QUIT

message, the return value is zero. If there is an error, the return value is -1.

BOOL GetMessage(
LPMSG lpMsg, // address of structure with message
HWND hWnd, // handle of window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax // last message
);


//The TranslateMessage function translates virtual-key messages into character messages. The character messages are posted to

the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function.
BOOL TranslateMessage(
CONST MSG *lpMsg // address of structure with message
);

//The DispatchMessage function dispatches a message to a window procedure.
LONG DispatchMessage(
CONST MSG *lpmsg // pointer to structure with message
);

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答