分类: C/C++
2008-03-14 14:02:24
二、相关函数
1.窗口类的属性可以通过GetWindowLong和SetWindowLong进行读取和设置
LONG GetWindowLong( HWND hWnd, // handle to window int nIndex // offset of value to retrieve ); LONG SetWindowLong( HWND hWnd, // handle to window int nIndex, // offset of value to set LONG dwNewLong // new value );可以返回或设置以下内容:
所以使用
OldMsgProc = (WNDPROC)SetWindowLong (hControlWnd, GWL_WNDPROC, (LONG)MyMsgProc);将控件消息处理函数替换成MyMsgProc,原处理函数被OldMsgProc记录。
2.调用消息处理函数
LRESULT CallWindowProc( WNDPROC lpPrevWndFunc, // pointer to previous procedure HWND hWnd, // handle to window UINT Msg, // message WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
//记录原来处理函数的全局变量 WNDPROC OldMsgProc; //新消息处理函数 LRESULT MyMsgProc(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_LBUTTONDOWN: ::MessageBox(NULL,"click!","",MB_OK); } //调用控件原来的消息处理函数 return CallWindowProc(OldMsgProc,hwnd,message,wParam,lParam); }
case WM_CREATE: { HWND hControlWnd = CreateWindowEx(0,"BUTTON", TEXT("按钮(&A)"), WS_CHILD | WS_VISIBLE|BS_PUSHBUTTON, 10, 10, 100, 100, hwnd, (HMENU)1000, //控件ID ((LPCREATESTRUCT) lParam)->hInstance, //实例句柄 NULL); //嵌入新的消息处理函数 OldMsgProc = (WNDPROC) SetWindowLong (hControlWnd, GWL_WNDPROC, (LONG)MyMsgProc); } return 0;