enocknitti
enocknitti

Reputation: 31

console to second display in windows

I am writing an MFC-app for windows. During development I am using a console window for debug output. What I want is to set this console so that it shows up on second display as default on start. Is it possible ??

Upvotes: 0

Views: 169

Answers (2)

enocknitti
enocknitti

Reputation: 31

After some fiddling I ended up with this:

#ifdef _DEBUG
    CONSOLE_FONT_INFOEX cfi;
    cfi.cbSize = sizeof(cfi);
    cfi.nFont = 0;
    cfi.dwFontSize.X = 0;                   // Width of each character in the font
    cfi.dwFontSize.Y = 24;                  // Height
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;

    wcscpy_s(cfi.FaceName, L"Consolas"); // Choose your font

    // Make a console window
    bool o = AllocConsole();
    SetConsoleOutputCP( CP_UTF8 );      // UTF-8 please

    // and a larger font so that I can read it :)
    SetCurrentConsoleFontEx( GetStdHandle( STD_OUTPUT_HANDLE ), FALSE, &cfi );

    HWND hWConsol = GetConsoleWindow();
    ::MoveWindow( hWConsol, -800, 0, 800, 800, true );
#endif

Corrected code, works as charm :) thanks !

Upvotes: 0

Vlad Feinstein
Vlad Feinstein

Reputation: 11321

You can get a handle to the monitor containing your app window:

HMONITOR hMyMonitor = ::MonitorFromWindow(MyHwnd, MONITOR_DEFAULTTOPRIMARY);

Then you can enumerate all monitors using EnumDisplayMonitors function

In your MONITORENUMPROC callback function, compare its monitor handle to hMyMonitor. If it is different - you found another monitor. Now you can use GetMonitorInfoW function to get MONITORINFO structure, containing

rcWork

A RECT structure that specifies the work area rectangle of the display monitor, expressed in virtual-screen coordinates.

Finally, you can get a handle to your console using GetConsoleWindow, and move it anywhere you want with MoveWindow

Upvotes: 3

Related Questions