CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2012
    Posts
    20

    MFC get input keys in while loop

    I don't know how to bypass how MFC handles messages but I need to read input character keys while being in a while loop. An example is posted below;

    Code:
    runmode=1;
    	//get input keys from keyboard some how 
    
    		while(runmode==1)
    		{
    			wait(50);
                     //get input keys
    		}
    		break;
    While this is may be an infinite loop it shows that I need to get input keys while the while loop is operating, so CRichEditCtrl::OnChar simply won't work because the message handle doesn't process until after the code completes execution.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: MFC get input keys in while loop

    What are you doing (or going to do) within this infinite loop?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2012
    Posts
    20

    Re: MFC get input keys in while loop

    I'm going to read key strokes and send the key strokes to a microcontroller and have the microcontroller process them and send back commands that may end the infinite loop.

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

    Re: MFC get input keys in while loop

    But why the loop? Why bypass normal Windows message processing? Why not just respond to key events as you get them?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: MFC get input keys in while loop

    Quote Originally Posted by printz0r View Post
    I'm going to read key strokes and send the key strokes to a microcontroller and have the microcontroller process them and send back commands that may end the infinite loop.
    And what does it have to do with the CRichEditCtrl?
    Victor Nijegorodov

  6. #6
    Join Date
    Mar 2012
    Posts
    20

    Re: MFC get input keys in while loop

    RichEditCtrl displays values that the microcontroller outputs. The loop is important because there are various modes the microcontroller is in. Sometimes it should get values, othertimes it shouldn't

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: MFC get input keys in while loop

    You should avoid implementing such type of loops (like infinite)in the main GUI thread.
    Create a worker thread and move this infinite loop to get values from the microcontrollers in this worker thread.
    Read about Using Worker Threads
    Victor Nijegorodov

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