Chinaunix首页 | 论坛 | 博客
  • 博客访问: 368486
  • 博文数量: 715
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:46
文章分类

全部博文(715)

文章存档

2011年(1)

2008年(714)

我的朋友

分类:

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

          // Dont 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.

    


--------------------next---------------------

阅读(191) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~