Coder's Guild Mailing List

Re: Win32 programming

Posted by Fox on 2001-01-02

> I have a listbox with a few items in it. I am responding to the
> WM_LBUTTONDBLCLK on the item and I want to get the text of the item that was
> double clicked. I am a total beginner with Win32 programming. Will the
> function SendMessage and passing it WM_GETTEXT solve my problem?

/****************************/

Partially.

When the user double clicks on an item in a listbox, a WM_COMMAND message 
is sent to message loop that owns that control.  The LOWORD(wParam) will 
contain the ID associated with the listbox and HIWORD(wParam) contains the 
LBN_LISTBOX message, which tells you that a doubleclick has occurred on that 
listbox.

switch(message)
{
case WM_COMMAND:
  if(LOWORD(wParam) == *insert your listbox ID here*)
     {
      if(HIWORD(wParam) == LBN_DBLCLK)
           //process what you would do with the double click message on that listbox
     }
 . . .
 . . .
 . . .


Once you get to that point, call:
SendDlgItemMessage(*your listbox window handle*, LB_GETTEXT, *a zero-based 
index relating to index of the string to retrieve*, *a pointer variable to the string to 
receive the data*);

You might have to call:
SendDlgItemMessage(*your listbox window handle*, LB_GETCURSEL, 0, 0);
to get the current selection before you call the first one.

I think you want SendDlgItemMessage() instead of SendMessage().  Try both, 
just to find out.  One of these has to work.

I pray this helps you.  I took it from memory and the book, "Windows 98 
Programming From The Ground Up" by Herbert Schildt ( www.osborne.com ).