分类:
2008-10-13 16:31:38
很多时候,我们会使用系统对话框,比如MessageBox, GetOpenFileName等,而有时我们可能对它做些微调,比如出现的位置,或显示一些附加信息,而这些并不都能够通过API的参数设定.当然小技巧在这就有用的,我们可以设定一个钩子来完成这个工作.
//----------------------------------------------------------------------------
// CBTDlgProc
LRESULT CALLBACK CBTDlgProc(INT nCode, WPARAM wParam, LPARAM lParam)
{
// Notification that a window is about to be activated.
// window handle is wParam.
if(nCode == HCBT_ACTIVATE)
{
// check if the window is a find-in-files dialog
HWND hwnd = (HWND)wParam;
…….. // do things you like
// Don’t forget unhook.
UnhookWindowsHookEx(g_ hhkDlg);
}
else
{
// otherwise, continue with any possible chained hooks.
CallNextHookEx(g_hhkFindInFiles, nCode, wParam, lParam);
}
return 0;
}
//-----------------------------------------------------------------------------
// Global variable
HHOOK g_ hhkDlg;
//-----------------------------------------------------------------------------
// if you want to customize the system dialog, you may set the hook and call system
// dialog.
g_hhkDlg = SetWindowsHookEx(WH_CBT,
&CBTDlgProc,
0,
GetCurrentThreadId());
MessageBox(…), GetOpenFileName(…) and so on.