Click here to Skip to main content
15,915,708 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Printing bitmaps from a frame grabber Pin
Bob Hickey14-Oct-06 16:00
Bob Hickey14-Oct-06 16:00 
QuestionDialog 'hang' after C procedure called. Pin
searcher0812-Oct-06 15:56
searcher0812-Oct-06 15:56 
AnswerRe: Dialog 'hang' after C procedure called. Pin
Christian Graus12-Oct-06 15:58
protectorChristian Graus12-Oct-06 15:58 
GeneralRe: Dialog 'hang' after C procedure called. Pin
XuShanghua12-Oct-06 17:07
XuShanghua12-Oct-06 17:07 
GeneralRe: Dialog 'hang' after C procedure called. Pin
Hamid_RT12-Oct-06 19:51
Hamid_RT12-Oct-06 19:51 
GeneralRe: Dialog 'hang' after C procedure called. Pin
searcher0813-Oct-06 7:43
searcher0813-Oct-06 7:43 
GeneralRe: Dialog 'hang' after C procedure called. Pin
Christian Graus13-Oct-06 8:03
protectorChristian Graus13-Oct-06 8:03 
AnswerRe: Dialog 'hang' after C procedure called. Pin
Don Fletcher12-Oct-06 21:22
Don Fletcher12-Oct-06 21:22 
Calling a function like this periodically (but not too often) during your computations should help:

<br />
// DoMessagePump - Allow windows message processing to occur<br />
int DoMessagePump()<br />
{<br />
	BOOL bCompleteFlag=FALSE;<br />
	MSG msg;<br />
	BOOL bDoingBackgroundProcessing=TRUE;<br />
<br />
	Sleep(1);<br />
<br />
	while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {<br />
		if (msg.message == WM_QUIT) {<br />
			bDoingBackgroundProcessing=FALSE;<br />
			::PostQuitMessage(0);<br />
			break;<br />
		}<br />
<br />
		if (!AfxGetApp()->PreTranslateMessage(&msg)) {<br />
			::TranslateMessage(&msg);<br />
			::DispatchMessage(&msg);<br />
		}<br />
	}<br />
		<br />
	AfxGetApp()->OnIdle(0);   // updates user interface<br />
	AfxGetApp()->OnIdle(1);   // frees temporary objects<br />
<br />
	if (bDoingBackgroundProcessing == FALSE) return -1;<br />
	if (bCompleteFlag == TRUE) return -1;<br />
<br />
	return 0;<br />
}<br />


This code implements basic message passing (the Windows GUI is based on a cooperative multitasking approach, so your code has to "cooperate" LOL).

Christian is of course correct - The best way to do this is put your code into a different thread, but that sometimes adds a layer of complexity you don't always need.

Beware the calls to AfxGetApp()->OnIdle() - MFC needs this to "breathe" but it can result in lots of overhead in your computation. The more often you call DoMessagePump() the better the GUI response will be, but the longer your computation will take.
GeneralRe: Dialog 'hang' after C procedure called. Pin
searcher0813-Oct-06 10:04
searcher0813-Oct-06 10:04 
Questionapi hooking Pin
DannSmith12-Oct-06 13:05
DannSmith12-Oct-06 13:05 
AnswerRe: api hooking Pin
Hamid_RT12-Oct-06 20:02
Hamid_RT12-Oct-06 20:02 
QuestionAppend data in middle of binary file Pin
samkook12-Oct-06 11:02
samkook12-Oct-06 11:02 
AnswerRe: Append data in middle of binary file Pin
PJ Arends12-Oct-06 11:32
professionalPJ Arends12-Oct-06 11:32 
GeneralRe: Append data in middle of binary file Pin
samkook12-Oct-06 11:51
samkook12-Oct-06 11:51 
GeneralRe: Append data in middle of binary file Pin
Christian Graus12-Oct-06 13:03
protectorChristian Graus12-Oct-06 13:03 
GeneralRe: Append data in middle of binary file Pin
samkook12-Oct-06 13:31
samkook12-Oct-06 13:31 
GeneralRe: Append data in middle of binary file Pin
Christian Graus12-Oct-06 14:10
protectorChristian Graus12-Oct-06 14:10 
GeneralRe: Append data in middle of binary file Pin
samkook12-Oct-06 15:00
samkook12-Oct-06 15:00 
GeneralRe: Append data in middle of binary file Pin
Christian Graus12-Oct-06 15:16
protectorChristian Graus12-Oct-06 15:16 
GeneralRe: Append data in middle of binary file Pin
samkook12-Oct-06 16:06
samkook12-Oct-06 16:06 
GeneralRe: Append data in middle of binary file Pin
Christian Graus12-Oct-06 16:13
protectorChristian Graus12-Oct-06 16:13 
GeneralRe: Append data in middle of binary file Pin
samkook12-Oct-06 16:19
samkook12-Oct-06 16:19 
GeneralRe: Append data in middle of binary file Pin
Christian Graus13-Oct-06 0:59
protectorChristian Graus13-Oct-06 0:59 
GeneralRe: Append data in middle of binary file Pin
David Crow13-Oct-06 3:00
David Crow13-Oct-06 3:00 
GeneralRe: Append data in middle of binary file [modified] Pin
samkook13-Oct-06 6:46
samkook13-Oct-06 6:46 

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.