蔓
蔓草
Unregistered / Unconfirmed
GUEST, unregistred user!
unit text;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Grids;
type
TTestCombobox = class;
TMyComboBox=class(TListbox)
private
FEdit:TTestCombobox;
protected
procedure CreateParams(var params:TCreateParams);override;
procedure CreateWnd; override;
procedure WMSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
public
constructor Create(AOwner:TComponent);override;
end;
TTestCombobox = class(TcustomEdit)
private
FMyComboBox:TMyComboBox;
FDowned:Boolean;
procedure ShowCombobox;
procedure HideComboBox;
protected
procedure CMCancelMode(var Msg:TCMCancelMode);message CM_CANCELMODE;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
procedure WMKillFocus(var Msg:TWMKillFocus);message WM_KILLFOCUS;
procedure WM_KeyDown(var Msg:TWMKey);message WM_KEYDOWN;
public
Constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DevTools', [TTestCombobox]);
end;
{ TTestCombobox }
procedure TTestCombobox.CMCancelMode(var Msg: TCMCancelMode);
begin
inherited;
if FDowned then
begin
HideComboBox;
end;
end;
constructor TTestCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyComboBox:=TMyComboBox.Create(self);
FDowned:=false;
end;
destructor TTestCombobox.Destroy;
begin
FMyComboBox.Free;
FMyComboBox:=nil;
inherited Destroy;
end;
procedure TTestCombobox.HideComboBox;
begin
ShowWindow(FMyCombobox.handle,SW_HIDE);
FDowned:=not FDowned;
end;
procedure TTestCombobox.ShowCombobox;
var
Point:TPoint;
begin
Point.x:=Left;
Point.y:=top+Height;
Point:=Parent.ClienttoScreen(Point);
SetWindowPos(FMyComboBox.Handle,HWND_TOP,Point.x,Point.y,0,0,SWP_NOACTIVATE or SWP_HideWindow or SWP_NOSIZE); ShowWindow(FMyComboBox.Handle,SW_SHOW);
FDowned:=not FDowned;
end;
procedure TTestCombobox.WMKillFocus(var Msg: TWMKillFocus);
begin
inherited;
if FDowned then
HideCombobox;
end;
procedure TTestCombobox.WM_KeyDown(var Msg: TWMKey);
begin
case Msg.CharCode of
VK_UP,VK_Down:
begin
if FDowned then
begin
SendMessage(FMyCombobox.Handle,Msg.Msg,Msg.CharCode,Msg.KeyData);
end
else
Inherited;
end;
VK_Return,vk_space:
begin
text:=fmycombobox.Items[fmycombobox.itemindex];
if FDowned then hidecombobox; /////这句话怎么没有用,如果是空格键总是出现一个空格,怎么去掉呢
////我想在这里加上一个过程把焦点转移开,相当于TAB健,我写个几个都不管用,应该怎么写?
end;
else
Inherited;
end;
if not FDowned then
begin
ShowComboBox;
end
end;
procedure TTestCombobox.WM_LButtonDown(var Msg: TWMMouse);
begin
Inherited;
if not FDowned then
begin
ShowComboBox;
end
else
begin
HideCombobox;
end;
end;
{ TMyComboBox }
constructor TMyComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEdit:=TTestCombobox(AOwner);
ControlStyle:=ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];
Width:=fedit.width;///这句怎么没有用?
Height:=130;
Visible := False;
Parent:=TWinControl(AOwner);
end;
procedure TMyComboBox.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
with Params do
begin
Style:=style or ws_popup;
EXStyle:=EXStyle or WS_EX_CLIENTEDGE or WS_EX_TOOLWINDOW;
end;
end;
procedure TMyComboBox.CreateWnd;
begin
inherited;
inherited CreateWnd;
Items.Assign (Screen.Fonts);
end;
procedure TMyComboBox.WMSetFocus(var Msg: TWMSetFocus);
begin
Inherited;
FEdit.SetFocus;
end;
procedure TMyComboBox.WM_LButtonDown(var Msg: TWMMouse);
begin
inherited;
fedit.Text:=items[itemindex];////这句话永远也不发生,为什么?
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Grids;
type
TTestCombobox = class;
TMyComboBox=class(TListbox)
private
FEdit:TTestCombobox;
protected
procedure CreateParams(var params:TCreateParams);override;
procedure CreateWnd; override;
procedure WMSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
public
constructor Create(AOwner:TComponent);override;
end;
TTestCombobox = class(TcustomEdit)
private
FMyComboBox:TMyComboBox;
FDowned:Boolean;
procedure ShowCombobox;
procedure HideComboBox;
protected
procedure CMCancelMode(var Msg:TCMCancelMode);message CM_CANCELMODE;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
procedure WMKillFocus(var Msg:TWMKillFocus);message WM_KILLFOCUS;
procedure WM_KeyDown(var Msg:TWMKey);message WM_KEYDOWN;
public
Constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DevTools', [TTestCombobox]);
end;
{ TTestCombobox }
procedure TTestCombobox.CMCancelMode(var Msg: TCMCancelMode);
begin
inherited;
if FDowned then
begin
HideComboBox;
end;
end;
constructor TTestCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyComboBox:=TMyComboBox.Create(self);
FDowned:=false;
end;
destructor TTestCombobox.Destroy;
begin
FMyComboBox.Free;
FMyComboBox:=nil;
inherited Destroy;
end;
procedure TTestCombobox.HideComboBox;
begin
ShowWindow(FMyCombobox.handle,SW_HIDE);
FDowned:=not FDowned;
end;
procedure TTestCombobox.ShowCombobox;
var
Point:TPoint;
begin
Point.x:=Left;
Point.y:=top+Height;
Point:=Parent.ClienttoScreen(Point);
SetWindowPos(FMyComboBox.Handle,HWND_TOP,Point.x,Point.y,0,0,SWP_NOACTIVATE or SWP_HideWindow or SWP_NOSIZE); ShowWindow(FMyComboBox.Handle,SW_SHOW);
FDowned:=not FDowned;
end;
procedure TTestCombobox.WMKillFocus(var Msg: TWMKillFocus);
begin
inherited;
if FDowned then
HideCombobox;
end;
procedure TTestCombobox.WM_KeyDown(var Msg: TWMKey);
begin
case Msg.CharCode of
VK_UP,VK_Down:
begin
if FDowned then
begin
SendMessage(FMyCombobox.Handle,Msg.Msg,Msg.CharCode,Msg.KeyData);
end
else
Inherited;
end;
VK_Return,vk_space:
begin
text:=fmycombobox.Items[fmycombobox.itemindex];
if FDowned then hidecombobox; /////这句话怎么没有用,如果是空格键总是出现一个空格,怎么去掉呢
////我想在这里加上一个过程把焦点转移开,相当于TAB健,我写个几个都不管用,应该怎么写?
end;
else
Inherited;
end;
if not FDowned then
begin
ShowComboBox;
end
end;
procedure TTestCombobox.WM_LButtonDown(var Msg: TWMMouse);
begin
Inherited;
if not FDowned then
begin
ShowComboBox;
end
else
begin
HideCombobox;
end;
end;
{ TMyComboBox }
constructor TMyComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEdit:=TTestCombobox(AOwner);
ControlStyle:=ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];
Width:=fedit.width;///这句怎么没有用?
Height:=130;
Visible := False;
Parent:=TWinControl(AOwner);
end;
procedure TMyComboBox.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
with Params do
begin
Style:=style or ws_popup;
EXStyle:=EXStyle or WS_EX_CLIENTEDGE or WS_EX_TOOLWINDOW;
end;
end;
procedure TMyComboBox.CreateWnd;
begin
inherited;
inherited CreateWnd;
Items.Assign (Screen.Fonts);
end;
procedure TMyComboBox.WMSetFocus(var Msg: TWMSetFocus);
begin
Inherited;
FEdit.SetFocus;
end;
procedure TMyComboBox.WM_LButtonDown(var Msg: TWMMouse);
begin
inherited;
fedit.Text:=items[itemindex];////这句话永远也不发生,为什么?
end;
end.