controls go dead

I have an application that goes into a loop and waits (using WaitCommEvent) 
for data to come into the serial port. My problem is that once I enter that 
loop, all my CButton's go stupid. The checkbox won't check, the OK and Cancel 
buttons don't work.  Below is the code in question, post a note if this is 
not enough info. These Functions are all part of a CDialog class--PickOps.cpp


while(m_PauseCheckBox.GetState() == BST_UNCHECKED){
       controllerResponse = "";
	    //Tells controller to begin polling
       waitForAnswer(&controllerResponse);
	   
	   if(m_PauseCheckBox.GetState() == BST_CHECKED)
		   OnStop();
	   if(strlen(controllerResponse) > 0){  //if response invalid, empty string 
returned
		   //return negative address for reverse, positive address for forward
	      requestSectionNumber = decodeControllerResponse(controllerResponse);
           
	      int address = requestSectionNumber - SECTION_ADDRESS_OFFSET;
	      if(requestSectionNumber > 0){
	   	     if(arraySecStats[address].canProceed){
		        arraySecStats[address].curRecordNum++;
			 
			 //Obtain Section Table Name
			    CString tableName = "Section ";
		        char sectionNum[3];
		        _itoa(address+1,&sectionNum[0],10);
		        tableName += sectionNum;
			 
			 //Open table and recordset
                CDaoTableDef* secTD = 
dat.openTableDef(secDB,(char*)tableName.GetBuffer(strlen(tableName)));
		        CDaoRecordset* secRS = dat.openRecordset(secTD,secDB);
		     
			 //position Recordset pointer on current record
		        seekRecordNumber(secRS,arraySecStats[address].curRecordNum);
		     
			 //send data to section
		        writeToSection(secRS);
		        secRS->Close();
		        secTD->Close();
             
			 //update other sections as needed
			    processIsWaitingForUpdate(address,bco,secDB);
			 
			    saveCurrentRecordNumber(address);
				startPolling();
			 }
		  }                             //inner if
		  else{
			//can't proceed
            arraySecStats[address].isWaitingForUpdate = TRUE; 
			arraySecStats[address].canProceed = FALSE;
			sendBlockedSectionMessage(requestSectionNumber,FALSE,bco );
			startPolling();  //resume polling
		  }	
		
	   }                          //outer if
	   else {
		
       //TO DO add code to go backwards
	   }
	   
	}   


void PickOps::waitForAnswer(CString* answer){
	
       BicoOutput* bco = new BicoOutput();
	  	  
	   serialPort serPort;
	   HANDLE sp;
	   OVERLAPPED overlapped;
	   DWORD dwEventMask;
	   bool setEventMask;
       DefaultData::commPortType cpt;
       DefaultData ddata;
	   char inChar;
	   
	   

       
	   ddata.getCommDefaults(&cpt);  //Get comm settings
	   sp = serPort.openPort(cpt);               //openPort
            
	   setEventMask = SetCommMask(sp,EV_RXCHAR);
	   if(!setEventMask)
		   AfxMessageBox("Failed to Set Communication Mask");
       
	   overlapped.hEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
	   overlapped.Internal = 0;
	   overlapped.InternalHigh = 0;
	   overlapped.Offset = 0;
	   overlapped.OffsetHigh = 0;
	   assert(overlapped.hEvent);
       inChar = 'n'; //something other than carriage return
	   while(inChar != 0x0d){
	      if(WaitCommEvent(sp,&dwEventMask,&overlapped)){
			  if(dwEventMask & EV_RXCHAR){
			     inChar = serPort.getOneChar(sp);
                 *answer += inChar;
			  }
		  }
	   }
       
	   
	   serPort.closePort(sp);
	   serPort.~serialPort();
	   ddata.~DefaultData();
	        


}
0
bicoman (15)
1/24/2005 5:32:19 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
714 Views

Similar Articles

[PageSpeed] 3

bicoman wrote:
> I have an application that goes into a loop and waits (using WaitCommEvent) 
> for data to come into the serial port. My problem is that once I enter that 
> loop, all my CButton's go stupid. The checkbox won't check, the OK and Cancel 
> buttons don't work.  Below is the code in question, post a note if this is 
> not enough info. These Functions are all part of a CDialog class--

