?
Solved

WTL - Use of CIdleHandler with CDialogImpl

Posted on 2002-03-19
2
Medium Priority
?
1,001 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 600 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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