1. Hotkey demo (hiding window)
- Posted by Eddy Van Esch <raimundo4u at YAHOO.COM> Jan 16, 2001
- 448 views
Hi all, Some time ago I posted a question of how to make a hidden window visible again by pressing a hotkey. Since nobody answered, I was forced to find it out myself.. So here it is...: You can use the hotkey to call any procedure you want. -- demo of hiding a window and getting it back by pressing a hotkey combination -- Eddy Van Esch 15/01/2001 include win32lib.ew include w32Keys.e without warning global constant WM_HOTKEY = #312 global constant MOD_CTRL = #2 -- hotkey is CTRL Q, change as necessary global constant key = 'Q' global constant xRegisterHotKey = registerw32Function( user32, "RegisterHotKey",{ C_LONG, C_LONG, C_LONG, C_LONG }, C_LONG ) global constant xUnregisterHotKey = registerw32Function( user32, "UnregisterHotKey",{ C_LONG, C_LONG }, C_LONG ) integer retval -- Window Window1 global constant Window1 = create( Window, "Window1", 0, Default, Default, 600, 200, 0 ) global constant HideButton = create( PushButton, "Hide window", Window1, 190, 12, 144, 40, 0 ) global constant LText3 = create( LText, "Click 'Hide window' button to hide this window. Press hotkey combination CTRL Q to show the window again.", Window1, 12, 68, 472, 36, 0 ) -- Hide button's behavior global procedure onClick_HideButton() setVisible( Window1, False ) -- Hide the window end procedure -- Event handler: intercept the hotkey and define what to do with it: procedure Events(atom iMsg, atom wparam, atom lparam) if iMsg = WM_CLOSE then --clean up: free hotkey retval = w32Func(xUnregisterHotKey, {getHandle(Window1), 0}) end if --************************************ if iMsg = WM_HOTKEY then --unhide window, can be used to do anything you want here... setVisible( Window1, True ) end if --************************************ end procedure ----Main------------- onClick[HideButton] = routine_id( "onClick_HideButton" ) onEvent[Window1] = routine_id( "Events" ) retval = w32Func(xRegisterHotKey, {getHandle(Window1), 0, MOD_CTRL, key}) -- register hotkey if retval = 0 then --key already taken retval = w32Func(xUnregisterHotKey, {getHandle(Window1), 0}) --set hotkey free end if WinMain( Window1, Normal ) --normal event loop