Link to home
Start Free TrialLog in
Avatar of mridey
mridey

asked on

WTL - Use of CIdleHandler with CDialogImpl

This is a Windows Template Library question.

I would like to implement an Idle loop on a dialog.
I have:

class CMcScanDlg : public CDialogImpl<CMcScanDlg>, CIdleHandler
{
public:
     enum { IDD = IDD_TEXT };

     BEGIN_MSG_MAP(CMcScanDlg)
          MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
          COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
     END_MSG_MAP()

     LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
     {
          CMessageLoop* pLoop = _Module.GetMessageLoop();
          ATLASSERT(pLoop != NULL);
          pLoop->AddIdleHandler(this);

          return TRUE;
     }

     LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
     {
          EndDialog(wID);
          return 0;
     }

     BOOL OnIdle()
     {
          Beep(4000,100);
          return TRUE;
     }

};

and I call it using

CMcScanDlg dlg1;
dlg1.DoModal();

But OnIdle() is never called, at least not during the DoModal(). It's only called once the code is back in the main application (and the main message loop).

Any clue ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you insult me with a C because of my race?  Gender bias?  I can't think of any other reason you would want to tarnish my otherwise 4.0 Grade Point Average.

-- Dan