Skip to content

Instantly share code, notes, and snippets.

@CarlTBarnes
Created July 5, 2020 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlTBarnes/5e0e7d5a3e3f0b5c991e8f0601e69004 to your computer and use it in GitHub Desktop.
Save CarlTBarnes/5e0e7d5a3e3f0b5c991e8f0601e69004 to your computer and use it in GitHub Desktop.
A fix for the Alt key lockup problem with the latest version of Windows 10 that I wrote and published in ClarionMag
#TEMPLATE (CBAltFix, 'Carl Barnes fix for Alt Key Lockup in Windows 7'),FAMILY('ABC','CW20')
#!===========================================================================
#! Warning! Version 2 of the template changes things.
#! The Global template AltWin7Fix_Global has been removed and is no longer needed.
#! The Frame template AltWin7Fix_Frame has been renamed because it has new questions
#! Only the Frame Extension template is required, it is where you specify all choices.
#! It has a new name AltWin7Fix_Frame2 so you must populate it again on the Frame.
#! If you used the first version of the template you will get errors when you open
#! an APP. Ignore the errors, you should open the Frame, go to Extenstions and add the new template.
#! *** Removed ===>#EXTENSION (AltWin7Fix_Global,'Fix Windows 7 Alt Key Lockup-Global-by Carl Barnes'), APPLICATION
#! *** Removed ===>#EXTENSION (AltWin7Fix_Frame,'Windows 7 Alt Key Lockup-Frame Extension-by Carl Barnes'),PROCEDURE
#!===========================================================================
#EXTENSION (AltWin7Fix_Frame2,'Windows 7 Alt Key Lockup 2-Frame Extension-by Carl Barnes'),PROCEDURE
#RESTRICT
#CASE(%ProcedureTemplate)
#OF('Frame')
#OROF('FRAME')
#ACCEPT
#ELSE
#REJECT
#ENDCASE
#ENDRESTRICT
#BOXED('')
#DISPLAY('Clarion MDI Apps built by C6, C5.5, C5, or C4 will lockup')
#DISPLAY('under Windows 7 if ALT is pressed and released, or the')
#DISPLAY('F10 key, or Alt+Space in an MDI Child Window.')
#DISPLAY('Read Clarion Magazine: A Windows 7 Alt-Lockup Fix')
#DISPLAY('')
#PROMPT('Fix Windows 7 Alt Key Bug',CHECK),%FixAltKeyBug,DEFAULT(1),AT(8)
#ENABLE(%FixAltKeyBug)
#PROMPT('Drop a Menu (uncheck and ALT does nothing)',CHECK),%FixAltByDropMenu,DEFAULT(1),AT(12)
#ENABLE(%FixAltByDropMenu)
#PROMPT('Menu to Drop',FROM(%Control,%ControlType='MENU')),%FixAltMenu2Drop,REQ,PROMPTAT(16)
#PREPARE
#FIX(%Control,%FixAltMenu2Drop)
#ENDPREPARE
#VALIDATE(%ControlType='MENU','You must select a Menu from the List')
#! #VALIDATE(%FixAltMenu2Drop>' ','Must select a Menu from the list')
#DISPLAY('On ALT key release this drops the menu by sending'),AT(16)
#DISPLAY('an Alt+ letter message to the menu. This normally'),AT(16)
#DISPLAY('would be "f" when MENU(''&&File'') is first menu.'),AT(16)
#ENDENABLE
#ENDENABLE
#DISPLAY('')
#PROMPT('Auto Close App during Windows Shutdown',CHECK),%AutoShutdown,AT(8)
#ENABLE(%AutoShutdown)
#DISPLAY('Template will take WM_QUERYENDSESSION message')
#DISPLAY('and close app during Windows shutdown.')
#ENDENABLE
#DISPLAY('')
#DISPLAY('This extension sets Frame Prop:WndProc to point')
#DISPLAY('to subclass procedure W7AF_AppFrame_OrigWndProc.')
#DISPLAY('That procedure is generated after the frame. It')
#DISPLAY('has embeds in the Frame''s list named "Alt 7 Fix".')
#DISPLAY('The SubClass procedure sends a message to the')
#DISPLAY('frame to drop the menu you select above.')
#DISPLAY('')
#DISPLAY('An undesirable side-effect is Alt+Space will no')
#DISPLAY('longer open the System Menu. If you drop the first')
#DISPLAY('menu the System menu will open if you press left.')
#ENDBOXED
#DISPLAY('(c)2011 Carl Barnes, Barrington Illinois')
#DISPLAY('Free for use by Clarion Magazine Subscribers')
#AT(%GlobalMap)
MODULE('Win32') !Win7AltFix
W7AF_CallWindowProc(SIGNED lpPrevWndProc,UNSIGNED hWnd,UNSIGNED wMsg,UNSIGNED wParam,SIGNED lParam),SIGNED,RAW,PASCAL,DLL(1),NAME('CallWindowProcA')
W7AF_PostMessage(UNSIGNED hWnd,UNSIGNED uMsg,UNSIGNED wParam,LONG lParam),BOOL,PASCAL,PROC,DLL(1),NAME('PostMessageA')
END
#ENDAT
#!---------
#AT(%ModuleDataSection)
W7AF_AppFrame_OrigWndProc LONG !Win7AltFix - Holds Frame original WndProc for W7AF_CallWindowProc
#ENDAT
#!---------
#AT(%CustomModuleDeclarations),FIRST
MAP
W7AF_SubClassFrame(SIGNED _hWnd, UNSIGNED _wMsg, UNSIGNED _wParam, SIGNED _LParam),SIGNED,PASCAL !Win7AltFix
END
#ENDAT
#!---------
#!#AT(%ProgramRoutines)
#AT(%LocalProcedures),PRIORITY(10000),LAST
W7AF_SubClassFrame PROCEDURE(SIGNED _hWnd, UNSIGNED _wMsg, UNSIGNED _wParam, SIGNED _LParam)!,SIGNED,PASCAL
!Frame WndProc subclassed to send messages here to catch menu keys that hang Clarion RTL
!WM_SYSCOMMAND EQUATE(0112h)
!SC_KEYMENU EQUATE(0F100h)
#DECLARE(%MenuLetterVal,LONG)
#DECLARE(%AmpPos,LONG)
#IF (%FixAltKeyBug AND %FixAltByDropMenu)
#FIX(%Control,%FixAltMenu2Drop)
#IF(~%ControlStatement)
#ERROR('AltWin7Fix_Frame: Menu ' & %FixAltMenu2Drop & ' does not exist')
#ELSE
#SET(%AmpPos,INSTRING('&',%ControlParameter,1))
#! ok, known bug is if menu has && e.g. 'Franks && Bea&ns'
#IF (~%AmpPos)
#ERROR('AltWin7Fix_Frame: Menu ' & %FixAltMenu2Drop & ' does not have "&" in "' & %ControlParameter & '"')
#ELSE
#SET(%MenuLetterVal,VAL(LOWER(SUB(%ControlParameter,%AmpPos+1,1))))
#ENDIF
#! !Menu=%FixAltMenu2Drop parm=%ControlParameter Stmt=%ControlStatement AmpPos=%AmpPos MenuLetterVal=%MenuLetterVal
#IF (%MenuLetterVal)
Alt1stMenu LONG(%MenuLetterVal) !CHR(%MenuLetterVal) is Alt+%(CHR(%MenuLetterVal)) of %ControlStatement !<<< set to your first menu Alt letter, i.e. &File is Alt+f (use lower case)
#ENDIF
#ENDIF
#ENDIF
#EMBED(%W7AFSubClassFrameDataSection,'Alt7 Fix Frame Subclass Data Section'),DATA
CODE
#EMBED(%W7AFSubClassFrameCodeTop,'Alt7 Fix Frame Subclass Code before CASE _wMsg')
CASE _wMsg
#EMBED(%W7AFSubClassFrameCodeCasewMsg,'Alt7 Fix Frame Subclass Code inside CASE _wMsg')
#IF (%FixAltKeyBug)
OF 0112h !WM_SYSCOMMAND !Win 7 Alt Bug Fix
IF BAND(_wParam,0FFF0h)=0F100h | ! _wParam=SC_KEYMENU - Menu Key Message?
AND (_LParam=0 OR _LParam=32) THEN ! _LParam=Key for Menu - 0=ALT or F10; 32=Alt+Space
#IF (%MenuLetterVal=0 OR %MenuLetterVal=32)
!Menu will NOT be dropped; ALT,F10,Alt+Space will do nothing
#ELSE
W7AF_PostMessage(_hWnd,0112h,0F100h,Alt1stMenu) !PostMsg( Send WM_SYSCOMMAND,SC_KEYMENU,Alt+%ControlParameter) message to drop menu
#ENDIF
RETURN(True) ! Prevent RTL from getting message or ALT locks up frame
END
#ENDIF
#IF (%AutoShutdown)
OF 0011h ; RETURN(True) !WM_QUERYENDSESSION EQUATE(0011h) Windows is asking if we would shutdown, True says YES
OF 0016h ; RETURN(True) !WM_ENDSESSION EQUATE(0016h) Windows IS shutting down, we say YES and will get EVENT:CloseDown next
#ENDIF
END !CASE _wMsg
#EMBED(%W7AFSubClassFrameCodeEnd,'Alt7 Fix Frame Subclass Code before Return')
RETURN(W7AF_CallWindowProc(W7AF_AppFrame_OrigWndProc,_hWnd,_wMsg,_wParam,_LParam))
#ENDAT
#AT(%AfterWindowOpening)
!Subclass sends messages to W7AF_SubClassFrame() procedure in Global. Fix Alt 7 lockup.
W7AF_AppFrame_OrigWndProc = %window{PROP:WndProc} !Win7AltFix
%window{PROP:WndProc} = Address(W7AF_SubClassFrame) !Win7AltFix
#ENDAT
#!===========================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment