Kbase 21284: How To Send Accelerators To Normal Widgets
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/02/2005 |
|
Status: Unverified
GOAL:
How To Send Accelerators To Normal Widgets
CAUSE:
Since the ActiveX control gets all of the keystrokes before Progress sees them, the solution involves sending keyboard messages to Progress by using the PostMessage API.
This Solution gives a way to send accelerators to normal Progress widgets when using ActiveX controls (OCX) in a Progress window.
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window, and then returns without waiting for the thread to process the message.
PROCEDURE PostMessageA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER hWnd AS LONG NO-UNDO.
DEFINE INPUT PARAMETER wMsg AS LONG NO-UNDO.
DEFINE INPUT PARAMETER wParam AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lParam AS LONG NO-UNDO.
DEFINE RETURN PARAMETER rc AS LONG NO-UNDO.
END PROCEDURE.
Parameters:
hWnd: Handle of destination window. However any widget's handle
may also be specified.
wMsg: Message to post. The usual messages are WM_SYSKEYDOWN
(system keys) or WM_KEYDOWN (nonsystem keys).
wParam: First message parameter.
lParam: Second message parameter.
rc: If it fails the return value is zero.
Those messages are composed of:
wParam: Virtual keycode of the key being pressed.
lParam: Key data.
The virtual keycode of the WM_KEYDOWN (256) and WM_SYSKEYDOWN (260) can be found in the winuser.h file if you have Microsoft Visual C++ installed.
FIX:
In the following code, the ActiveX control (Microsoft TreeView) has a KeyUp trigger sending a system message (WM_SYSKEYDOWN) to a button named BUTTON-1, which uses "Alt+T" as its accelerator key.
/* *** Definitions *** */
DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
PROCEDURE PostMessageA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER hwnd AS LONG NO-UNDO.
DEFINE INPUT PARAMETER wMsg AS LONG NO-UNDO.
DEFINE INPUT PARAMETER wParam AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lParam AS LONG NO-UNDO.
DEFINE RETURN PARAMETER rc AS LONG NO-UNDO.
END PROCEDURE.
/* *** OCX KeyUp Trigger *** */
PROCEDURE CtrlFrame.TreeView.KeyUp .
/*-----------------------------------------------------------------*/
Purpose:
Parameters: Required for OCX.
KeyCode
Shift
Notes:
------------------------------------------------------------------*/
DEFINE INPUT-OUTPUT PARAMETER p-KeyCode AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER p-Shift AS INTEGER NO-UNDO.
/* Post a message to BUTTON-1 */
IF p-shift = 4 THEN
DO: /* [ALT] + [Any nonsystem key] */
RUN postMessageA (
INPUT BUTTON-1:HWND,
INPUT 260, /* WM_SYSKEYDOWN */
INPUT p-KeyCode ,
INPUT 0,
OUTPUT iResult).
END.
END PROCEDURE.
/* BUTTON-1 trigger */
ON CHOOSE OF BUTTON-1 IN FRAME DEFAULT-FRAME
DO:
MESSAGE "Hello World!" VIEW-AS ALERT-BOX.
END.
Reference to Written Documentation:
Progress Solution 18281, "ACTIVEX - How to Get Accelerators for Normal Widgets Working"