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


ActiveX and OnIdle

Posted on 1998-08-12
Medium Priority
Last Modified: 2013-11-20
Is it possible to do idle processing in an ActiveX Control? I have overridden CMyApp::OnIdle, it is never called by the main message loop. Any ideas?

I'd prefer to handle my background processing this way instead of embedding a peekmessage loop in a function.

Thanks in advance,
Lisa Beaulieu

Question by:lisab

Expert Comment

ID: 1320700
Since the control 'probably' doesn't contain it's own message loop (it's controlled by the container), I would have to doubt that you can use the OnIdle.  Have you checked up on OnKickIdle? It typically works for modal CDialogs.

Also consider adding a method to receive the OnIdle from the container?

Third, a timer will work in your ActiveX.

I dunno, just wanted to respond to a lady on the net.


Expert Comment

ID: 1320701
Why don't you create a worker thread?
(See AfxBeginThread)

Expert Comment

ID: 1320702
Philip is right, I guess. OnIdle will not be called inside your
ActiveX control. One work around would be to modify the container
app to trap OnIdle message and relay it to the Ax ctrl thru
a method. But if u can't modify the container App, well it
appears it wouldn't be possible to do Idle processing inside
your ActiveX control.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 1320703
I've done something very close to this before, but unfortunately I can't remember how. I do remember spending weeks on the solution, and I probably came up with something inferior...

First, if OnIdle doesn't work, PeekMessage won't either. Either the control has its own message pump (in which case it'll call OnIdle), it's tied to the container's message pump (in which case neither solution will work), or for some reason it's not getting messages at all (in which case you have bigger problems). Look at the way CWinThread::Run works--it does the PeekMessage for you, and throws out OnIdle calls for you...

Also, you didn't mention whether the "CMyApp" you're referring to is your control's CWinApp derivative, or the container's. If you can trap the container's OnIdle and have it call a method on the control, your problem's solved, but I suspect you're trying to build a general control that doesn't depend on such support from the container, and you're trying to override the control's OnIdle.

If I'm right, I'm pretty sure that the control's CWinApp derivative pretty much does nothing, and you can't count on it to, e.g., handle OnIdle for you.

You might be able to count on MFC-built containers passing WM_IDLEUPDATECMDUI messages to you, but that obviously won't work with containers that aren't either built with MFC or extraordinarily friendly. And even if it does, I'm pretty sure you'll only get the message if you're active (that is, in-place active and have an HWND, or windowless in-place active).

Which reminds me: If you're in-place active and have an HWND, you have your own messages. If you're windowless in-place active, you get your messages from your container. Maybe either changing your control to explicitly not be windowless and to request activation on creation will solve your problem (assuming you don't need to receive idle messages until activated, or while inactive).

Sorry I couldn't help more...

Accepted Solution

psdavis earned 100 total points
ID: 1320704

What are you trying to run on the OnIdle mode?  Maybe there's another answer to your question.  

I still think a OnTimer might be the answer.  Writing a Idle method won't work for a container that isn't aware of your control.  The timer would be universal.  On each of your OnTimer function calls, do somethings to check the idleness of the computer.  For example, get the mouse position with GetCursorPos and the position of the caret with GetCaretPos.  If there is a noticeable change in either within 2-3 seconds, then the system is active, otherwise, you're idle.  It's really gonna depend on what you want to do with the Idleness, but it's going to be your only solution.



Author Comment

ID: 1320705
Thanks to everyone for their interest in this question. Here are some details for you...

I have created a control that is to be used as an editor for C and Assembler code. It's a simple CRichEdit Doc/View that the container application creates an instance of "on demand". The control needs to provide the standard bells and whistles including color coding of comments and key words. I parse the 1st 48K before the text is displayed without a noticable delay. If the file is larger than 48K, parsing must continue, however, the user can't wait while a 1MB file is made pretty.

I could tie a timer and scroll events to parsing the remainder of the file. But, isn't this a good candidate for a background task? The worker thread sounds like a possible solution unfortunately I cant pass C++ objects. Although it appears there are workarounds for that too..

Thanks again for any guidance.


Expert Comment

ID: 1320706
I would definitely look at worker threads.  Have your worker thread busy loading up the code and your UI interface processing the data.

Author Comment

ID: 1320707
Thanks to all, esp. snoegler for the most informative one liner.

Off I go to the land of worker threads.


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 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