[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1018
  • Last Modified:

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
0
mridey
Asked:
mridey
  • 2
1 Solution
 
DanRollinsCommented:
It's because it is a true 'DoModal'; that is, control passes to the system and does not return until the user dismisses the dialog.

MFC handles this by simulating DoModal -- the dialog box is actually a modeless dlg so it can micro-manage the message pump.

-- Dan
0
 
DanRollinsCommented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now