You are seeing how Windows works. The windows and controls respond to 
messages from Windows.  While your code is looping or waiting then your 
program doesn't get any messages - they are waiting for you to return to 
MFC.  No paint messages, no click messages, ...etc.

To keep the GUI working all of your message handlers must execute in a 
short time and then return.  If you need to execute a time consuming 
loop or a blocking call like WaitCommEvent you should put that code in a 
separate thread.  For a multithreaded serial port example, see the MTTTY 
sample in MSDN.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
1/24/2005 11:01:24 PM
I don't know, I just looked at your code real quick. Are you having the
same problem as any of these posts?

http://groups-beta.google.com/groups?q=waitcommevent%20hangs&hl=en&lr=&safe=off&sa=N&tab=wg

0
szuchymj (5)
1/25/2005 12:30:35 AM
Scott, Thanks.
But making the waitCommEvent a separate thread probably won't do
to much good. Even when I comment the method that calls waitCommEvent,
my dialogs controls still go dead. It seems that Wiindows only checks for 
mouse events if there is nothing actually executing.  Maybe if I make a 
thread of the whole set of functions that are in the class in question, do 
you think that would work? Would the messages handlers get executed or would 
the thread also take control of the program?
Mike


szuchymj, 
Thanks. But my WaitCommEvent is not hanging, its just that the controls on 
my dialog
go dead once the function that calls waitCommEvent begins to execute. If I 
didn't need to be able to stop the program without generating error messages, 
everything would be fine. WaitCommEvent works, its pulling down the data and 
acting on it.
Mike


"Scott McPhillips [MVP]" wrote:

> bicoman wrote:
> > I have an application that goes into a loop and waits (using WaitCommEvent) 
> > for data to come into the serial port. My problem is that once I enter that 
> > loop, all my CButton's go stupid. The checkbox won't check, the OK and Cancel 
> > buttons don't work.  Below is the code in question, post a note if this is 
> > not enough info. These Functions are all part of a CDialog class--
> 
> You are seeing how Windows works. The windows and controls respond to 
> messages from Windows.  While your code is looping or waiting then your 
> program doesn't get any messages - they are waiting for you to return to 
> MFC.  No paint messages, no click messages, ...etc.
> 
> To keep the GUI working all of your message handlers must execute in a 
> short time and then return.  If you need to execute a time consuming 
> loop or a blocking call like WaitCommEvent you should put that code in a 
> separate thread.  For a multithreaded serial port example, see the MTTTY 
> sample in MSDN.
> 
> -- 
> Scott McPhillips [VC++ MVP]
> 
> 
0
bicoman (15)
1/25/2005 12:51:06 AM
bicoman wrote:
> Scott, Thanks.
> But making the waitCommEvent a separate thread probably won't do
> to much good. Even when I comment the method that calls waitCommEvent,
> my dialogs controls still go dead. It seems that Wiindows only checks for 
> mouse events if there is nothing actually executing.  Maybe if I make a 
> thread of the whole set of functions that are in the class in question, do 
> you think that would work? Would the messages handlers get executed or would 
> the thread also take control of the program?
> Mike

You don't quite understand:  Windows checks for mouse events all the 
time.  It puts them in your program's message queue.  Your program only 
checks for these messages when you return to MFC.

The dialog controls, and MFC, are part of your program and run in your 
main thread.  They cannot process messages from your queue until you 
return to MFC.

Yes, you should move all of the serial port handling into a thread.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
1/25/2005 1:37:22 AM
Sorry I couldn't help......tell us if you got it working successfully.

0
szuchymj (5)
1/25/2005 8:08:06 AM
Reply:

Similar Artilces:

Where do Write-In Products go after you create them?
When I create a quote and wish to add a new product and set the price from within the CRM GUI, I use "write-in" products. After I do this, I can see them in that quote, but they do not appear to any available product list. Is there a way to display the Write-In products? This actually is stored as a part of the QuoteDetail. The write in product is specific to that quote only. Sean Fullerton "TurboCAT" <myles@twitch.ca> wrote in message news:9867cf87.0406161146.2e4e9fda@posting.google.com... > When I create a quote and wish to add a new product and set the pri...

why won't word 2007 release control of a .rtf file after exiting w
I AM HAVING TROUBLE WITH ACCESS TO RICH TEXT FILES BY PROGRAMS OTHER THAN WORD------ AFTER THE FILE OPEN IN WORD IS CLOSED AND EVEN AFTER WORD HAS BEEN SHUT DOWN (EXITED) ---------- I GET THE ERROR MESSAGE THAT THE FILE IS "IN USE" BY WORD WHEN (FOR EXAMPLE) AN ATTEMPT IS MADE TO DELETE IT ---- SOMETIMES WHEN RE-OPENING THE FILE AFTER RE-STARTING WORD THE FILE CANNOT BE SAVED BECAUSE IT IS IN "READ ONLY" MODE ------- AFTER MUCH FIDDLING AROUND I FINALLY MANAGED TO DELETE THE PROBLEM FILE ONLY TO HAVE THE SAME PROBLEM RETURN WITH A DIFFERNT FILE ----- WORD 200...

RE: Control
Can some one point me right direction to achive this following. Need to dispaly a data in a table format. some of the column data may have to display a image/icon based on a value from the table (1 :- Red color icon, 2:-yellow color icon...) Once the data is loaded and displayed on the format , able to search particular row by column index and update the values including the images(change different image). I tried with Listview control, with the report view I am not able to search row and update the columns with the List vew I am not able to show the image/icon. do not want to use ...

bound control or inbound control
Hi Katherine, There are differences between using bound versus unbound controls. Where on the form do you want to use an unbound control? Jeanette Cunningham "Katherine" <Katherine@discussions.microsoft.com> wrote in message news:23BBC192-0A74-4B9F-9513-5E5923A76658@microsoft.com... > ...

MSCRM login and the Users Control Panel
Is anyone aware of any way that the settings stored under Control Panel - Users - Password Management might interfere with the process of Single Sign On into MSCRM? It seemed to have somehow cached someones login and prevented logging in as the logged in user, until cached credentials had been "deleted". However I have never seen this mentioned as being relevant. I am not too sure what the architecture model is there, but it appears to be a single domain. If this area has any relevance, it would be useful to know....thanks ...

Adding a control variable
Hello all, Under VC++ 7.1, I've added a checkbox to a dialog. Using the dialog editor, I am not trying to add a control variable for this check box. However, when I right-click on the check box and select "Add Variable", the resulting wizard dialog does not allow me to select "Control Variable" (it is grayed out). What do I need to do to get a control variable for this check box added to my class? Thanks, Dave I've never seen that before - are you able to duplicate this problem with other projects too? -- Regards, Nish [VC++ MVP] "Dave" <bett...

Releasing memory after creating OCX control
Hi, I try to create an instance of an activex control in my MFC dialog based app. Though my application works with out any error, if i check the memory after calling "delete pMyControl" it keeps on occupying the same memory it occupied when the control was alive. Could anyone help me where I am missing to clear the memory? Thank you. My Code here ---------------m_pxWmp= new CWMPPlayer4();if( m_pxWmp->Create("replay", WS_CHILD | WS_BORDER | WS_VISIBLE , CRect(100, 100,320,240), this, 2)){ m_replay = true; m_pxWmp->SetUrl("C:\\video.avi"); m_pxWmp->Set...

Spam control - MS Outlook
Hi! I am using MS Outlook 2000 and use 2 profiles. I recently installed a firewall package (Fsecure = Telia S�ker Surf), including Spam control. After install, MSO hangs and I cannot change to the other profile (if I not removed MSO by ctrl/alt/del) Somebody want to comment this? /Sven-Erik Intergrated AV/Spam is the cause of frequent issues in Outlook Is the FSecure you installed compatible with this old version of Outlook? "Storfille" <storfille@ebrev.net> wrote in message news:b1Ixm.11987$U5.164765@newsb.telia.net... > Hi! > > I am using MS Outlook 200...

Outlook Go-Slow ...
I am having major problems with Outlook XP on a Go-Slow! Every time move to another message in my inbox Outlook sends a request to m Exchange Server. It can take up to 10 minutes to block delete a handfu of messages too. This happened shortly after receiving a message with what I assume wa an infected document, and which was not opened. As a precaution I hav run virus & trojan removal tools but nothing is ever found. Yesterday I backed up my PST, removed my mail account from the server created a new account and re-imported my PST. All ran fine for half a hour then it went back to this ...

stock control system
trying to see up a 'basic stock control sytem' for a warehouse that contains building materials. -- Thank you. You can use multiple ways of doing, there's 3 ways to come to m head... 1) Use a worksheet as database an save all the information on the cell of that worksheet using some macros to access it and handle. 2) You might want to use Access instead of Excel, I think would b easier to handle the database portion and you still have the Macro available. 3) You can use VB with an Access to create an application -- fanay ------------------------------------------------------...

Creating dialog controls at run-time
I've been researching how to do this, but whenever I try what other people do, I get very bad results. But my challenge doesn't end there. The number of controls I want to create is only known at run-time. The problems I face are manifold: 1. The code most people use fails badly. Not only is the font unconventionally big, but when I click the checkbox I create, the whole dialog disappears. If that's not enough, the pointer to the control is NULL when the dialog's destructor is called, so I can't delete the instance, and get a memory leak message when the program ends: CADi...

what control can display characters from txt files in a dialog?
I want to read lines from txt files and display them on a dialog.I wonder which control can be put into the dialog to hold the characters from txt? Something like :- while(m_file.ReadString(tmpstr)) { str += tmpstr; } m_edit.SetWindowText(str); -- Regards, Nish [VC++ MVP] "liao_xf" <sclxf@sina.com> wrote in message news:001401c3652f$177b9830$a001280a@phx.gbl... > Thanks first! > I know that Edit control can receive and edit input. > and I know the filestdio can read lines from txt. > but can you tell me how to attatch the lines to the edit? > Thanks!...

MDI support in ATL composite control
Hi, I have components created in ATL. The components are ATL composite controls. Entire work has been done till now using ATL, however I now need to give MDI type of work area (based o doc-view architecture) within the control. I have class derived from CMDIFrameWnd. However when I try to initialize instance of this class by calling "Create" method of CFrameWnd (base class in CMDIFrameWnd), I get error and creation fails. Tracing the code, I found that base class create method calls "AfxGetInstanceHandle" to get handle to the DLL. Now since this is ATL Composite control, ...

View Filtering and Access Controls for Business Units
I am trying to implement MS-CRM for my company. We have multiple Business Units . I need to give views to each Business Units so that they see only their own Contacts/Accounts/Opp lists. How do I accomplish this ? Also, If I gave inter business unit acesses , how do I make sure that the one business unit users can not modify any fields on other's Business Unit's records ? Thanks in advance for any help, Kishore This is quite easy to do with CRM. Assuming you have already created your Business Units in CRM, you can view a security role within one of the Business Units and a...

Tab Control Problems
I previously worked in VC++ 6.0, and have several applications that have either custom shadebox controls, or tab controls or group boxes. In all cases, when I moved the applications over to VS.NET 2003, everything was fine, except in the resource editor, I cannot see any of the controls that have been overlayed on a tab control, or a custom shadebox control and in some cases group boxes. I can tab to them and see the outline, but I cannot see the actual controls. If I drag a new control onto the tab control, I can see the control, but once it is saved, I can no longer access the cont...

FindRecord Control Button
i built a find record control button so a user can type in the form number and go there but it only searches the field that the cursor is in and the form # is not on the tab order(purposely). How can i specify where the find record function searches? thanks Ryan, usually people use an unbound combo box or an unbound text box for searching. There is a sample download with code of a search form at http://www.allenbrowne.com/ser-62.html If you need help to get it working, post back. You can also use the wizard to put a combo for searching on your form. On the form in design view, click the...

Controls coordinates
Hi everyone, Could somebody give me a simple example of getting a controls coordinates and then using them to put the control back where it was. So basicaly the control hasn't moved. Here's what I'm doing: m_cQuality.GetWindowRect(&qualityRC); ClientToScreen(&qualityRC); // int temp=qualityRC.Height(); // qualityRC.top=unyteRC.bottom-temp; // qualityRC.right=qualityRC.Width(); // qualityRC.left=0; // qualityRC.bottom=qualityRC.top+temp; // m_cQuality.MoveWindow(&qualityRC); m_cQuality.SetWindowPos(this, qualityRC.left, qualityRC.top, qualityRC.Width(), qualityRC.He...

User Control to Control Other User Control
Has anyone here created a control that controlled the content of other controls? I have my own custom ad control (for displaying space ads). I may have several on a page. What I'd like it to create another control that could determine how many instances of the first control existed on the current page, build a list of ads, and then set each control to show a particular ad. Is this practical? Suggestions? Thanks. Jonathan "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:uQ5stZRnKHA.1552@TK2MSFTNGP05.phx.gbl... > Has anyone...

Controlling drawing objects in Excel . . .
i m trying to do the following. 1) i draw 10 circles, 10 rectangles and 10 ellipses (all are scattering here & there) in excel. 2) i would like to change all the sizes of circles with minimum steps. [Is it possible to control in such a way that a circle is drawn as a master one, and that circle will be copied and copied until required number. When we want to change something to all circles, we will change the master circle, and all other circles will be automatically changed.] If someone knows, kindly explain to me. Thanks & Have a nice day!!! Thaw Htin Oo. Thaw, (Oo?) One...

