Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: about CPU Usage Pin
Mark Salsbery18-Apr-07 6:14
Mark Salsbery18-Apr-07 6:14 
GeneralRe: about CPU Usage Pin
Roger Stoltz18-Apr-07 6:26
Roger Stoltz18-Apr-07 6:26 
GeneralRe: about CPU Usage Pin
Mark Salsbery18-Apr-07 6:35
Mark Salsbery18-Apr-07 6:35 
QuestionBitmap [modified] Pin
Vijayan.S17-Apr-07 23:49
Vijayan.S17-Apr-07 23:49 
AnswerRe: Bitmap Pin
Paresh Chitte18-Apr-07 0:15
Paresh Chitte18-Apr-07 0:15 
AnswerRe: Bitmap Pin
Hamid_RT18-Apr-07 1:30
Hamid_RT18-Apr-07 1:30 
QuestionManage Timer on MFC [modified] Pin
CDRAIN17-Apr-07 23:36
CDRAIN17-Apr-07 23:36 
AnswerRe: Manage Timer on MFC Pin
Roger Stoltz18-Apr-07 6:19
Roger Stoltz18-Apr-07 6:19 
Not much info to go on here, but let me guess about what I think is going on...
I'll just have a look inside my crystal orb... Wink | ;)

In your application you have set up a Single Threaded Apartment (STA) and you're using an ActiveX control from that thread.
At some point you're calling one of the interface methods of the ActiveX control commencing an operation that will take some time to complete. The function call will not return until the operation has completed. During this time you want to display a progress indicator and update it periodically.

If the above is correctly guessed about your situation, then your main problem probably is that your application doesn't process messages while it's executing inside the ActiveX control. The call to the ActiveX is blocking and won't return until finished. This also prevents your user interface from being responsive as well.
There's no sustainable way to fix this. Your main thread has got to process messages if you want to do GUI stuff in that thread.

How it should be done:
The ActiveX control should be implemented to be asyncronous. If an operation is started that will take a relatively long time to complete, the call should return immediately with information whether the operation could be started or not. When the operation completes, the ActiveX should fire an event through a connection point interface. It means that the ActiveX calls an interface implemented by the client. Progress information should be given to the client the same way, but through another method of course.

What could be done:
If the ActiveX control is not your own and you don't have access to the source code for it, there are some workarounds that may do the trick. The preferred solution at the top.

1. If the ActiveX does not have a GUI, you could spawn a UI-thread, initialize another STA and create the ActiveX in that thread. Marshal the interface for the ActiveX back to the main thread to be able to call other functions easily, but when starting lengthy operations you should post messages to the UI-thread so that thread becomes blocked instead.
In your main thread you can update the progress indicator with a timer, typically with CWnd::SetTimer(...). Post a message back to the main thread when the operation has finished.

2. Spawn a UI-thread from which you display a dialog box with a progress indicator while the main thread is blocked. Update the progress indicator with a timer in the dialog box.


N.B. None of the suggested solutions above is easy and if you don't know how to do it, you will have to ask a lot of questions in the VC++/MFC and COM forums.

Read this article[^] regarding how to create UI-threads if you need to.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown

GeneralRe: Manage Timer on MFC Pin
CDRAIN19-Apr-07 1:12
CDRAIN19-Apr-07 1:12 
QuestionRe: Manage Timer on MFC Pin
Roger Stoltz19-Apr-07 1:48
Roger Stoltz19-Apr-07 1:48 
AnswerRe: Manage Timer on MFC [modified] Pin
CDRAIN19-Apr-07 2:45
CDRAIN19-Apr-07 2:45 
GeneralRe: Manage Timer on MFC Pin
Roger Stoltz19-Apr-07 4:23
Roger Stoltz19-Apr-07 4:23 
GeneralRe: Manage Timer on MFC Pin
CDRAIN19-Apr-07 23:34
CDRAIN19-Apr-07 23:34 
GeneralRe: Manage Timer on MFC Pin
Roger Stoltz23-Apr-07 23:53
Roger Stoltz23-Apr-07 23:53 
QuestionHow you size your views? Pin
baerten17-Apr-07 23:11
baerten17-Apr-07 23:11 
AnswerRe: How you size your views? Pin
Mark Salsbery18-Apr-07 6:28
Mark Salsbery18-Apr-07 6:28 
GeneralRe: How you size your views? Pin
baerten18-Apr-07 21:26
baerten18-Apr-07 21:26 
GeneralRe: How you size your views? Pin
Mark Salsbery19-Apr-07 8:07
Mark Salsbery19-Apr-07 8:07 
GeneralRe: How you size your views? Pin
baerten19-Apr-07 23:10
baerten19-Apr-07 23:10 
GeneralRe: How you size your views? Pin
Mark Salsbery20-Apr-07 7:26
Mark Salsbery20-Apr-07 7:26 
Question_splitpath Issue Pin
Programm3r17-Apr-07 22:54
Programm3r17-Apr-07 22:54 
AnswerRe: _splitpath Issue Pin
Cedric Moonen17-Apr-07 23:21
Cedric Moonen17-Apr-07 23:21 
GeneralRe: _splitpath Issue Pin
Programm3r18-Apr-07 0:49
Programm3r18-Apr-07 0:49 
QuestionWhere to create font and set it to owner drawn menu Pin
Atul2317-Apr-07 22:48
Atul2317-Apr-07 22:48 
AnswerRe: Where to create font and set it to owner drawn menu Pin
Hamid_RT18-Apr-07 1:41
Hamid_RT18-Apr-07 1:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.