How to use WriteConsoleInput() in MFC?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to use WriteConsoleInput() in MFC?

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    14

    How to use WriteConsoleInput() in MFC?

    I can use WriteConsoleInput() in console application. But when I try to use writeConsoleInput() in MFC it not type any thing in command window. This's my code.

    Code:
    DWORD WINAPI test(LPVOID lp)
    {
        system("edit");
        return 0;
    }
    
    void CVirusScanDlg::OnBnClickedFormat()
    {
        HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
        HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
        DWORD dwTmp;
        INPUT_RECORD ir[5];
    
        CreateThread(NULL, 0, test,(LPDWORD)0, 0, &dwTmp);
    
        Sleep( 1000 );
    
        ir[0].EventType = KEY_EVENT;
        ir[0].Event.KeyEvent.bKeyDown = TRUE;
        ir[0].Event.KeyEvent.dwControlKeyState = 0;
        ir[0].Event.KeyEvent.uChar.UnicodeChar = 'u';
        ir[0].Event.KeyEvent.wRepeatCount = 1;
        ir[0].Event.KeyEvent.wVirtualKeyCode = 'U';
        ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('U', 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 = 'c';
        ir[1].Event.KeyEvent.wRepeatCount = 1;
        ir[1].Event.KeyEvent.wVirtualKeyCode = 'C';
        ir[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('C', MAPVK_VK_TO_VSC);
    
        ir[2].EventType = KEY_EVENT;
        ir[2].Event.KeyEvent.bKeyDown = TRUE;
        ir[2].Event.KeyEvent.dwControlKeyState = 0;
        ir[2].Event.KeyEvent.uChar.UnicodeChar = 'i';
        ir[2].Event.KeyEvent.wRepeatCount = 1;
        ir[2].Event.KeyEvent.wVirtualKeyCode = 'I';
        ir[2].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('I', MAPVK_VK_TO_VSC);
    
        ir[3].EventType = KEY_EVENT;
        ir[3].Event.KeyEvent.bKeyDown = TRUE;
        ir[3].Event.KeyEvent.dwControlKeyState = 0;
        ir[3].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
        ir[3].Event.KeyEvent.wRepeatCount = 1;
        ir[3].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        ir[3].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);
    
        ir[4].EventType = KEY_EVENT;
        ir[4].Event.KeyEvent.bKeyDown = FALSE;
        ir[4].Event.KeyEvent.dwControlKeyState = 0;
        ir[4].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
        ir[4].Event.KeyEvent.wRepeatCount = 1;
        ir[4].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        ir[4].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);
    
        dwTmp = 0;
        WriteConsoleInput(hConIn, ir, 5, &dwTmp);
        //FlushConsoleInputBuffer(hConIn);
        //WriteConsole(hConIn, "uci\n", 5, &dwTmp, NULL);
        //printf(" dwTmp = %d ", dwTmp);
    
        Sleep(1000);
    
      //return 0;
    }
    when I run this code it not type anything in command window. How to use WriteConsoleInput() in MFC ?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,923

    Re: How to use WriteConsoleInput() in MFC?

    Doesn't matter MFC or not, but in case you create Win32 App but not Win32 Console App, there is no console attached to the process.

    AttachConsole function
    Best regards,
    Igor

  3. #3
    Join Date
    Feb 2013
    Posts
    14

    Re: How to use WriteConsoleInput() in MFC?

    Thank you .

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center