函数原型:LONG SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong);
主要说明函数的第二个参数为GWL_WNDPROC的情况。
GWL_WNDPROC |
Sets a new address for the window procedure. You cannot change this attribute if the window does not belong to the same process as the calling thread. |
例子:
WNDPROC pWindowProc = 0;
LRESULT CALLBACK CallWindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
void Ctest_HkDlg::OnBnClickedProc()
{
pWindowProc = (WNDPROC)GetWindowLong(GetDlgItem(IDC_WND1)->m_hWnd, GWL_WNDPROC); //保存原来的窗口过程
LONG lValue = SetWindowLong(GetDlgItem(IDC_WND1)->m_hWnd,GWL_WNDPROC,(LONG)CallWindProc);
if (lValue==0)
{
int lErr = GetLastError();
char buf[32] = {0};
sprintf_s(buf, 32,"gle = %d \r\n", lErr);
OutputDebugString(buf);
}
}
LRESULT CALLBACK CallWindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch(message)
{
case WM_ACTIVATE:
break;
case WM_NCACTIVATE:
break;
case WM_NCMOUSEMOVE:
break;
case WM_MOUSEMOVE:
break;
case WM_SIZE:
break;
case WM_PAINT:
break;
}
if(pWindowProc)
return (*pWindowProc)(hwnd, message, wparam, lparam); //调用原来的窗口过程
return DefWindowProc(hwnd, message, wparam, lparam); //调用默认的窗口过程函数
}