How to check thread with MFC ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to check thread with MFC ?

  1. #1
    Join Date
    Feb 2013
    Posts
    14

    How to check thread with MFC ?

    I use MFC Find console window and send key to console like this.

    Code:
    HWND w;
    
    	w = FindWindow(NULL, L"c:\\users\\pkru\\documents\\visual studio 2010\\Projects\\CleanVirus\\Debug\\CleanVirus.exe");
    			
    
    			if(w==NULL)
    				MessageBox(NULL,_T("Not Found"), _T("OK"), MB_OK);
    
    
    
    			else{
    				DWORD dwProcessId = 0;
    GetWindowThreadProcessId( ::GetDesktopWindow(),
                              &dwProcessId );
    
    	while(TRUE){
    
    		//if(w!=NULL){
    				
    		//MessageBox(NULL,_T("Found"), _T("OK"), MB_OK);
    	
    	ir[0].EventType = KEY_EVENT;
        ir[0].Event.KeyEvent.bKeyDown = TRUE;
        ir[0].Event.KeyEvent.dwControlKeyState = 0;
        ir[0].Event.KeyEvent.uChar.UnicodeChar = 'y';
        ir[0].Event.KeyEvent.wRepeatCount = 1;
        ir[0].Event.KeyEvent.wVirtualKeyCode = 'Y';
        ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('Y', MAPVK_VK_TO_VSC);
    
        ir[1].EventType = KEY_EVENT;
        ir[1].Event.KeyEvent.bKeyDown = TRUE;
        ir[1].Event.KeyEvent.dwControlKeyState = 0;
        ir[1].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
        ir[1].Event.KeyEvent.wRepeatCount = 1;
        ir[1].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        ir[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);
    
    
        ir[2].EventType = KEY_EVENT;
        ir[2].Event.KeyEvent.bKeyDown = FALSE;
        ir[2].Event.KeyEvent.dwControlKeyState = 0;
        ir[2].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
        ir[2].Event.KeyEvent.wRepeatCount = 1;
        ir[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        ir[2].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);
    
    	 dwTmp = 0;
        WriteConsoleInput(hConIn, ir, 3, &dwTmp);
    
    	
    	 Sleep( 1000 );
    	}
    	
    	FreeConsole();
    }
    After program process success in console it not close console windows but it show like this in Output
    The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).
    I think if I can check when VC will show this line, then I can use FreeConsole(); for close console windows.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,385

    Re: How to check thread with MFC ?

    What app launches CleanVirus.exe? If your process is launching it, try to launch it with the /c switch.

    E.g.
    Code:
    C:\>"c:\users\pkru\documents\visual studio 2010\Projects\CleanVirus\Debug\CleanVirus.exe" /c

  3. #3
    Join Date
    Feb 2013
    Posts
    14

    Re: How to check thread with MFC ?

    C:\>"c:\users\pkru\documents\visual studio 2010\Projects\CleanVirus\Debug\CleanVirus.exe"

    is my project name in VC which FindWindow() read title from
    DWORD WINAPI unhidden(LPVOID lp)
    {

    system("C:/unhidden.bat");
    return 0;
    }

    And the code unhidden.bat is

    @echo off
    N:
    Unhidden.exe
    I try to use Unhidden.exe /c but it not close console window

    when process success it show like this in console. it not close console windows.
    Process complete !
    Press any key to continue . . .

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,027

    Re: How to check thread with MFC ?

    Quote Originally Posted by mmc01 View Post
    I try to use Unhidden.exe /c but it not close console window

    when process success it show like this in console. it not close console windows.
    If you run your program from VS with F5, you are not able to avoid being given with "Press any key to continue..." This is how VS works, and this has nothing to do with your code.
    Best regards,
    Igor

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center