|
Bay Six Software Beyond the Basics
|
View previous topic :: View next topic |
Author |
Message |
Jaws Guest
|
Posted: Jun 22nd, 2011, 4:08pm Post subject: Using Enter Key to select in Listbox |
|
|
I once found some information on the web about using the MsgHook.DLL to trap activity in a listbox so that the Enter key could be used to make the selection.
I put it into a program and had it working, but it doesn't work anymore. If anyone knows where any there is any information on this is located, I would greatly appreciate knowing.
Or, if anyone knows of a different way of doing this that would also be great.
Thanks in advance for any help.
Jim |
|
Back to top |
|
|
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Jun 23rd, 2011, 2:48am Post subject: Re: Using Enter Key to select in Listbox |
|
|
Hi Jim and welcome!
I've never used MsgHook, so I can't be much help with it specifically. I always use my own WMLiberty DLL for things likethis.
However, I'm not sure I understand what you are wanting to do exactly. I put together a quick demo that uses WMLiberty to catch "key down" messages from the list box, and if the user presses Enter or double-clicks an item, it grabs the text and prints it to a text box.
Code: | open "wmliberty" for dll as #wmlib
for i = 1 to 10
a$(i) = "Item " + str$(i)
next
listbox #demo.list, a$(), [demo.list.dblClick], 10, 10, 75, 75
stylebits #demo.list, _LBS_WANTKEYBOARDINPUT, 0, 0, 0
textbox #demo.item, 95, 10, 75, 25
open "Demo" for window as #demo
#demo "trapclose [quit]"
#demo.list "setfocus"
callback lpfn, OnVKeyToItem(ulong, ulong, ulong, ulong), long
ret = SetWMHandler(hwnd(#demo), _WM_VKEYTOITEM, lpfn, -2)
[wait]
scan
calldll #kernel32, "Sleep", 25 as long, ret as void
goto [wait]
[quit]
close #demo
close #wmlib
end
[demo.list.dblClick]
call demo.list.selected
goto [wait]
function OnVKeyToItem(hwnd, msg, wparam, lparam)
code = (wparam and 65535) ' low word
print code
select case code
case _VK_RETURN ' Enter
call demo.list.selected
end select
end function
sub demo.list.selected
#demo.list "selection? a$"
#demo.item a$
#demo.item "!setfocus"
end sub
function SetWMHandler(hwnd, msg, lpfn, lsuccess)
calldll #wmlib, "SetWMHandler", hwnd as ulong, msg as ulong, lpfn as ulong, lsuccess as long, SetWMHandler as long
end function |
_________________ Brent |
|
Back to top |
|
|
Jaws Guest
|
Posted: Jun 23rd, 2011, 12:35pm Post subject: Just what I needed |
|
|
Thank you for the response, it is just what I needed.
As far as what I am doing, it is a simple selection screen where the user can type in some text and it lists all the records containing that text.
I am an old time programmer (cobol, RPG, DOS Basic), so I like to use the keyboard a lot. I set the focus to the list box after the search and want the user to be able to arrow to the desired selection and press enter key to select it. I was simply trying to avoid making them grab the mouse.
Jim |
|
Back to top |
|
|
|
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|