alt tab to console app

I need to alt tab to console app with function.
Using #include <windows.h>
Have this piece of code to make console app be always on top
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
HWND consoleWindowHandle = GetConsoleWindow();

    if( consoleWindowHandle ){
        cout << endl << "Setting up associated console window ON TOP !";
        SetWindowPos(
            consoleWindowHandle, // window handle
            HWND_TOPMOST, // "handle to the window to precede
                          // the positioned window in the Z order
                          // OR one of the following:"
                          // HWND_BOTTOM or HWND_NOTOPMOST or HWND_TOP or HWND_TOPMOST
            0, 0, // X, Y position of the window (in client coordinates)
            0, 0, // cx, cy => width & height of the window in pixels
            SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW // The window sizing and positioning flags.
        );
        // OPTIONAL ! - SET WINDOW'S "SHOW STATE"
        ShowWindow(
            consoleWindowHandle, // window handle
            SW_NORMAL // how the window is to be shown
                      // SW_NORMAL => "Activates and displays a window.
                      // If the window is minimized or maximized,
                      // the system restores it to its original size and position.
                      // An application should specify this flag
                      // when displaying the window for the first time."
        );
        cout << endl << "Done.";
    } else {
        cout << endl << "There is no console window associated with this app :(";
    }

So I need to make this console app always on top and have possibility to alt tab to this application by some windows lib function.
Big thanks in advance
Last edited on
here are instructions to AOT a console window.
https://www.thewindowsclub.com/how-to-enable-always-on-top-for-windows-terminal

I don't know if you can rig code to make those same things happen easily or not. Its not at the program level, its at the shell level ... but maybe the program can tamper with its own shell to save, set, and restore the values?
Topic archived. No new replies allowed.