Thema: Delphi Combobox mit Bitmaps

Einzelnen Beitrag anzeigen

Benutzerbild von uligerhardt
uligerhardt

Registriert seit: 19. Aug 2004
Ort: Hof/Saale
1.735 Beiträge
 
Delphi 2007 Professional
 
#13

Re: Combobox mit Bitmaps

  Alt 30. Nov 2007, 14:14
Zitat von Deep-Sea:
Ich bezweifel, dass das so einfach geht.
Eine ComboBox ist nun mal nicht dafür gedacht in ihrer DropDown-Liste "Pseudo-Buttons" zu handhaben.
Ich hab mal eine Combo mit Checkboxen zur Bearbeitung von Sets gebaut (siehe Bild), bei der ich vor einem ähnlichen Problem stand. Ich hab mal (hoffentlich alle) relevanten Teile rausgeklaubt:
Delphi-Quellcode:
type
  TRehCheckComboBox = class(TRehCustomComboBox)
  private
    FListInstance: Pointer;
    FDefListProc: Pointer;
    procedure ListWndProc(var Message: TMessage);
    // ...
   end;

constructor TRehCheckComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FListInstance := MakeObjectInstance(ListWndProc);
end;

destructor TRehCheckComboBox.Destroy;
begin
  FreeObjectInstance(FListInstance);
  inherited;
end;

procedure TRehCheckComboBox.CreateWnd;
var
  cbi: TComboBoxInfo;
  pListHandle: ^HWND;
begin
  inherited CreateWnd;
  FillChar(cbi, SizeOf(cbi), 0);
  cbi.cbSize := SizeOf(cbi);
  pListHandle := @ListHandle;
  if GetComboBoxInfo(Handle, cbi) then
  begin
    pListHandle^ := cbi.hwndList;
    FDefListProc := Pointer(GetWindowLong(ListHandle, GWL_WNDPROC));
    SetWindowLong(ListHandle, GWL_WNDPROC, Longint(FListInstance));
  end
  else
  begin
    //OutputDebugString(PChar(SysErrorMessage(GetLastError)));
    pListHandle^ := 0;
  end;
end;

procedure TRehCheckComboBox.ListWndProc(var Message: TMessage);
var
  X, Y, Index: Integer;
begin
  case Message.Msg of
    WM_LBUTTONDOWN:
      begin
        X := TWMMouse(Message).XPos;
        Y := TWMMouse(Message).YPos;
        Index := ItemAtPos(Point(X, Y), True);
        if Index <> -1 then
        begin
          if not UseRightToLeftAlignment then
          begin
            if X - ItemRect(Index).Left < GetCheckWidth then
            begin
              ToggleClickCheck(Index);
              Exit;
            end;
          end
          else
          begin
            Dec(X, ItemRect(Index).Right - GetCheckWidth);
            if (X > 0) and (X < GetCheckWidth) then
            begin
              ToggleClickCheck(Index);
              Exit;
            end;
          end;
        end;
      end;
  end;

  Message.Result := CallWindowProc(FDefListProc, ListHandle, Message.Msg,
    Message.WParam, Message.LParam);
end;
HTH,
Uli.
Miniaturansicht angehängter Grafiken
checkcombo_135.png  
Uli Gerhardt
  Mit Zitat antworten Zitat