标签:
实现方法:
1.定义自己的控件类,比如CButtonEx:public CButton,实现自绘。
2.安装WH_CALLWNDPROC钩子
a.定义HHOOK全局变量
HHOOK g_WndProcHook=NULL;
b.在CXXAPP ::InitInstance()中安装钩子
g_WndProcHook=SetWindowsHookEx(
WH_CALLWNDPROC,
(HOOKPROC)CallWndProc,
NULL,
GetCurrentThreadId());
c.在CXXAPP::ExitInstance()中删除钩子
UnhookWindowsHookEx(g_WndProcHook);
d.在CallWndProc中子类化控件
LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if (HC_ACTION==nCode)
{
CWPSTRUCT* lpCWPSTRUCT=(CWPSTRUCT*) lParam;
HWND hWnd=lpCWPSTRUCT->hwnd;
char szClassName[512];
::GetClassName(hWnd,szClassName,512);
switch (lpCWPSTRUCT->message)
{
case WM_Create:
{
if (strcmp(szClassName,"Button")==0)
{
//在这里开始子类化
CButtonEx*pBtn=newCButtonEx();
pBtn->SubclassWindow(hWnd);
}
break;
}
case WM_NCDESTROY:
{
//取消子类化
//pBtn->UnsubclassWindow();
break;
}
default:
break;
}
}
return CallNextHookEx(g_WndProcHook,nCode,wParam,lParam);
}
MFC学习笔记之12:用窗口过程WH_CALLWNDPROC钩子+子类化实现皮肤功能
标签:
原文地址:http://www.cnblogs.com/dgx/p/5491546.html