Need more than 1208 controls per sheet
Hi, Does anyone know how to go around the limitation of MS Excel, which doesn't let the user, through automation, to create more than 1208 controls (checkboxes, buttons, or combination of two for example) on one sheet?? Thanks much! -- mowali ------------------------------------------------------------------------ mowali's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=20886 View this thread: http://www.excelforum.com/showthread.php?threadid=491476 I don't know whether it is possible to overcome the limit, but I would not use a worksheet where the ...

Outlook box pops up and won't go away; wants disk inserted
>A Microsoft Office Outlook box keeps popping up whenever I go to do >anything on my computer. AND it won't go away. It really never opens, it >just has lots of windows with errors on it that keep popping up. It >started when I went to send some Real Estate docs from one of my Real >Estate programs. I can't get rid of it and I can't send my documents with >my >Real Estate program. Had to print all the docs out and rescan them back >into the computer and then send them as an attachment. I have never opened >the Microsoft office outlook. I do use outloo...

MFC Table control or similar control
Hi, I have a MFC dialog database application that returns data which i then put into an excel spreadsheet and display onscreen. Due to license issues i would like to write the data to a user defined control. I would like this control to have a similar tabular look like the excel spreadsheet. It should also have the option on control to print out what data is in the control. I would also like to be able to put a bitmap on the control (Showing a logo). Can anyone give me advice on how what control(s) i should use to accomplish this? Thanks In Advance Macca You could buy a third party ...

Unprotection For ActiveX Control
I have a protected sheet but would like others to manipulate Spin Buttons (ActiveX variety) to change some of the data. But if the sheet is protected I can't use the spin buttons even when the cells to be manipulated are unprotected AND the spin buttons are unlocked. Is there ANY way to get around this without having to unprotect the entire sheet every time I use the spin buttons?? Thanks, --Abe Do you have a linkedcell? Is that cell locked? Can you unlock that linkedcell? You could put the linked cell on another sheet (or even in an unlocked hidden cell (hidden column or h...

Metrics are not available
Hi everyone, I get the following error message appear on my homepage when logging into GP9.0: "Metrics are not available because the Microsft Office Chart Control is Missing". This never appeared until we installed IE7 on all our systems, including the Citrix boxes where our users gain access to GP9.0. Following advice from a previous post I installed Office Web Components for Office XP onto the server, but it hasn't helped at all. Does anyone know a fix for this? Thanks all, T S Since the homepage is created and rendered on the individual workstation, I would look at...

Version Control of Database
Anybody have any suggestions for products to do version control of database objects? TIA - Jeff. Pretty much any source control. Source Safe, SCCS, CVS, any Gnu, etc. "Mr. Magic" <Mufasa@NoWhere.Com> wrote in message news:O29A5XnrKHA.1352@TK2MSFTNGP06.phx.gbl... > Anybody have any suggestions for products to do version control of > database objects? > > TIA - Jeff. http://en.wikipedia.org/wiki/Comparison_of_revision_control_software "Mr. Magic" <Mufasa@NoWhere.Com> wrote in message news:O29A5XnrKHA.1352@TK2MSFTNGP06...