Page 1 of 1

Minimized window and programrunning

Posted: Mon May 20, 2024 7:27 pm
by jak64
Hello everyone,
I'm writing a program that allows me to run games (over 300 that are on my hard drive). They are classified by categories, in a ListView and when you click on a category, the corresponding games are displayed in a second ListView.

By clicking on the name of a game, 4 screenshots of the selected game are displayed on the right.

Below there are two buttons (one to launch the game and another to put it in the "My favorite games" category).

By clicking on the button that launches the game, I minimize the window because some games take a long time to start and I don't want people to click on the button several times to launch the game.

What I would like to do:

When you stop the game you are playing, I would like to return the window to full screen. I know there is the ProgramRunning statement but since my window is minimized I don't think it would work because I think if my program is minimized then it doesn't run anymore...

Do you have an idea to return to full screen when the game is stopped?

thank you

Re: Minimized window and programrunning

Posted: Mon May 20, 2024 8:18 pm
by boddhi
Hello,

How do you launch your game? With RunProgram()?
Why not a timer that would test at regular intervals if your game is still running?

EDIT: After several tests, it's not probably the better way...

Re: Minimized window and programrunning

Posted: Mon May 20, 2024 10:09 pm
by Jeromyal
Have you tried the #PB_Program_Wait flag with RunProgram ?

1) launch button gets pressed and calls your procedure with game path and name passed into it

2) DisableWindow(#Window, #True)

3) HideWindow(#Window, #True)

4) Result = RunProgram(Filename$ [, Parameter$, WorkingDirectory$ [, #PB_Program_Wait [, SenderProgram]]])

5) DisableWindow(#Window, #False)

6) HideWindow(#Window, #Fasle)

7) SetWindowState(#Window, #PB_Window_Maximize)

8) end of your procedure

Re: Minimized window and programrunning

Posted: Mon May 20, 2024 10:37 pm
by jak64
Hello Jeromyal,
Thank you for your answer. I tested but it didn't work, I was able to click the button a second time to launch the game.

Let me explain :
For some games, when they are launched, nothing happens for several seconds, sometimes 10 seconds and only the first screen of the game appears (the program loads the resources necessary for the game).

In this case, my program stays in the foreground for these 10 seconds and I can click the button a second time to play, or even more...

Re: Minimized window and programrunning

Posted: Mon May 20, 2024 10:55 pm
by jak64
Hello,
Actually, I just added the "#PB_Program_Wait" parameter as suggested by Jeromyal and it's ok like that! I'm really stupid!!!

Here is my corresponding piece of code (I'm French, that's why there is French in the code...)

Code: Select all

          ;= Clic sur le bouton pour jouer à ce jeu
        Case #BoutonJouer
          Select EventType()
            Case #PB_EventType_LeftClick ; Clic gauche sur le bouton Jouer à ce jeu
              ;= Mettre le clavier en Français
              ActivateKeyboardLayout_(MakeLong(1036, 1036), 0) 
              ;= Minimiser la Fenêtre
              SetWindowState(#FenetreWindows, #PB_Window_Minimize)
              ;= Le programme du jeu est lancé
              If RunProgram(NomDuJeuSelectionne + ".exe","",CheminProgramme, #PB_Program_Wait)
                ;= Maximiser la fenêtre
                SetWindowState(#FenetreWindows, #PB_Window_Maximize)
              Else
                MessageRequester("Programme", "Jeu - " + CheminProgramme + " - non trouvé !")
                End
              EndIf 
          EndSelect

Re: Minimized window and programrunning

Posted: Wed May 22, 2024 9:48 am
by Jeromyal
The only thing I think I would personally change with your code would be the line -

Code: Select all

SetWindowState(#FenetreWindows, #PB_Window_Minimize)
TO -

Code: Select all

If FileSize(NomDuJeuSelectionne + ".exe") > 0 : SetWindowState(#FenetreWindows, #PB_Window_Minimize) : EndIf
For the off chance your game EXE doesn't exist, your window won't minimize and then maximize with no evident purpose.

For your problem with the button being able to be pressed multiple times you can use DisableGadget(#Gadget, State) after it is pressed and re-enable when your game fails to start or finishes running and is maximizing your window again.

Happy coding :D

Re: Minimized window and programrunning

Posted: Wed May 22, 2024 10:37 am
by jak64
Thank you for your advice Jeromyal