-
October 29th, 2009, 08:50 AM
#1
How to enable a button press during a loop of appending edit box in MFC
Hi,
I have a dialog window developed in visual c++.net 2003 MFC. I have a edit box in the dialog, and also a generate and Abort button. in my code, I have a while loop to append information into the edit box, the while loop may take for a long time, so I need to have a abort button can be able to pressed during the while loop. but it looks like any button are not activated while the edit box is updated. So I would like to know if there is a easy way that I can get the abort button pressed so that I can setup a flag to break the while loop.
Thanks a lot!
Christine
-
October 29th, 2009, 08:57 AM
#2
Re: How to enable a button press during a loop of appending edit box in MFC
I don't know about a .net app since this isn't a .net forum.
In a regular VC Windows app, put PeetMessage and DispatchMessage inside your while loop and it will process pending messages, such as your button click.
-
October 29th, 2009, 09:14 AM
#3
Re: How to enable a button press during a loop of appending edit box in MFC
Thanks a lot! I'll give it a try.
-
October 29th, 2009, 09:39 AM
#4
Re: How to enable a button press during a loop of appending edit box in MFC
Such operations should be done on a worker thread, so that you leave the GUI thread free. If the user presses the Abort button you signal the thread to stop (for instance with a boolean flag, but you can also use other mechanisms).
-
October 29th, 2009, 09:52 AM
#5
Re: How to enable a button press during a loop of appending edit box in MFC
Originally Posted by cilu
Such operations should be done on a worker thread, so that you leave the GUI thread free. If the user presses the Abort button you signal the thread to stop (for instance with a boolean flag, but you can also use other mechanisms).
A message pump is easier and just as effective in most cases, IMHO.
-
October 30th, 2009, 03:06 PM
#6
Re: How to enable a button press during a loop of appending edit box in MFC
To me, if you are reading external data (i.e. network, serial port, etc), it warrants a worker thread. The main reason is that if you don't use a worker thread you can lose data in a single thread scenario because you can't control what the user will do to the UI while the data operation is going on.
Another reason for using a worker thread is that, imo, it's actually easier to code when you need to manage worker operations like start, stop, pause, and so on. Sure, you can do it in a single thread scenario, but usually that ends up more complicated than using a secondary thread.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|