Question : GetMessage() in MFC console app

Hi all,
I have an MFC console application, with main declared as follows:
int _tmain(int argc, _TCHAR* argv[])

Can I receive windows standard messages, key up/down etc.?
If I call GetMessage() it never returns (unless I send a message myself with PostThreadMessage), nothing even gets printed on the screen when I type - the thread is blocked, just waiting.

Any help is appreciated.

Answer : GetMessage() in MFC console app

What about sending a CTRL_C_EVENT to ypour console handler to terminate?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
#include <windows.h> 
#include <stdio.h> 
 
BOOL CtrlHandler( DWORD fdwCtrlType ) 
{ 
  switch( fdwCtrlType ) 
  { 
    // Handle the CTRL-C signal. 
    case CTRL_C_EVENT: 
      printf( "Ctrl-C event, exiting\n\n" );
      ExitProcess(0);
      return( TRUE );
 
    default: 
      return FALSE; 
  } 
} 
 
void main( void ) 
{ 
  if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) ) 
  { 
    printf( "\nThe Control Handler is installed.\n" ); 
 
    while( 1 ){ } 
  } 
  else 
    printf( "\nERROR: Could not set control handler"); 
}


// other thread:

  GenerateConsoleCtrlEvent(CTRL_C_EVENT,0);
Random Solutions  
 
programming4us programming4us