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

C / C++ / MFC

 
GeneralDate/Time Picker in CListCtrl Pin
aswdwdwd26-May-04 6:40
aswdwdwd26-May-04 6:40 
GeneralCSerialPort Class Problem and Error 87 Pin
AnotherProgrammer26-May-04 6:25
AnotherProgrammer26-May-04 6:25 
GeneralPS - sorry, here's the link to that other post... Pin
AnotherProgrammer26-May-04 6:29
AnotherProgrammer26-May-04 6:29 
GeneralNetwork Order cponversion Pin
Stan the man26-May-04 6:17
Stan the man26-May-04 6:17 
GeneralRe: Network Order cponversion Pin
Ryan Binns26-May-04 19:05
Ryan Binns26-May-04 19:05 
GeneralGrabbing standard out to a pipe Pin
Anonymous26-May-04 5:57
Anonymous26-May-04 5:57 
GeneralRe: Grabbing standard out to a pipe Pin
Antti Keskinen26-May-04 11:46
Antti Keskinen26-May-04 11:46 
Generalwaiting for something to finished Pin
pnpfriend26-May-04 5:47
pnpfriend26-May-04 5:47 
Hi.. I have an application that create the thread at PRINT button is clicked, and stop the thread when STOP PRINTING button is clicked.

<br />
UINT PrintFile(LPVOID lParam)<br />
{<br />
	myApp *cc=(myApp*)lParam;<br />
  while(!stopprinting)<br />
  {	  <br />
    if(stopprinting)<br />
	{		<br />
		break;<br />
	}<br />
	cc->myClass->Print()<br />
  } <br />
  return 0;<br />
}<br />
<br />
void myApp::print()<br />
{<br />
....<br />
CWinThread *printingThread;  <br />
printingThread = AfxBeginThread(PrintFile,this);<br />
printingThread->m_bAutoDelete = FALSE;<br />
}<br />


then I have a class called myClass in the same application. myClass print the files, it ofcourse, has other functions except Print().

Ok here how Print() does print the file
<br />
void myClass::Print()<br />
{<br />
  for(int i=0;i<10;i++) <br />
{<br />
CString f=   array[i];<br />
 PrintFile(f); //send the file to printer<br />
 finishedprinting = false;<br />
 WaitForFilePrinted();<br />
finifhsedprinting = true;<br />
<br />
}<br />
}<br />

The printer server send the window messages when the file starts and ends printing doc, to application and myApp catch those messages. I had to used RegisterWindowMessage() and in MessageMap
I add following statement,
ON_REGISTERED_MESSAGE(BlackIcePrintMessage,OnPrinterMsg)
and then OnPrinterMsg() catch the messages and do something when the document get started printing, and ended printing. when the document get printed, finishedPrinting get set to true
<br />
finishedprinting = true;<br />


I want my application to be continue on the next file if and only if finishedprinting = true.
so I wrote following function to wait for the file to really get printed.
<br />
UINT WaitForFilePrinted(LPVOID lParam)<br />
{<br />
	myClass *cc=(myClass*)lParam;<br />
  while(!finishedprinting)<br />
  {	  <br />
    if(finishedprinting)<br />
	{		<br />
		break;<br />
	}<br />
	cc->WaitForPrinter();<br />
  } <br />
  AfxEndThread(1);			<br />
  return 0;<br />
}<br />
void myClass::WaitForFilePrinted(void)<br />
{<br />
	CWinThread *printingThread;  <br />
	printingThread = AfxBeginThread(WaitForFilePrinted,this);<br />
	printingThread->m_bAutoDelete = FALSE;<br />
<br />
}<br />
<br />
void myClass::WaitForPrinter(void)<br />
{<br />
	while(!finishedprinting)<br />
		Sleep(500);<br />
}<br />


I'm not sure I'm doing the right thing. And it is seems like thread inside another thread. it is not doing what I want to do..and I got access error. All I want is that
send the file to the printer..
wait for the messages from the printer..
when I get the message that the printer said the file get printed.. send next file
keep the same process, untill all the files gets printed.

could you please give me some suggestion how should I pause myApp so it will wait for the file just send to printer gets printed and then move on next one?

thank you
GeneralRe: waiting for something to finished Pin
valikac26-May-04 13:22
valikac26-May-04 13:22 
GeneralRe: waiting for something to finished Pin
pnpfriend27-May-04 8:50
pnpfriend27-May-04 8:50 
GeneralListView: XP - 2000 CPU usage Pin
Dan Hill26-May-04 5:35
Dan Hill26-May-04 5:35 
GeneralRe: ListView: XP - 2000 CPU usage Pin
Ryan Binns26-May-04 19:08
Ryan Binns26-May-04 19:08 
GeneralOCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 5:13
sweep12326-May-04 5:13 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
jmkhael26-May-04 5:28
jmkhael26-May-04 5:28 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 5:40
sweep12326-May-04 5:40 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
jmkhael26-May-04 5:42
jmkhael26-May-04 5:42 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 5:48
sweep12326-May-04 5:48 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
jmkhael26-May-04 5:57
jmkhael26-May-04 5:57 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 6:09
sweep12326-May-04 6:09 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 6:20
sweep12326-May-04 6:20 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
jmkhael26-May-04 7:05
jmkhael26-May-04 7:05 
GeneralRe: OCCMGR.CPP Assertion Error Line 410 Pin
sweep12326-May-04 21:29
sweep12326-May-04 21:29 
GeneralDynamic compilation in c/c++ Pin
mooze26-May-04 4:48
mooze26-May-04 4:48 
GeneralRe: Dynamic compilation in c/c++ Pin
Navin26-May-04 6:42
Navin26-May-04 6:42 
GeneralRe: Dynamic compilation in c/c++ Pin
mooze26-May-04 20:57
mooze26-May-04 20:57 

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.