ESC SHORTCUT FOR EXIT/CLOSE

ESC SHORTCUT FOR EXIT/CLOSE

Hello,

I would like to use the ESC-key as shortcut for closing a SDI application with a single edit control in the client area (the application is a simple text editor).
I have tried to use WM_KEYDOWN and WM_CHAR messages, but it seems that these messages are never send. Any key pressed generates a WM_COMMAND message. Even when focus is on the menu and I press a key, the WM_KEYDOWN message is still not send.
Am I missing something here?

Walter Kramer

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I guess my question is not a Fortran question. I should have looked at MSDN first. WM_KEYDOWN and WM_CHAR messages are passed to the control not to the application's windows procedure.
An article on using a message filter to detect F1 keystrokes requesting context sensitive help in a dialog box ID: Q72219 discusses this issue.
It is apparently not as easy as I hoped.

Walter Kramer

P.S.

Great improvement to have the forum sorted by date.

Hello,

I managed to get things working using:

 
case (WM_CREATE)
!// Create the edit control child window
lParam=ghInstance
ghHook=SetWindowsHookEX(WH_KEYBOARD, LOC(EscKeyProc), ghInstance, GetCurrentThreadID())
hwndEdit = CreateWindowEx(0,"edit"C, &
""C, &
IOR(WS_CHILD, IOR(WS_VISIBLE, &
IOR(WS_HSCROLL, IOR(WS_VSCROLL, &
IOR(WS_BORDER, IOR(ES_LEFT, &
IOR(ES_MULTILINE, IOR(ES_NOHIDESEL, &
IOR(ES_AUTOHSCROLL, IOR(ES_READONLY, &
ES_AUTOVSCROLL)))))))))), &
0, 0, 0, 0, &
hwnd, EDITID, ghInstance, NULL)
ghwndEdit=hwndEdit
hBrushEdit = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT))
iret=SendMessage(hwndEdit,EM_LIMITTEXT,32000,0)

The hook procedure is:

 
integer*4 function EscKeyProc(nCode, wParam, lParam)
!DEC$ IF DEFINED (_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS: '_EscKeyProc@12' :: EscKeyProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS: '_EscKeyProc' :: EscKeyProc
!DEC$ ENDIF
use NemListGlobals
use Dfwbase
integer*4, intent(in) :: nCode ! hook code
integer*4, intent(in) :: wParam ! virtual-key code
integer*4, intent(in) :: lParam ! keystroke message information
integer*4 hwnd
integer*4 iret
hwnd=getFocus()
iret=HIWORD(lParam)
if ((nCode==HC_ACTION).AND.(wParam==VK_ESCAPE).AND.(hwnd==ghwndEdit).AND. &
(IAND(KF_MENUMODE,iret)==0)) then
iret=PostMessage(getParent(hwnd), WM_CLOSE, 0, 0)
EscKeyProc = 1 ! non zero to stop further processing
return
endif
EscKeyProc = CallNextHookEx(ghHook, nCode, wParam, loc(lParam))
return
end function EscKeyProc

IAND(KF_MENUMODE,iret)==0 makes sure that the ESCAPE key doesn't
function as shortcut for EXIT while the menu is active.

Remains one question.

If the menu is active and I press ESC the pull down closes, but optically it seems that the menu is still active (blue color or shadow).

How can I trap this state? I would like that ESC will not work as shortcut for EXIT under these circumstances either.

Thanks,

Walter Kramer

Leave a Comment

Please sign in to add a comment. Not a member? Join today