(Windows) Launch/Close Programs With Fullscreen

Windows specific questions.
Post Reply
Username
Posts: 30
Joined: Jun 22, 2020 5:56

(Windows) Launch/Close Programs With Fullscreen

Post by Username »

Hey.
I've been wondering:
When the CHAIN command is used to launch another program, and then the program closes, when a fullscreen mode is used at least for the original program, the program won't do anything until the user switches it back to active again, such as by clicking it in the taskbar.
Is there a simple way to resume program execution after a called program quits, with no user interaction?
Thank you.
fxm
Moderator
Posts: 12582
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: (Windows) Launch/Close Programs With Fullscreen

Post by fxm »

Workaround on Windows:
fxm wrote: Aug 20, 2014 21:06 The only and best solution I've found to force a window to the foreground with the focus, whatever the starting configuration, is to run the 5 following commands in this order:
- Hide (not absolutely necessary, just to reduce a little the window flashing)
- Minimize
- Restore
- Foreground
- Focus

Test program:

Code: Select all

#INCLUDE "windows.bi"
#INCLUDE "fbgfx.bi"

DIM HandleWindow AS HWND

SCREEN 12

PRINT
PRINT " You have 5 seconds:"
PRINT "   - to put the graphic window in the background,"
PRINT "   - or to minimize the graphic window."
SLEEP 5000

SCREENCONTROL(FB.GET_WINDOW_HANDLE, CAST(INTEGER, HandleWindow))
ShowWindow(HandleWindow, SW_HIDE) 'Hide
ShowWindow(HandleWindow, SW_MINIMIZE) 'Minimize
ShowWindow(HandleWindow, SW_RESTORE) 'Restore
SetForegroundWindow(HandleWindow) 'Foreground
SetFocus(HandleWindow) 'Focus

PRINT
PRINT " The window is back in the foreground with the focus."

SLEEP
Username
Posts: 30
Joined: Jun 22, 2020 5:56

Re: (Windows) Launch/Close Programs With Fullscreen

Post by Username »

fxm wrote: Jul 15, 2022 4:49 Workaround on Windows:
fxm wrote: Aug 20, 2014 21:06 The only and best solution I've found to force a window to the foreground with the focus, whatever the starting configuration, is to run the 5 following commands in this order:
- Hide (not absolutely necessary, just to reduce a little the window flashing)
- Minimize
- Restore
- Foreground
- Focus

Test program:

Code: Select all

#INCLUDE "windows.bi"
#INCLUDE "fbgfx.bi"

DIM HandleWindow AS HWND

SCREEN 12

PRINT
PRINT " You have 5 seconds:"
PRINT "   - to put the graphic window in the background,"
PRINT "   - or to minimize the graphic window."
SLEEP 5000

SCREENCONTROL(FB.GET_WINDOW_HANDLE, CAST(INTEGER, HandleWindow))
ShowWindow(HandleWindow, SW_HIDE) 'Hide
ShowWindow(HandleWindow, SW_MINIMIZE) 'Minimize
ShowWindow(HandleWindow, SW_RESTORE) 'Restore
SetForegroundWindow(HandleWindow) 'Foreground
SetFocus(HandleWindow) 'Focus

PRINT
PRINT " The window is back in the foreground with the focus."

SLEEP
Thank you!
I will try that (at some point I'll get around to it).
dodicat
Posts: 8289
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: (Windows) Launch/Close Programs With Fullscreen

Post by dodicat »

I only use 2 of fxm's commands in the loop.

Code: Select all

'
'	tabstop=4
'
'	This is taken directly from the FreeBasic CHM file and just modified to work here.
'
'	include fbgfx.bi for some useful definitions
'
#include "windows.bi"
#include "fbgfx.bi"

#if __FB_LANG__ = "fb"
Using fb ' constants and structures are stored in the FB namespace in lang fb
#endif

ScreenRes 200, 50',,,GFX_ALWAYS_ON_TOP or GFX_HIGH_PRIORITY  'not needed

dim as any ptr win
Screencontrol(GET_WINDOW_HANDLE ,Cast(Integer, win))

	Dim e As Event
    
#macro focus
SetForegroundWindow(win) 
SetFocus(win)
#endmacro

	Do
        focus
    
		If (ScreenEvent(@e)) Then
            
			Select Case e.type
				Case EVENT_KEY_PRESS
					If (e.scancode = SC_ESCAPE) Then
                        shell "notepad key.dat"
                        kill "key.dat"
						End
						End If

					If (e.ascii > 0) Then
						open "key.dat" for append as #1
						Print #1, chr( e.ascii );
						close #1
						End If

				Case EVENT_KEY_RELEASE
				Case EVENT_KEY_REPEAT
					If (e.ascii > 0) Then
						open "key.dat" for append as #1
						Print #1, chr( e.ascii );
						close #1
						End If

				Case EVENT_MOUSE_MOVE
				Case EVENT_MOUSE_BUTTON_PRESS
				Case EVENT_MOUSE_BUTTON_RELEASE
				Case EVENT_MOUSE_DOUBLE_CLICK
				Case EVENT_MOUSE_WHEEL
				Case EVENT_MOUSE_ENTER
				Case EVENT_MOUSE_EXIT
				Case EVENT_WINDOW_GOT_FOCUS
				Case EVENT_WINDOW_LOST_FOCUS
				Case EVENT_WINDOW_CLOSE
					End

				Case EVENT_MOUSE_HWHEEL
				End Select
			End If

		Sleep 1
    
		Loop 
Tested 32/64 bits win 11.
Also checked resource monitor.
All OK.

Please note I kill the file key.dat, maybe you don't want to (line 36)
Post Reply