[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ActiveX and OnIdle

Posted on 1998-08-12
8
Medium Priority
?
939 Views
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

0
Comment
Question by:lisab
[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
8 Comments
 
LVL 7

Expert Comment

by:psdavis
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.

Phillip
0
 
LVL 6

Expert Comment

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

Expert Comment

by:tvgPrabhu
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.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 1

Expert Comment

by:payn
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...
0
 
LVL 7

Accepted Solution

by:
psdavis earned 100 total points
ID: 1320704
Lisa,

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.

Phillip

0
 

Author Comment

by:lisab
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.
-Lisa

0
 
LVL 7

Expert Comment

by:psdavis
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.
0
 

Author Comment

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

Off I go to the land of worker threads.

Lisa
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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