Solved

ActiveX and OnIdle

Posted on 1998-08-12
8
890 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
8 Comments
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
Comment Utility
Why don't you create a worker thread?
(See AfxBeginThread)
0
 

Expert Comment

by:tvgPrabhu
Comment Utility
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
 
LVL 1

Expert Comment

by:payn
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to all, esp. snoegler for the most informative one liner.

Off I go to the land of worker threads.

Lisa
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 99
Expand data scrubbing tool 13 29
Whole sheet autoscrub still needed 19 44
List out all word 7 219
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

9 Experts available now in Live!

Get 1:1 Help Now