MEGA Search
20.3 Million


Sign Up
From: Jim J. Yang  
Subject: TComboBox: "horizontal scrollbar" possible?
NewsGroup: borland.public.delphi.vcl.components.using.general
Date Posted: 26-Dec-2004 at 18:44:29 PST
Hi!

Anybody who can help me with this silly Q:

How can I have a "vertical scrollbar" in a Combobox such that text items 
which are too long can also be showed in their full length (of course 
without having to have a very wide Combobox)?

(I am using Delphi 5 standard) 



From: Jim J. Yang  
Subject: Re: TComboBox: "horizontal scrollbar" possible?
NewsGroup: borland.public.delphi.vcl.components.using.general
Date Posted: 27-Dec-2004 at 16:58:39 PST
Thanks! I got it working now!

> A better solution would be to widen all your dropdowns so that all
> the text shows. Place this unit in your uses and it will do this for
> all combos that need it. Originally posted by Stphen Deetz (9/21/2000)
>
> :
> : 



From: eshipman  
Subject: Re: TComboBox: "horizontal scrollbar" possible?
NewsGroup: borland.public.delphi.vcl.components.using.general
Date Posted: 27-Dec-2004 at 9:15:7 PST
In article <41cef877@newsgroups.borland.com>, yang@online.no says...
> Hi!
> 
> Anybody who can help me with this silly Q:
> 
> How can I have a "vertical scrollbar" in a Combobox such that text items 
> which are too long can also be showed in their full length (of course 
> without having to have a very wide Combobox)?
> 
> (I am using Delphi 5 standard) 

A better solution would be to widen all your dropdowns so that all
the text shows. Place this unit in your uses and it will do this for
all combos that need it. Originally posted by Stphen Deetz (9/21/2000)

unit WidenCombos;
interface
implementation
uses
  Windows, Messages, Classes, Controls, Forms, StdCtrls, Dialogs, 
Sysutils;

var
  cwpHandle: THandle;
  //This is kind of a hack, but because there isn't a
  //connection between the the edit part and the listbox
  //part the assumption is being made that the CBN_DROPDOWN
  //and WM_CTLCOLORLISTBOX are for the same combobox.
  SaveRight:Integer;

procedure AutoSetComboxDropDownWidth( AComboBox: TComboBox );
var
  i: Integer;
  MaxWidth: Integer;
  CurWidth: Integer;
  TempSize: SIZE;
  TempHDC: HDC;
  SaveFont: HFont;
begin 
  MaxWidth := AComboBox.Width; //(GetSystemMetrics(SM_CXVSCROLL)*2);
  TempHDC := GetDC(0);
  try
    for i := 0 to AComboBox.Items.Count-1 do
    begin
      SaveFont := SelectObject( TempHDC, AComboBox.Font.Handle );
      Windows.GetTextExtentPoint32( TempHDC, PChar(AComboBox.Items
[i]),Length(AComboBox.Items[i]), TempSize );
      SelectObject( TempHDC, SaveFont );

	  //if scrollbar needed.
      if AComboBox.Items.Count>AComboBox.DropDownCount then 
	   //The 8 seems to provide a centering effect between left and 
right.
       CurWidth := TempSize.cx + (GetSystemMetrics(SM_CXVSCROLL)+8)
      else
       CurWidth := TempSize.cx+8;
      if CurWidth>MaxWidth then
       MaxWidth := CurWidth;
    end;
  finally
    ReleaseDC(0, TempHDC );
  end;
  SaveRight := AComboBox.ClientOrigin.X + AComboBox.Width;
  AComboBox.Perform( CB_SETDROPPEDWIDTH, MaxWidth, 0 );
end;


procedure MoveDropDownListIfNecessary( AComboBoxListHandle: LongInt );
var
  R: TRect;
begin
  GetWindowRect( AComboBoxListHandle, R );

  if R.Right>=Screen.Width then
  begin
    MoveWindow( AComboBoxListHandle, SaveRight-(R.Right-R.Left)-1, 
R.Top,
R.Right-R.Left, R.Bottom-R.Top, True );
  end;
end;


function HookCallbackFunction(nCode: Integer; wParam: LongInt; lParam: 
LongInt): Integer; stdcall;
var
  wNotifyCode: Integer;
  Control: TWinControl;
  ListHandle: LongInt;
begin
  Result := CallNextHookEx(cwpHandle,nCode,wParam,lParam);
  // Don't do anything when program is closing
  if (Application.Terminated) or (nCode<0) then 
   Exit;

  if nCode=HC_ACTION then
  begin
    if PCWPStruct(LParam)^.message = WM_COMMAND then
    begin
      wNotifyCode := HIWORD(PCWPStruct(LParam)^.wParam);

      if wNotifyCode = CBN_DROPDOWN then
      begin
        Control := FindControl( PCWPStruct(LParam)^.lParam );

        if (Control<>nil) and (Control is TComboBox) then
          AutoSetComboxDropDownWidth( TComboBox( Control ) );
      end;
    end
    else if PCWPStruct(LParam)^.message = WM_CTLCOLORLISTBOX then
    begin
      ListHandle := PCWPStruct(LParam)^.lParam;
      MoveDropDownListIfNecessary( ListHandle );
    end;
  end;
end;

initialization
  cwpHandle := SetWindowsHookEx( WH_CALLWNDPROC, @HookCallbackFunction, 
0, MainThreadID );

finalization
  if cwpHandle <> 0 then
   UnhookWindowsHookEx( cwpHandle );

end.

From: Jim J. Yang  
Subject: Re: TComboBox: "horizontal scrollbar" possible?
NewsGroup: borland.public.delphi.vcl.components.using.general
Date Posted: 27-Dec-2004 at 12:8:17 PST
Thanks, Yorai!

I am not so very familiar with Delphi, could you threrefore please write 
some lines for showing how to send a CB_message to a combo box?

"Yorai Aminov (TeamB)"  skrev i melding 
news:xn0drhymu1h9izd000@newsgroups.borland.com...
> On 26/12/2004 19:44:29, Jim J. Yang wrote:
>
> The Platform SDK claims you can send a CB_SETHORIZONTALEXTENT message
> to the combo box, which will set the scrolling width for the list
> box. It doesn't seem to work, though.
>
> Another option is to send a CB_SETDROPPEDWIDTH message to the combo
> box. This will set the width of the dropped list, regardless of the
> combo box's width.
>
> -- 
> Yorai Aminov (TeamB)
> (TeamB cannot answer questions received via email.)
> Shorter Path - http://www.shorterpath.com
> Yorai's Page - http://www.yoraispage.com 



From: Yorai Aminov (TeamB)  
Subject: Re: TComboBox: "horizontal scrollbar" possible?
NewsGroup: borland.public.delphi.vcl.components.using.general
Date Posted: 26-Dec-2004 at 16:59:42 PST
On 26/12/2004 19:44:29, Jim J. Yang wrote:

> How can I have a "vertical scrollbar" in a Combobox such that text
> items which are too long can also be showed in their full length
> (of course without having to have a very wide Combobox)?

The Platform SDK claims you can send a CB_SETHORIZONTALEXTENT message
to the combo box, which will set the scrolling width for the list
box. It doesn't seem to work, though.

Another option is to send a CB_SETDROPPEDWIDTH message to the combo
box. This will set the width of the dropped list, regardless of the
combo box's width.

-- 
Yorai Aminov (TeamB)
(TeamB cannot answer questions received via email.)
Shorter Path - http://www.shorterpath.com
Yorai's Page - http://www.yoraispage.com