Solved

WTL - Use of CIdleHandler with CDialogImpl

Posted on 2002-03-19
2
971 Views
Last Modified: 2013-11-25
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
Comment
Question by:mridey
  • 2
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 7043936
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7058252
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now