Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Enter Key to select in Listbox

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
Jaws
Guest





PostPosted: Jun 22nd, 2011, 4:08pm    Post subject: Using Enter Key to select in Listbox Reply with quote

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: 729

PostPosted: Jun 23rd, 2011, 2:48am    Post subject: Re: Using Enter Key to select in Listbox Reply with quote

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
View user's profile Send private message Send e-mail
Jaws
Guest





PostPosted: Jun 23rd, 2011, 12:35pm    Post subject: Just what I needed Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> General Discussions All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
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



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group