Thread: simulating doubleclick on item in listbox

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    18

    simulating doubleclick on item in listbox

    I'm trying to simulate a doubleclick on a listbox in a VB program (my program is c++, the target program is VB).
    I have the handle to the listbox and the main window, but I don't know what messages to send to the program.
    Does anybody know what messages to send to the target program?

    Thanks in advance,
    Borre

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I think you have to send a WM_NOTIFY message with a NM_DBLCLICK message

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You may wish to try sending a LBN_DBLCLK notification as a WM_COMMAND to the listbox parent. Something like:
    Code:
    SendMessage(GetParent(hwndListbox),
                WM_COMMAND,
                MAKEWPARAM(GetDlgCtrlId(hwndListbox),LBN_DBLCLK),
                (LPARAM)hwndListbox);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For a list box, it might as well be a WM_COMMAND with LBN_DBLCLK.

    But this will only work if the VB app uses the standard list box (which is an ActiveX wrapper around the standard Windows list box). If the VB app uses a fancy custom list box (and very often you don't even know it unless you look at the class name in Spy++) it will probably not work, because the programmer of the ActiveX will not have bothered to be compatible with standard Windows behavior.

    Another problem is that VB doesn't necessarily even use the WM_COMMAND messages. ActiveX has its own way of passing notifications. It would thus make sense if the ActiveX wrapper intercepts the message the control tries to send and instead sends its ActiveX notfication. In that case you have to make the control itself believe it has been doubleclicked. This is complicated.
    First, you have to send the list box a LB_SELECTSTRING or LB_SETCARETINDEX message (the former only if it's not a multiple-selection box, the latter requires you to find the item index first) to guarantee that the item you want is actually visible.
    Second, you have to find its actual position within the box. I don't know an easy way, you have to use LB_GETITEMHEIGHT and LB_ITEMFROMPOINT to scan the box for the id you want. Once you know where the item you want is you can do the actual doubleclicking by sending a WM_LDBLCLK specifying coordinates you know hit the item you want.

    Good luck
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  3. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM