From: D.J.W. van Kooten on
I tried to catch Ctrl A in a datawindow. When I use code like this in
the dispatch

IF oEvent:Message == WM_KEYUP .AND. oEvent:wParam == 65 .AND.
isCTRL_ON() // VK_A = 65
ErrorBox{,Vt(,"ctrl a")}:Show()
ENDIF


it won't catch Ctrl A, I assume because it will be absorbed by one of
the controls (most keys won't work but some keys search through a
combobox for example).

Using RegisterHotKey works great except it works too well (pressing
Ctrl A in ANY Windows application will run my dispatch code, altough I
would expect RegisterHotKey(SELF:Handle(), 101, MOD_CONTROL, 65) //
->A to only work on the window given thee first paramater and the MSDN
description of it).

Any suggestions how to safely trap Ctrl A in one datawindow only?

Dck van Kooten
From: Geoff Schaller on
Try WM_KEYDOWN then (in the BeforeDispatch)

It isn't a matter of trapping in the "datawindow" because as you
correctly surmised, different controls will swallow certain keys quite
deliberately.

But you can control this.

One way (for SLEs for example) is to intercept the WM_GETDLGCODE message
and return WANTALLKEYS etc. Then you MUST process all messages or send
them to the default handler. Willie's RightSLE does this for example.
But there is another way.

If you subclass the WndProc for each control you can access ALL messages
even before they go to the control so if you know which control is
behaving badly, you can trap it. You have my 2 GCS GUI library
somewhere. I have several examples of controls where I subclass the
WndProc. Use that to write your own. Here is one example to get you
started (not doing WM_KEYUP/DOWN but you will get the drift)

METHOD Init(oOwner, xID, oPoint, oDimension, kComboType, kStyle) CLASS
GCSComboBox

LOCAL hWndCtrl AS PTR
LOCAL oControl AS OBJECT

SUPER:Init(oOwner, xID, oPoint, oDimension, kComboType, kStyle)
SELF:lAutoDrop := FALSE // make TRUE to become and auto-dropdown box

SELF:ToolTipText := "Use the arrow or other navigation keys or type
some text"

// ...
SELF:lpfnDefaultProc := PTR(_CAST,
GetWindowLong(SELF:Handle(),GWL_WNDPROC))
SetWindowLong(SELF:Handle(), GWL_WNDPROC,
LONG(_CAST,@GCSComboBoxWindowProc()))
// ...

RETURN SELF
FUNCTION GCSComboBoxWindowProc(hWnd AS PTR,dwMessage AS DWORD,wParam AS
DWORD,lParam AS LONG) AS LONG _WINCALL

LOCAL hBackgroundComboBoxBrush AS PTR
LOCAL hDCLB AS PTR
LOCAL oControl AS GCSComboBox
LOCAL oGlobal AS GCSGlobalObjectBase

oControl := GetObjectByHandle(hWnd)
oGlobal := GetGlobal()

DO CASE
CASE oControl = NULL_OBJECT
RETURN 0L

CASE dwMessage == WM_LBUTTONDBLCLK
IF oControl:ReadOnly
// DebugOutput("Disable button click")
// disable when in READONLY mode
RETURN 0L
ENDIF

CASE dwMessage == WM_LBUTTONDOWN
IF oControl:ReadOnly
// DebugOutput("Disable button double click")
// disable when in READONLY mode
RETURN 0L
ENDIF

CASE dwMessage==WM_CTLCOLORLISTBOX
hDCLB := PTR(_CAST,wParam)
SetTextColor(hDCLB, oGlobal:sle_editcolour:ColorRef)
SetBkColor(hDCLB, oGlobal:sle_editbrushc:ColorRef)
IF hBackgroundComboBoxBrush == NULL_PTR
hBackgroundComboBoxBrush :=
CreateSolidBrush(oGlobal:sle_editbrushc:ColorRef)
END
RETURN LONG(_CAST,hBackgroundComboBoxBrush)

ENDCASE

RETURN
CallWindowProc(oControl:lpfnDefaultProc,hWnd,dwMessage,wParam,lParam)


Cheers.

Geoff



"D.J.W. van Kooten" <public(a)ic2remove.this.com> wrote in message
news:kf3b06155hm6qqg5pij5i9kg5fj9ovk6t7(a)4ax.com:

> I tried to catch Ctrl A in a datawindow. When I use code like this in
> the dispatch
>
> IF oEvent:Message == WM_KEYUP .AND. oEvent:wParam == 65 .AND.
> isCTRL_ON() // VK_A = 65
> ErrorBox{,Vt(,"ctrl a")}:Show()
> ENDIF
>
>
> it won't catch Ctrl A, I assume because it will be absorbed by one of
> the controls (most keys won't work but some keys search through a
> combobox for example).
>
> Using RegisterHotKey works great except it works too well (pressing
> Ctrl A in ANY Windows application will run my dispatch code, altough I
> would expect RegisterHotKey(SELF:Handle(), 101, MOD_CONTROL, 65) //
> ->A to only work on the window given thee first paramater and the MSDN
> description of it).
>
> Any suggestions how to safely trap Ctrl A in one datawindow only?
>
> Dck van Kooten