Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2

    Is there a command to make running fullscreen app go into windowed mode?


    Is there a command to make running fullscreen app go into windowed mode, and how do I use it?

    I'd like the fullscreen program 1 to be external from the program 2 that will be running the command, that will make it windowed. Once that external program 1 is windowed the program 2 that executed the command will then come to the foreground. After use of that program 2 is finished I would like to have program 1 go back to fullscreen again and to the foreground. Windows is the OS.
    Last edited by pditty8811; October 11th, 2013 at 05:33 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by pditty8811
    Is there a command to make running fullscreen app go into windowed mode, and how do I use it?

    I'd like the fullscreen program 1 to be external from the program 2 that will be running the command, that will make it windowed. Once that external program 1 is windowed the program 2 that executed the command will then come to the foreground. After use of that program 2 is finished I would like to have program 1 go back to fullscreen again and to the foreground. Windows is the OS.
    Is this not possible?
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    Call ShowWindow() for the window handle and pass it SW_MAXIMIZE or SW_SHOW as needed.

    You probably also want to look at BringWindowToTop()
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by Scorpions4ever
    Call ShowWindow() for the window handle and pass it SW_MAXIMIZE or SW_SHOW as needed.

    You probably also want to look at BringWindowToTop()
    Thank you for this.

    Could you perhaps show me an example of how to use these built-in functions?
    If say the fullscreen app I want to make windowed is called "firstapp.exe" and the second one I want to bring to foreground is called "secondapp.exe".

    thank you for your help.
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    If you look at the pages I linked before, there are code samples linked from the bottom of the page.

    The only thing you might need to know is how to get the window handle of secondapp.exe before passing it to ShowWindow(). For that, there is FindWindow() which you can use if you know the title of the window for secondapp.exe or its Window class name (if you don't know that, you can easily find it out using the Spy.exe utility tool that comes with Visual C++). Again, there is also an example using FindWindow() in the bottom of the page I just linked.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    I think this is a bit over my head. Thanks anyway.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Could you perhaps show me an example of how to use these built-in functions?
    If say the fullscreen app I want to make windowed is called "firstapp.exe" and the second one I want to bring to foreground is called "secondapp.exe".
    The following is your "firstapp"...

    Code:
    #pragma comment(lib,"gdi32.lib")
    #pragma comment(lib,"user32.lib")
    
    #include <windows.h>
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;
        MSG messages;
        WNDCLASSEX wincl;
    
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;
        wincl.style = CS_DBLCLKS;
        wincl.cbSize = sizeof (WNDCLASSEX);
    
    
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;
        wincl.cbClsExtra = 0;
        wincl.cbWndExtra = 0;
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        if (!RegisterClassEx (&wincl))
            return 0;
    
    
        hwnd = CreateWindowEx (
                   0,
                   szClassName,
                   "Window1",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT,
                   CW_USEDEFAULT,
                   544,
                   375,
                   HWND_DESKTOP,
                   NULL,
                   hThisInstance,
                   NULL
               );
    
        ShowWindow(hwnd, SW_MAXIMIZE);
        UpdateWindow(hwnd);
    
        while (GetMessage (&messages, NULL, 0, 0))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
    
        return messages.wParam;
    }
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    The following is your "secondapp"...

    Code:
    #pragma comment(lib,"gdi32.lib")
    #pragma comment(lib,"user32.lib")
    #include <windows.h>
    
    #define IDC_MAIN_BUTTON	101			// Button identifier
    #define FULLSCREEN 0
    #define WINDOWED 1
    
    LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
    
    void CenterWindow(HWND hwndWindow)
    {
        HWND hParent = GetDesktopWindow();
        RECT rcChild = {0}, rcParent = {0};
        int nWidth, nHeight, nX, nY;
    
        // make the window relative to its parent
        GetWindowRect(hwndWindow, &rcChild);
        GetWindowRect(hParent, &rcParent);
    
        nWidth = (rcChild.right - rcChild.left) / 2;
        nHeight = (rcChild.bottom - rcChild.top) /2;
        nX = ((rcParent.right - rcParent.left) - nWidth) / 2 + rcParent.left;
        nY = ((rcParent.bottom - rcParent.top) - nHeight) / 2 + rcParent.top;
    
    
        int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
        int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
    
        // make sure that the dialog box never moves outside of the screen
        if (nX < 0) nX = 0;
        if (nY < 0) nY = 0;
        if (nX + nWidth > nScreenWidth) nX = nScreenWidth - nWidth;
        if (nY + nHeight > nScreenHeight) nY = nScreenHeight - nHeight;
    
        MoveWindow(hwndWindow, nX, nY, nWidth, nHeight, FALSE);
    }
    
    BOOL CALLBACK EnumWindowsProc( HWND hwnd, LONG lParam )
    {
        TCHAR buffer[512] = {0};
        SendMessage(hwnd,WM_GETTEXT,sizeof(buffer), (LPARAM)(void*)buffer);
        if(strcmp(buffer, "Window1") == 0)
    	{
            if(lParam == WINDOWED)
            {
                SetForegroundWindow(hwnd);
                CenterWindow(hwnd);
                UpdateWindow(hwnd);
            }
            else if(lParam == FULLSCREEN)
            {
                SetForegroundWindow(hwnd);
                ShowWindow(hwnd, SW_MINIMIZE);
                ShowWindow(hwnd, SW_MAXIMIZE);
                UpdateWindow(hwnd);
            }
        return FALSE;
    	}
    return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
    {
        WNDCLASSEX wClass;
        ZeroMemory(&wClass,sizeof(WNDCLASSEX));
        wClass.cbClsExtra=NULL;
        wClass.cbSize=sizeof(WNDCLASSEX);
        wClass.cbWndExtra=NULL;
        wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
        wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
        wClass.hIcon=NULL;
        wClass.hIconSm=NULL;
        wClass.hInstance=hInst;
        wClass.lpfnWndProc=(WNDPROC)WinProc;
        wClass.lpszClassName="Window Class";
        wClass.lpszMenuName=NULL;
        wClass.style=CS_HREDRAW|CS_VREDRAW;
    
        if(!RegisterClassEx(&wClass))
        {
            int nResult=GetLastError();
            MessageBox(NULL,
                       "Window class creation failed\r\n",
                       "Window Class Failed",
                       MB_ICONERROR);
        }
    
        HWND hWnd=CreateWindowEx(NULL,
                                 "Window Class",
                                 "Windows application",
                                 WS_OVERLAPPEDWINDOW,
                                 200,
                                 200,
                                 640,
                                 480,
                                 NULL,
                                 NULL,
                                 hInst,
                                 NULL);
    
        if(!hWnd)
        {
            int nResult=GetLastError();
    
            MessageBox(NULL,
                       "Window creation failed\r\n",
                       "Window Creation Failed",
                       MB_ICONERROR);
        }
    
        ShowWindow(hWnd,nShowCmd);
    
        MSG msg;
        ZeroMemory(&msg,sizeof(MSG));
    
        while(GetMessage(&msg,NULL,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return 0;
    }
    
    LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        switch(msg)
        {
        case WM_CREATE:
        {
    
            // Create a push button
            HWND hWndButton=CreateWindowEx(NULL,
                                           "BUTTON",
                                           "Start Processing",
                                           WS_TABSTOP|WS_VISIBLE|
                                           WS_CHILD|BS_DEFPUSHBUTTON,
                                           10,
                                           100,
                                           200,
                                           48,
                                           hWnd,
                                           (HMENU)IDC_MAIN_BUTTON,
                                           GetModuleHandle(NULL),
                                           NULL);
        }
        break;
    
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
            case IDC_MAIN_BUTTON:
            {
                // firstapp is changed to Windowed
                EnumWindows(EnumWindowsProc, WINDOWED);
                Sleep(5000);
                // Bring secondapp to foreground
                SetForegroundWindow(hWnd);
                Sleep(5000);
                // Maximize first app
                EnumWindows(EnumWindowsProc, FULLSCREEN);
                Sleep(5000);
                // Terminate secondapp
                PostQuitMessage(0);
            }
            break;
            }
            break;
        case WM_QUIT:
            EnumWindows(EnumWindowsProc, FULLSCREEN);
            break;
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
        break;
        }
         return DefWindowProc(hWnd,msg,wParam,lParam);
    }
    Click on the Start Processing button of the second app to get a demonstration of the interaction of the two apps.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Hi, I'm sorry. Perhaps I should clarify what I was looking for. It seems you spent alot of time on that.


    I am creating a mod for a game. The game is "firstapp.exe" well call it. And my mod will be "secondapp.exe". So, for obvious reasons I cannot edit the source code of the firstapp, which is a 3rd party game.

    How it will work is the game will be fullscreen as it is played. Once the game is saved, a file is created externally (save game file), which will launch my "secondapp.exe" mod. I will trigger the mod to launch from a batch file that will be looking for these save game files and then launch my secondapp.exe when a new save game file is created.

    But all that aside, my secondapp.exe is the only source code I can edit with these ShowWindow() functions. So, when secondapp.exe launches (through the batch script), I'd like the game (firstapp.exe) to go windowed and the secondapp.exe to go to the foreground. Then when the secondapp.exe is closed, I'd like firstapp.exe (the game) to go back to fullscreen.

    Does this make sense? And is it possible?
    Last edited by pditty8811; October 22nd, 2013 at 09:12 PM.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    The "firstapp" with source code from my previous post isn't really relevant for your task. I just used this "firstapp" as proof of concept (POC) code to prove that the "secondapp" does in fact work. In your scenario , "firstapp" would be your game binary.

    What you need to do is get the name of the window from the game binary. If the name of the window is not easily accessible, I would then suggest that you use Scorpions4ever recommendation to use the Spy utility to acquire the name.

    When you have the window name, you must change "Window1" in the following code from "secondapp" to the name of the window in the game binary.

    Code:
    BOOL CALLBACK EnumWindowsProc( HWND hwnd, LONG lParam )
    {
        TCHAR buffer[512] = {0};
        SendMessage(hwnd,WM_GETTEXT,sizeof(buffer), (LPARAM)(void*)buffer);
    // Change Window1 to game binary window name
        if(strcmp(buffer, "Window1") == 0)
    	{
            if(lParam == WINDOWED)
            {
                SetForegroundWindow(hwnd);
                CenterWindow(hwnd);
                UpdateWindow(hwnd);
            }
            else if(lParam == FULLSCREEN)
            {
                SetForegroundWindow(hwnd);
                ShowWindow(hwnd, SW_MINIMIZE);
                ShowWindow(hwnd, SW_MAXIMIZE);
                UpdateWindow(hwnd);
            }
        return FALSE;
    	}
    return TRUE;
    }
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by BobS0327
    The "firstapp" with source code from my previous post isn't really relevant for your task. I just used this "firstapp" as proof of concept (POC) code to prove that the "secondapp" does in fact work. In your scenario , "firstapp" would be your game binary.

    What you need to do is get the name of the window from the game binary. If the name of the window is not easily accessible, I would then suggest that you use Scorpions4ever recommendation to use the Spy utility to acquire the name.

    When you have the window name, you must change "Window1" in the following code from "secondapp" to the name of the window in the game binary.

    Code:
    BOOL CALLBACK EnumWindowsProc( HWND hwnd, LONG lParam )
    {
        TCHAR buffer[512] = {0};
        SendMessage(hwnd,WM_GETTEXT,sizeof(buffer), (LPARAM)(void*)buffer);
    // Change Window1 to game binary window name
        if(strcmp(buffer, "Window1") == 0)
    	{
            if(lParam == WINDOWED)
            {
                SetForegroundWindow(hwnd);
                CenterWindow(hwnd);
                UpdateWindow(hwnd);
            }
            else if(lParam == FULLSCREEN)
            {
                SetForegroundWindow(hwnd);
                ShowWindow(hwnd, SW_MINIMIZE);
                ShowWindow(hwnd, SW_MAXIMIZE);
                UpdateWindow(hwnd);
            }
        return FALSE;
    	}
    return TRUE;
    }
    OK great, I can do that.

    To call the function EnumWindowsProc above how would I do that. I see it takes two parameters, one an HWND object and the other a long data type. Is this correct? Or is long another objecT?
    Last edited by pditty8811; October 22nd, 2013 at 10:51 PM.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    To call the function EnumWindowsProc above how would I do that. I see it takes two parameters, one an HWND object and the other a long data type. Is this correct? Or is long another objecT?
    The source code for "secondapp" in my previous post is a complete fully functional app that demonstrates how to call EnumWindowsProc etc.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by BobS0327
    The source code for "secondapp" in my previous post is a complete fully functional app that demonstrates how to call EnumWindowsProc etc.
    OK so I call it like this:
    EnumWindows(EnumWindowsProc, WINDOWED);

    For windowed.

    How come I'm passing in a string for the second param but the data type is LONG?
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Originally Posted by pditty8811
    OK so I call it like this:
    EnumWindows(EnumWindowsProc, WINDOWED);

    For windowed.

    How come I'm passing in a string for the second param but the data type is LONG?
    You're not passing a string. WINDOWED is not a string. WINDOWED is essentially defined to be the value 1 (ONE) by using a preprocessor directive at the top of the source code file...

    Code:
    #define WINDOWED 1
    Thus, wherever WINDOWED is found, it is replaced with the value 1 (ONE). Check this link out for additional info on preprocessor directives.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by BobS0327
    You're not passing a string. WINDOWED is not a string. WINDOWED is essentially defined to be the value 1 (ONE) by using a preprocessor directive at the top of the source code file...

    Code:
    #define WINDOWED 1
    Thus, wherever WINDOWED is found, it is replaced with the value 1 (ONE). Check this link out for additional info on preprocessor directives.
    Hi, ok I've been fiddling around with your code. I am able to window the window of the firstapp, if the first app is already in winowed mode. It makes the window smaller. Then if I click the button again it goes to fullscrean.

    But if the firstapp is in fullscreen mode I am unable to window it.

    When It is in fullscreen mode it actually shows in UI Spy (the program referenced above to find window title) that it is a "pane" and not a "window", like it is called when it is windowed. The title of the windows are correct, when I edit your program. So I am unsure why I cannot go from fullscreen 3d app, to windowed using your program.

    Also, how do I change the size of the window that it turns into when I press the button? What part of your code do I have to change to change the size of the window?

    Thank you.
    Last edited by pditty8811; January 12th, 2014 at 10:02 PM.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Also, how do I change the size of the window that it turns into when I press the button? What part of your code do I have to change to change the size of the window?
    One option is to use AdjustWindowRectEx to manipulate the size of your target window.

    You can also use the above Win32 API call to address your fullscreen window issue.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo