Einzelnen Beitrag anzeigen

AlphaBug

Registriert seit: 2. Mär 2004
Ort: hinterm Transistor 246 gleich links
46 Beiträge
 
Delphi 6 Enterprise
 
#6

Re: ComboBox am Aufklappen hindern

  Alt 10. Aug 2004, 12:37
Außer dem Ableiten einer eigenen ComboBox fällt mir nicht mehr viel ein.
(Vieleicht im DropDown-Event etwas basteln...)
Ich hoffe, diese Code-Schnipsel helfen dabei:

Delphi-Quellcode:
  TCustomCombo = class(TCustomListControl)
  private
    ...
    procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
    ...
  protected
    ...
    procedure AdjustDropDown; virtual;
    ...
  end;

  TCustomComboBox = class(TCustomCombo)
  ...

  TMyComboBox = class(TCustomComboBox)
  private
    ...
    procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
    ...
  protected
    ...
    procedure AdjustDropDown; override;
    ...
  end;

...

procedure TCustomCombo.CNCommand(var Message: TWMCommand);
begin
  case Message.NotifyCode of
    CBN_DBLCLK:
      DblClick;
    CBN_EDITCHANGE:
      Change;
    CBN_DROPDOWN:
      begin
        FFocusChanged := False;
        // DropDown-Event ausführen
        DropDown;
        // DropDown-Liste konfigurieren
        AdjustDropDown;
        if FFocusChanged then
        begin
          PostMessage(Handle, WM_CANCELMODE, 0, 0);
          if not FIsFocused then
            // DropDown-Liste anzeigen
            PostMessage(Handle, CB_SHOWDROPDOWN, 0, 0);
        end;
      end;
    CBN_SELCHANGE:
      begin
        Text := Items[ItemIndex];
        Click;
        Select;
      end;
    CBN_CLOSEUP:
      CloseUp;
    CBN_SETFOCUS:
      begin
        FIsFocused := True;
        FFocusChanged := True;
        SetIme;
      end;
    CBN_KILLFOCUS:
      begin
        FIsFocused := False;
        FFocusChanged := True;
        ResetIme;
      end;
  end;
end;


procedure TCustomCombo.AdjustDropDown;
var
  Count: Integer;
begin
  Count := ItemCount;
  if Count > DropDownCount then Count := DropDownCount;
  if Count < 1 then Count := 1;
  FDroppingDown := True;
  try
    SetWindowPos(FDropHandle, 0, 0, 0, Width, ItemHeight * Count +
      Height + 2, SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_NOREDRAW or
      SWP_HIDEWINDOW);
  finally
    FDroppingDown := False;
  end;
  SetWindowPos(FDropHandle, 0, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or
    SWP_NOZORDER or SWP_NOACTIVATE or SWP_NOREDRAW or SWP_SHOWWINDOW);
end;
Delphi 4ever !
  Mit Zitat antworten Zitat