在SDK中经常会响应许多消息,这样大量代码在case:中,格式比较难看. 以下是消息分解的例子.
#include <windowsx.h> 消息分解,在<windowsx.h>中定义有宏HANDLE_MSG,例如: HANDLE_MSG(hWnd,WM_COMMAND,command) HANDLE_MSG(hWnd,WM_CREATE,create) HANDLE_MSG(hWnd,WM_PAINT,paint) HANDLE_MSG(hWnd,WM_DESTROY,destroy) 相应的定义函数如下: BOOL NEAR PASCAL TWnd_OnCreate(HWND hWnd, CREATESTRUCT FAR* lpCreateStruct) VOID NEAR PASCAL TWnd_OnSize(HWND hWnd, UINT state, int cx, int cy) void command(HWND hwnd,int icmd,HWND hctl,UINT ucode) BOOL create(HWND hwnd,LPCREATESTRUCT lpcreatestruct) void paint(HWND hwnd) void destroy(HWND hwnd) PRIVATE VOID NEAR PASCAL TWnd_OnTimer(HWND hWnd,UINT id) void Scrawl_OnKeyDown(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags) 其它的例子在MSDN中用HANDLE_MSG搜索到,这样可使程序简洁易懂