Ver Mensaje Individual
  #5  
Antiguo 30-06-2003
Avatar de delphi.com.ar
delphi.com.ar delphi.com.ar is offline
Federico Firenze
 
Registrado: may 2003
Ubicación: Buenos Aires, Argentina *
Posts: 5.964
Reputación: 29
delphi.com.ar Va camino a la fama
Este es un combo mío que despega un CheckListBox:
Código:
  TPopupCheckList = class(TCheckListBox)
  private
  protected
    procedure KeyPress(var Key: Char); override;
    procedure CreateWnd; override;
    procedure CreateParams(var Params: TCreateParams); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
  end;

inplementation

{ TPopupCheckList }

constructor TPopupCheckList.Create(AOwner: TComponent);
begin
  inherited;
  Visible := False;
end;

procedure TPopupCheckList.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do begin
    Style := Style or WS_BORDER;
    ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST;
    AddBiDiModeExStyle(ExStyle);
    WindowClass.Style := CS_SAVEBITS;
  end;
end;

procedure TPopupCheckList.CreateWnd;
begin
  inherited CreateWnd;
  if not (csDesigning in ComponentState) then begin
    Windows.SetParent(Handle, 0);
    CallWindowProc(DefWndProc, Handle, WM_SETFOCUS, 0, 0);
  end;
end;

procedure TPopupCheckList.KeyPress(var Key: Char);
begin
  if (Key = #27)  or (Key = #13) Then
    TCustomCheckCombo(Owner).CloseUp
  else 
    ...
  end;
end;
Código del Combo:

Código:
constructor TCustomCheckCombo.Create(AOwner: TComponent);
begin
  inherited;
  PopupWindow := TPopupCheckList.Create( Self );
  PopupWindow.Parent  := Self;
  PopupWindow.Visible := False;
  ...
end;


procedure TCustomCheckCombo.DropDown;
begin
  { Calcula la posicion y tamaño del Popup .... }
  ...
    Windows.SetParent(PopupWindow.Handle, 0);
    PopupWindow.Visible := True;
    SetWindowPos(PopupWindow.Handle, HWND_TOP, P.X, vPos, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
    SetActiveWindow(PopupWindow.Handle);
end;

procedure TCustomComboEditor.CloseUp;
begin
  SetWindowPos(PopupWindow.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
  PopupWindow.Visible := False;
end;
Y utiliza los mensajes WM_KILLFOCUS y CM_CANCELMODE para hacer un CloseUp por clickear fuera de la lista o perder el foco.

Espero que te sirva, creo no haber olvidado nada, si notas los nombres de las clases te darás cuenta que tengo todo un árbol de jerarquías con esto, así que no fue fácil "resumirlo", Saludos!
__________________
delphi.com.ar

Dedique el tiempo suficiente para formular su pregunta si pretende que alguien dedique su tiempo en contestarla.
Responder Con Cita