Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

[Q] TComboBox & ListHandle

Posted on 1998-07-31
9
Medium Priority
?
371 Views
Last Modified: 2010-04-04
Hello there,
 
I'm trying to get handle of the listbox portion of combobox control...
I'm expecting ListHandle property to be a correct thing but it always
returns 0 no matter what style my combobox is.
I tried GetWindow() with various values of relationship parameter. But I
could not get it to work properly anyway. Anybody can help?
 
Thank you!
0
Comment
Question by:_art_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1359290
Hey, How are ya?

I'm not exactly sure what you are looking for? Would exaplin a little more, what handle do you need...???? :)

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1359291
_art_

here is a snippet not very neat and quite untidy, but t was written very quickly...

This will retrieve the handle of a child of the combobox which is the listhandle as far as I understand it...Correct me if I'm wrong

procedure TForm1.Button1Click(Sender: TObject);
var
Lst: HWND;
 Combo: TCustomComboBox;
begin
  Combo := TCustomComboBox.Create(Form1);
   Combo.Parent := Self;
    Combo.Left := 12;
     Combo.Top := 10;
      Combo.Width := 100;
       Combo.Height := 25;
         Lst := GetWindow(Combo.Handle, GW_CHILD);
       if Lst <= 0 then
        Showmessage('No handle caught')
        else
         Showmessage('You have the handle');

end;

Later
BoRiS
0
 

Author Comment

by:_art_
ID: 1359292
viktornet: doin' fine. check out my new Delphi site at
www.torry.ru/dpfl/ (other are welcome as well).
BoRiS: Yep, thats exactly how Inprise catches ListHandle
and it is ALWAYS 0 ("No handle caught")!!
viktornet: Once again I need handle of the dropped list that
is part of combobox control and is listbox itself.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:viktornet
ID: 1359293
I think what Boris told ya is right...

GetWindow(Combo.Handle, GW_CHILD);

Regards,
Viktor Ivanov
0
 

Author Comment

by:_art_
ID: 1359294
yep except that it always returns 0. :-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359295
It's not that...did you try his example, when the combo is created it returns other than zero...and shows you the message that the handle is really there..Anyway, I'm not sure what's going on with that ... :)

Regards,
Viktor Ivanov
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359296
Hi everybody...
I don't think it's useful to get the handle of the list attached to the combo. If you want to manipulate the items and stuff, you better use some combo-related-smAPI.

Look at Win32 help on value "Combo Box Reference" and so on.
Search for messages like CB_ADDSTRING, CB_GETCURSEL and so on. All you want to do with the combo-list you can do through CB_ messages.
0
 
LVL 4

Accepted Solution

by:
erajoj earned 400 total points
ID: 1359297
Hi,
You're in for a surprise...
The combo listbox is NOT owned by the combobox but by the desktop unless "Style := csSimple;"! :-(
That's the reason you can't retrieve a handle for it as BoRiS suggested. The only other child a combobox has is the editbox in styles; csDropDown, csSimple.
Because the Combobox List window is not a child of the ComboBox window, there is no simple way to get its handle. Furthermore, because the Combo's list box is a private class registered by USER its class cannot be accessed either.

A way to get the handle is to replace the combobox subclass proc.
Here's some code on how to do it (in C++, mea culpa):

LRESULT CALLBACK NewComboProc (HWND hWnd,   UINT message,   WPARAM
   wParam, LPARAM lParam ); // prototype for the combo box subclass proc

HANDLE hInst;                     // Current app instance
BOOL bFirst;                      // a flag

// Dialog procedure for the dialog containing the combo box.

BOOL __export CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam,
            LPARAM lParam)
{
    FARPROC lpfnNewComboProc;

    switch (message)
    {
    case WM_INITDIALOG:

   bFirst = TRUE;       // set flag here - see below for usage

   // subclass the combo box

   lpfnOldComboProc = (FARPROC ) SetWindowLong (
               GetDlgItem ( hDlg, IDC_COMBO1 ),
               GWL_WNDPROC,
               (LONG)NewComboProc );
   break;

     case WM_DESTROY:
   (FARPROC ) SetWindowLong (    GetDlgItem ( hDlg, IDC_COMBO1 ),
               GWL_WNDPROC,
               (LONG)lpfnOldComboProc );
   break;
     default:
        break;
     }

     return FALSE;

} // end dialog proc



// Combobox subclass proc.

LRESULT CALLBACK NewComboProc (HWND hWnd,   UINT message,   WPARAM
            wParam, LPARAM lParam );

{
   static HWND hwndList;
   static RECT rectList;

#ifdef WIN16
   if (  WM_CTLCOLOR  == message)  // combo controls are to be painted.
#else
   if ( WM_CTLCOLORLISTBOX == message ) // 32 bits has new message.
#endif
   {
      // is this message for the list box control in the combo?
#ifdef WIN16
      if ( CTLCOLOR_LISTBOX==HIWORD (lParam )   ) // need only for 16 bits
      {
#endif
         // Do only the very first time, get the list
         // box handle and the list box rectangle.
         // Note the use of GetWindowRect, as the parent
         // of the list box is the desktop window

         if ( bFirst )
         {
#ifdef WIN16
            hwndList = LOWORD (lParam );
#else
            hwndList = (HWND) lParam ;     // HWND is 32 bits
#endif
            GetWindowRect ( hwndList, &rectList );
                       bFirst = FALSE;
         }

         // Resize listbox window cx by 50 ( use your size here )

         MoveWindow ( hwndList, rectList.left, rectList.top,
         ( rectList.right - rectList.left + 50 ),
         rectList.bottom - rectList.top, TRUE );
#ifdef WIN16
      }
#endif
   }

   // Call original combo box procedure to handle other combo messages.

   return CallWindowProc ( lpfnOldComboProc, hWnd, message,
wParam, lParam ); }

Hope this helps.

/// John
0
 

Author Comment

by:_art_
ID: 1359298
erajoj: Excellent! :-)

I really am surprised because actually even after subclassing the control that receiving messages is still ComboBox. :-)
Anyhow my problem is solved and everything works great. By the way in Delphi it's easier than in code you provided. I had not subclass ComboBox. It was enough to override WndProc() method which declared in TCustomComboBox and then:

procedure TSomeComboBox.WndProc(var Message: TMessage);
begin
  inherited WndProc(Message);

  try
    case Message.Msg of
      WM_CTLCOLORLISTBOX:
          HListBox := Message.lParam;
    end;
  except
    Application.HandleException(Self);
  end;
end;

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question