• <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

            免费观看成人久久网免费观看| 伊人久久免费视频| 无码人妻精品一区二区三区久久 | 伊人久久大香线蕉精品不卡 | 久久久久人妻一区二区三区| 亚洲天堂久久精品| 日产精品久久久一区二区| 久久久噜噜噜久久中文字幕色伊伊| 国产精品久久久久久久久免费| 色8久久人人97超碰香蕉987| 亚洲日本久久久午夜精品| 99久久伊人精品综合观看| 97久久精品午夜一区二区| 97久久综合精品久久久综合| 7777久久亚洲中文字幕| 久久精品国产亚洲AV无码麻豆 | 亚洲一本综合久久| 精品亚洲综合久久中文字幕| 国内精品九九久久久精品| 99久久成人国产精品免费| 9久久9久久精品| 91久久成人免费| 日韩欧美亚洲国产精品字幕久久久| 久久精品国产99国产精品| 伊人久久大香线蕉综合Av| 欧美精品国产综合久久| 伊人久久久AV老熟妇色| 国产麻豆精品久久一二三| 国产高清美女一级a毛片久久w| 国产伊人久久| 国产69精品久久久久观看软件| 久久国产欧美日韩精品| 蜜臀av性久久久久蜜臀aⅴ麻豆| 国产精品久久久久久吹潮| 99久久免费国产精品| 中文字幕无码久久精品青草| 国产成人久久精品一区二区三区| www.久久热.com| 欧美性猛交xxxx免费看久久久| 久久精品国产亚洲av高清漫画 | 区久久AAA片69亚洲|