CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Smile 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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    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.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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).
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to enable a button press during a loop of appending edit box in MFC

    Quote Originally Posted by cilu View Post
    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.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured