PowerBASIC Forums
  PowerBASIC for Windows
  Can't trap VK_RETURN and VK_UP in WM_KEYDOWN

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   Can't trap VK_RETURN and VK_UP in WM_KEYDOWN
Noel Orden
Member
posted November 23, 2004 01:00 AM     Click Here to See the Profile for Noel Orden     Edit/Delete Message   Reply w/Quote
Can anyone please show me how to trap %VK_UP and %VK_RETURN in %WM_KEYDOWN on a textbox.

I can manage to trap %VK_RETURN if I set the %ES_MULTILINE and %ES_WANTRETURN styles, but if I do that, %VK_UP doesn't respond in the %WM_KEYDOWN event.

I can remove %ES_MULTILINE and %ES_WANTRETURN styles for the %VK_UP to work, but then %VK_RETURN wont respond.

Please help, I want both the %VK_RETURN and %VK_UP in the %WM_KEYDOWN event.

Many Thanks
------------------
NHO

[This message has been edited by Noel Orden (edited November 23, 2004).]

IP: Logged

Charles Dietz
Member
posted November 23, 2004 04:07 AM     Click Here to See the Profile for Charles Dietz     Edit/Delete Message   Reply w/Quote
Using subclass as shown here is one way. (I reread your post and realized I
needed to change the program to better fit your case... so I have edited this
accordingly.)

#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"

GLOBAL gOldEditClassProc AS LONG

CALLBACK FUNCTION MainDlgProc
LOCAL i AS LONG
SELECT CASE CBMSG
CASE %WM_INITDIALOG
'Subclass the editbox control
STATIC hEdit AS LONG
CONTROL HANDLE CBHNDL, 100 TO hEdit
gOldEditClassProc = SetWindowLong(hEdit, %GWL_WNDPROC, CODEPTR(EditSubClassProc))
CASE %WM_DESTROY
'Important! Remove the subclassing
SetWindowLong hEdit, %GWL_WNDPROC, gOldEditClassProc
END SELECT
END FUNCTION

FUNCTION EditSubClassProc(BYVAL hWnd&, BYVAL wMsg&, BYVAL wParm&, BYVAL lParm&) AS LONG
' Process our messages in this subclass procedure
' Ignore everything but numbers, decimal, and backspace
SELECT CASE wMsg&
CASE %WM_KEYUP
IF wParm& = %VK_RETURN THEN
DIALOG SET TEXT GetParent(hWnd&), "Return"
ELSEIF wParm& = %VK_UP THEN
DIALOG SET TEXT GetParent(hWnd&), "Up"
END IF
END SELECT
' Pass the message on to the original window procedure... the DDT engine!
FUNCTION = CallWindowProc(gOldEditClassProc, hWnd&, wMsg&, wParm&, lParm&)
END FUNCTION

FUNCTION PBMAIN()
LOCAL style AS LONG, hDlg AS LONG
style = %WS_SYSMENU OR %WS_MINIMIZEBOX
DIALOG NEW 0, "Navigating Controls", , , 120, 80, style TO hDlg
CONTROL ADD TEXTBOX, hDlg, 100, "", 20, 10, 80, 40, %ES_MULTILINE OR %WS_BORDER
DIALOG SHOW MODAL hDlg, CALL mainDlgProc
END FUNCTION

------------------

[This message has been edited by Charles Dietz (edited November 23, 2004).]

IP: Logged

Noel Orden
Member
posted November 23, 2004 04:29 AM     Click Here to See the Profile for Noel Orden     Edit/Delete Message   Reply w/Quote
Thanks FOR the reply Charles, but I want the PROCESS TO be IN the %WM_KEYDOWN event. Is that possible?

------------------
NHO

IP: Logged

Lothar Pink
Member
posted November 23, 2004 05:58 AM     Click Here to See the Profile for Lothar Pink     Edit/Delete Message   Reply w/Quote
I don't know if this works for controls, but it works for dialogs.

Inside your dialog(!) callback procedure, try to catch CBMSG = %WM_GETDLGCODE
and return %DLGC_WANTALLKEYS.

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxmessages/wm_getdlgcode.asp

