• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            brent's hut

            simulate OnIdle in MFC ActiveX control

            There are two ways to do this, one is simple, another is complicated but more powerful.

            Method A:
            ::SetWindowsHookEx(WH_FOREGROUNDIDLE, YourIdleProc, AfxGetInstanceHandle(), GetCurrentThreadId());

            Method B (my way):
             1 static HHOOK s_hGetMsgHook = NULL;
             2 
             3 LRESULT FAR PASCAL GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
             4 {
             5     AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
             6 
             7     LPMSG lpMsg = (LPMSG) lParam;
             8     if( (nCode >= 0&& PM_REMOVE == wParam)
             9     {
            10         //your code here. maybe to deal with hot-keys, accelerators ...
            11         //see http://support.microsoft.com/kb/187988
            12 
            13         //my code to simulate OnIdle
            14         static BOOL bIdle = FALSE;
            15         CWinApp* pApp = AfxGetApp();
            16         if(!bIdle && pApp->IsIdleMessage(lpMsg))
            17             bIdle = TRUE;
            18         
            19         if(bIdle)
            20         {
            21             MSG msgPeek = {0};
            22             if(!::PeekMessage(&msgPeek, NULL, NULL, NULL, PM_NOREMOVE))
            23             {
            24                 VERIFY(PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WM_USER+0x120x340x56));
            25             }
            26         }
            27 
            28         if(lpMsg->hwnd == AfxGetMainWnd()->GetSafeHwnd() &&
            29             lpMsg->message == WM_USER+0x12 && lpMsg->wParam == 0x34 && lpMsg->lParam == 0x56)
            30         {
            31             lpMsg->message = WM_NULL;
            32             lpMsg->lParam = 0L;
            33             lpMsg->wParam = 0L;
            34 
            35             pApp->OnIdle(0);
            36             bIdle = FALSE;
            37         }
            38     }
            39 
            40     return ::CallNextHookEx(s_hGetMsgHook, nCode, wParam, lParam);
            41 }
            42 
            43 int CYourOleControl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
            44 {
            45     //...
            46     
            47     if(NULL == s_hGetMsgHook)
            48         s_hGetMsgHook = ::SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, AfxGetInstanceHandle(), GetCurrentThreadId());
            49 }
            50 
            51 void CYourOleControl::OnDestroy() 
            52 {
            53     //...
            54     
            55     ::UnhookWindowsHookEx(s_hGetMsgHook);
            56     s_hGetMsgHook = NULL;
            57 
            58     COleControl::OnDestroy();
            59 }

            Method A is far more simple, but with Method B:

            1) You can override CWinApp::IsIdleMessage to filter some special messages, such as a frequent timer which will not affect what you want to do in CWinApp::OnIdle. Because timer will affect message queue and if you don't filter it, OnIdle will be called every time after the timer is invoked.

            2) Sometimes your action in OnIdle will affect message queue inevitably, thus you will get a infinite loop: OnIdle->the special messages in message queue->OnIdle->... But with Method B, with SPY++ you can find the special messages, and filter them in IsIdleMessage.

            posted on 2010-04-15 15:49 brent 閱讀(1690) 評論(0)  編輯 收藏 引用 所屬分類: C++WindowsWeb

            狠狠色丁香婷婷久久综合五月| 欧洲性大片xxxxx久久久| 久久精品一本到99热免费| 亚洲人成网亚洲欧洲无码久久| 亚洲精品国产美女久久久| 77777亚洲午夜久久多喷| 精品久久久无码中文字幕天天| 日本亚洲色大成网站WWW久久| 色播久久人人爽人人爽人人片AV| 久久久久亚洲AV无码网站| 夜夜亚洲天天久久| 久久狠狠高潮亚洲精品| 久久综合九色欧美综合狠狠| AV狠狠色丁香婷婷综合久久| 女同久久| 久久嫩草影院免费看夜色| 久久国产精品77777| 国产精品久久久久久久app | 国产精品久久久久免费a∨| 久久精品成人免费看| 狠狠色综合网站久久久久久久高清| 99久久99久久精品免费看蜜桃| 色欲综合久久躁天天躁| 岛国搬运www久久| 97久久超碰国产精品旧版| 亚洲人成精品久久久久| 久久婷婷午色综合夜啪| 久久996热精品xxxx| 国产成人香蕉久久久久| AV色综合久久天堂AV色综合在| 久久天天躁狠狠躁夜夜网站| 麻豆av久久av盛宴av| 合区精品久久久中文字幕一区| 精品国产婷婷久久久| 国产—久久香蕉国产线看观看 | 久久免费视频1| 国内精品久久久久影院亚洲| 婷婷久久五月天| 一本一本久久A久久综合精品 | 亚洲精品乱码久久久久久| 日本强好片久久久久久AAA|