Well this was fun. Wndows hotkeys... - Pete - 06-09-2022
I expanded a bit on one of Dav's old programs, that used Shift + A to restore an automatically minimized window.
This demo uses the F3 key. It has (3) effects. The usual min and restore effect, which shows a shadow effect as the window changes to minimized and restored, a method that eliminates that effect, and one that merely hides the window and restores it. Use TAB to select which effect to use.
Obviously, this works on Windows platforms, only....
Code: (Select All) REM Based on the "Cheapo Windows Hotkey" program coded by Dav.
DECLARE DYNAMIC LIBRARY "user32"
REM FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
FUNCTION GetKeyState% (BYVAL nVirtKey AS LONG) 'Windows virtual key presses
FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
FUNCTION GetForegroundWindow%& 'find currently focused process handle
FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
END DECLARE
title$ = "Minimize-Restore Windows Demo" 'title of program window
_TITLE title$
DO
i = i + 1
_LIMIT 10
REM hwnd%& = FindWindowA(0, title$ + CHR$(0)) 'find this program's process handle
hwnd%& = _WINDOWHANDLE
IF i > 100000 THEN PRINT "Cannot obtain window handle.": END
LOOP UNTIL hwnd%&
keyact = 114
status = 0 ' Regular window.
DO
_LIMIT 30
SELECT CASE status
CASE 0
IF msg = 0 THEN
CLS
PRINT "Press F3 to toggle minimize / restore window.": PRINT
msg = 1
y% = CSRLIN
GOSUB menu
END IF
IF GetKeyState(9) < 0 THEN
LOCATE y%, 1: PRINT SPACE$(_WIDTH);: LOCATE y%, 1
demo = demo + 1: IF demo > 2 THEN demo = 0
GOSUB menu
DO: _LIMIT 30: LOOP UNTIL GetKeyState(9) >= 0
END IF
IF GetKeyState(keyact) < 0 THEN '<==== F3
SELECT CASE demo
CASE 0 ' Minimize with effect.
x& = ShowWindow&(hwnd%&, 2)
CASE 1 ' Minimize without effect.
x& = ShowWindow&(hwnd%&, 0)
_DELAY .33
x& = ShowWindow&(hwnd%&, 2)
x& = ShowWindow&(hwnd%&, 5)
CASE 2 ' Hide window only.
y& = ShowWindow&(hwnd%&, 0)
END SELECT
DO: _LIMIT 30: LOOP UNTIL GetKeyState(keyact) >= 0
status = 1
END IF
CASE 1
IF GetKeyState(keyact) < 0 THEN '<==== F3
FGwin%& = GetForegroundWindow%& 'get current process in focus
LOCATE _HEIGHT - 2, 1
PRINT SPACE$(_WIDTH);
LOCATE _HEIGHT - 2, 1
PRINT "Program Handle:"; hwnd%&; "Focus handle:"; FGwin%&;
SELECT CASE demo
CASE 0 ' Restore with effect.
y& = ShowWindow&(hwnd%&, 9) ' Restore to original state.
CASE 1 ' Restore without effect.
y& = ShowWindow&(hwnd%&, 0)
_DELAY .3
y& = ShowWindow&(hwnd%&, 9)
y& = ShowWindow&(hwnd%&, 5)
CASE 2 ' Show window only.
DO
y& = ShowWindow&(hwnd%&, 5)
LOOP UNTIL y&
END SELECT
IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
LOCATE _HEIGHT, 1
PRINT "Return Values:"; " Was/Is Minimized/Hidden"; x&; " Was/Is Restored"; y&; " Reactivated"; z&;
DO: _LIMIT 30: LOOP UNTIL GetKeyState(keyact) >= 0
status = 0
END IF
END SELECT
LOOP UNTIL INKEY$ = CHR$(27) AND status = 0
SYSTEM
menu:
SELECT CASE demo
CASE 0
PRINT "Tab Menu: Show screen on transition and minimize.": PRINT
CASE 1
PRINT "Tab Menu: Hide screen on transition and minimize.": PRINT
CASE 2
PRINT "Tab Menu: Hide window on transition.": PRINT
END SELECT
RETURN
REM ============================== VALUES ===================================
$IF THEN
SW_HIDE
0 Hides the window and activates another window.
---------------------------------------------------------------------------------------------
SW_SHOWNORMAL
SW_NORMAL
1 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.
---------------------------------------------------------------------------------------------
SW_SHOWMINIMIZED
2 Activates the window and displays it as a minimized window.
---------------------------------------------------------------------------------------------
SW_SHOWMAXIMIZED
SW_MAXIMIZE
3 Activates the window and displays it as a maximized window.
---------------------------------------------------------------------------------------------
SW_SHOWNOACTIVATE
4 Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the window is not activated.
---------------------------------------------------------------------------------------------
SW_SHOW
5 Activates the window and displays it in its current size and position.
---------------------------------------------------------------------------------------------
SW_MINIMIZE
6 Minimizes the specified window and activates the next top-level window in the Z order.
---------------------------------------------------------------------------------------------
SW_SHOWMINNOACTIVE
7 Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
---------------------------------------------------------------------------------------------
SW_SHOWNA
8 Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.
---------------------------------------------------------------------------------------------
SW_RESTORE
9 Activates and displays the 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 restoring a minimized window.
---------------------------------------------------------------------------------------------
SW_SHOWDEFAULT
10 Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
---------------------------------------------------------------------------------------------
SW_FORCEMINIMIZE
11 Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
---------------------------------------------------------------------------------------------
$END IF
Pete
|