------------------

IP: Logged

Charles Dietz
Member
posted November 23, 2004 11:45 AM     Click Here to See the Profile for Charles Dietz     Edit/Delete Message   Reply w/Quote
Would this work for you, Noel?

#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"

GLOBAL gOldEditClassProc AS LONG

CALLBACK FUNCTION MainDlgProc
LOCAL i AS LONG
SELECT CASE CBMSG
CASE %WM_INITDIALOG
'Subclass the editbox control
STATIC hEdit AS LONG
CONTROL HANDLE CBHNDL, 100 TO hEdit
gOldEditClassProc = SetWindowLong(hEdit, %GWL_WNDPROC, CODEPTR(EditSubClassProc))
CASE %WM_KEYDOWN
IF CBCTL = 100 then
IF CBLPARAM = %VK_RETURN THEN
DIALOG SET TEXT CBHNDL, "Return"
ELSEIF CBLPARAM = %VK_UP THEN
DIALOG SET TEXT CBHNDL, "Up"
ELSE
DIALOG SET TEXT CBHNDL, "Capture Keys"
END IF
END IF
CASE %WM_DESTROY
'Important! Remove the subclassing
SetWindowLong hEdit, %GWL_WNDPROC, gOldEditClassProc
END SELECT
END FUNCTION

FUNCTION EditSubClassProc(BYVAL hWnd&, BYVAL wMsg&, BYVAL wParm&, BYVAL lParm&) AS LONG
SELECT CASE wMsg&
CASE %WM_KEYUP
DIALOG SEND GetParent(hWnd&), %WM_KEYDOWN, 100, wParm&
END SELECT
' Pass the message on to the original window procedure... the DDT engine!
FUNCTION = CallWindowProc(gOldEditClassProc, hWnd&, wMsg&, wParm&, lParm&)
END FUNCTION

FUNCTION PBMAIN()
LOCAL style AS LONG, hDlg AS LONG
style = %WS_SYSMENU OR %WS_MINIMIZEBOX
DIALOG NEW 0, "Capture Keys", , , 150, 80, style TO hDlg
CONTROL ADD TEXTBOX, hDlg, 100, "", 20, 10, 100, 40, %ES_MULTILINE OR %WS_BORDER OR %ES_WANTRETURN
DIALOG SHOW MODAL hDlg, CALL mainDlgProc
END FUNCTION


------------------


[This message has been edited by Charles Dietz (edited November 23, 2004).]

IP: Logged

Noel Orden
Member
posted November 23, 2004 08:31 PM     Click Here to See the Profile for Noel Orden     Edit/Delete Message   Reply w/Quote
Thank you so much Charles for the code. The thing is, %VK_RETURN is still triggered by the %WM_KEYUP event.

Try this, insert a message box (msgbox "MESSAGE") in the %VK_RETURN key and you will then see what I am trying to avoid.
At the moment, I am using a switch variable to get around it in the %WM_KEYUP event.

Besides the TAB key, I want to use the Return key and arrow keys to scroll through a dialog controls.

Thanks Lothar, I have not tried your suggestion yet though.

------------------
NHO

IP: Logged

Borje Hagsten
Member
posted November 23, 2004 09:03 PM     Click Here to See the Profile for Borje Hagsten     Edit/Delete Message   Reply w/Quote
Enter key triggers IDOK in dialogs, so for an alternative way to move
around between for example text fields with the Enter key, see:

Link: http://www.powerbasic.com/support/forums/Forum7/HTML/001886.html

------------------
PowerBASIC Staff
------------------
Private web-site: http://www.tolkenxp.com/pb
Free downloads: POFFS, incLean, PBcodec, custom controls and PB samples.

IP: Logged

Noel Orden
Member
posted November 24, 2004 12:48 AM     Click Here to See the Profile for Noel Orden     Edit/Delete Message   Reply w/Quote
Borje Hagsten -- Sir, you're the man!!! Thank you, that is exactly what I need.

Charles Dietz and Lothar Pink, thank you.

------------------
NHO

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c