我在别人写的控件中看到以下代码,当执行Params.Style:=Params.Style or CtlCheckbox;后Treeview就显示带Checkbox了,谁能告诉我这是怎么回事。
$0100这个值是从那查出来的Const CtlCheckbox=$0100;
Const CheckedStatus=$2000;
const UnCheckedStatus=$1000;
procedure TWangTreeview.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=Params.Style or CtlCheckbox;
end;
$0100这个值是从那查出来的Const CtlCheckbox=$0100;
Const CheckedStatus=$2000;
const UnCheckedStatus=$1000;
procedure TWangTreeview.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=Params.Style or CtlCheckbox;
end;
SysUtils, Classes, Controls, ComCtrls,commctrl;type
TwangTreeview = class(TCustomTreeView)
private
{ Private declarations }
protected
{ Protected declarations }
procedure CreateParams(var Params: TCreateParams); override; public
{ Public declarations }
published
{ Published declarations }
property Align;
property Anchors;
property AutoExpand;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property ChangeDelay;
property Color;
property Ctl3D;
property Constraints;
property DragKind;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HotTrack;
property Images;
property Indent;
property MultiSelect;
property MultiSelectStyle;
property ParentBiDiMode;
property ParentColor default False;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property RightClickSelect;
property RowSelect;
property ShowButtons;
property ShowHint;
property ShowLines;
property ShowRoot;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property ToolTips;
property Visible;
property OnAddition;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnChange;
property OnChanging;
property OnClick;
property OnCollapsed;
property OnCollapsing;
property OnCompare;
property OnContextPopup;
property OnCreateNodeClass;
property OnCustomDraw;
property OnCustomDrawItem;
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnExpanding;
property OnExpanded;
property OnGetImageIndex;
property OnGetSelectedIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
{ Items must be published after OnGetImageIndex and OnGetSelectedIndex }
property Items;
end;
Const CtlCheckbox=$0500;
Const CheckedStatus=$2000;
const UnCheckedStatus=$1000;
function IsItemCheck(InTwangTreeView:TwangTreeview;itemindex:integer):boolean;
Procedure SetCheckStatus(InTwangTreeView:TwangTreeview;itemindex:integer;Checked:boolean);procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TwangTreeview]);
end;procedure TwangTreeview.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=Params.Style or CtlCheckbox;
end;function IsItemCheck(InTwangTreeView:TwangTreeview;itemindex:integer):boolean;
var
item:TTVItem;
begin
item.mask:=TVIF_HANDLE;
item.hItem:=InTwangTreeView.Items[itemindex].ItemId;
TreeView_GetItem(InTwangTreeView.Handle,item);
if (item.state and CheckedStatus)=0 then
result:=false
else
result:=true;
end;Procedure SetCheckStatus(InTwangTreeView:TwangTreeview;itemindex:integer;Checked:boolean);
var
item:TTVItem;
begin
item.mask:=TVIF_HANDLE;
item.hItem:=InTwangTreeView.Items[itemindex].ItemId;
TreeView_GetItem(InTwangTreeView.Handle,item);
item.mask:=TVIF_HANDLE or TVIF_STATE;
if checked then
item.state:= (item.state or CheckedStatus) and (not UnCheckedStatus)
else
item.state:= (item.state or UnCheckedStatus) and (not CheckedStatus );
item.stateMask:=$ffffffff;
treeView_SetItem(InTwangTreeView.Handle,item);
end;end.
利用api HWND CreateWindow( LPCTSTR lpClassName, // pointer to registered class name
LPCTSTR lpWindowName, // pointer to window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // handle to menu or child-window identifier
HANDLE hInstance, // handle to application instance
LPVOID lpParam // pointer to window-creation data
);
其中dwStyle就是Delphi中的Params.Style。
所以我猜测:这是微软未公开的东西。
当然,“$0100;$2000;$1000;都是windows定义的:-(”也是猜测。
说猜测好像不负责,其实应该是“推理”。
我认为我的推理是正确的。
Const CtlCheckbox=$0500;//windows定义的消息
Const CheckedStatus=$2000;
const UnCheckedStatus=$1000;
procedure TWangTreeview.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=Params.Style or CtlCheckbox;
end;
Caption: PChar;
Style: DWORD;
ExStyle: DWORD;
X, Y: Integer;
Width, Height: Integer;
WndParent: HWnd;
Param: Pointer;
WindowClass: TWndClass;
WinClassName: array[0..63] of Char;
end;
Const CtlCheckbox=$0500;//windows定义的消息
Const CtlCheckbox=$0100;我试了一下,500和100都一个效果,没区别。
大家可以试一下,在form上添加一个TreeView,
然后SetWindowLong( TreeView1.Handle, GWL_STYLE, GetWindowLong(
TreeView1.Handle, GWL_STYLE ) or $0100 );
CheckBox就出来了,把$0100 换成$0500一样,其它的数300,700,900,111,123,135,101...也行,
只要第二位数字是单数就可以,哈哈...
一切都是比尔说了算,在他未公开某个函数的隐藏参数之前,开发者无法使用这些参数,但是比尔却可以使用这些参数搞出普通开发者作不了的神奇效果。
Delphi的一切都是比尔给的,所以Delphi无论如何也作不过比尔的最新最神奇的东西。
唉,不得不低头啊...
我再猜测--或者叫推理:
1、Borland的从微软那里拿到了普通开发者拿不到的资料;
2、Borland分析了微软做出的类似东西,然后自己也跟进;
3、微软其实公开了这些参数,(当然不是在他的SDK中公布的)但是我并没得到....我没有装MSDN,微软也没有给我发Email.