function HasScroll(hWND:HWND):Boolean; var ff:TForm; begin Result := false; if IsVCLControl(hWND) then begin ff := FindControl(hWND) as TForm; if (ff <> nil) and ff.ScrollInView(ff) then Result := true; end; end;不敢肯定是否可用。 你试试看?
随便写个,不完整。有一定参考价值var h,hc:HWND; begin h:=findwindow('Tform1',nil); hc:=Findwindowex(h,nil,'Tscroll',nil); if hc <>0 then begin //有滚动条 end; end; 提前用spy++看看结构是不是Tscroll。
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Memo2: TMemo; ListBox1: TListBox; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm} function ScrollBarVisible(H: THandle; Code: Word): Boolean; var Style: Longint; begin Style := WS_HSCROLL; if Code = SB_VERT then Style := WS_VSCROLL; Result := GetWindowLong(H, GWL_STYLE) and Style <> 0; end;procedure TForm1.Button1Click(Sender: TObject); var H: THandle; begin H := ListBox1.Handle; if H<>0 then Memo2.Lines.Add('ok'); if ScrollBarVisible(H, SB_VERT) then Memo2.Lines.Add('VSCROLL'); if ScrollBarVisible(H, SB_HORZ) then Memo2.Lines.Add('HSCROLL'); end;procedure TForm1.FormCreate(Sender: TObject); var I: integer; begin for I:=100 to 1000 do Listbox1.Items.Add('数据项数据项第'+IntToStr(i)); end;end.对记事本什么的无效。对一般的Form ListBox Memo标准控件还可以。
WS_VSCROLL 竖直滚动条 WS_HSCROLL 水平滚动条 var dwHandle:THandle; iResult:Integer; begin dwHandle:=$00A40D6A;//窗口句柄 iResult:=GetWindowLong(dwHandle,GWL_STYLE); if ((iResult and WS_VSCROLL )>0 ) or ( (iResult and WS_HSCROLL )>0) then begin ShowMessage(''); end;
var ff:TForm;
begin
Result := false;
if IsVCLControl(hWND) then
begin
ff := FindControl(hWND) as TForm;
if (ff <> nil) and ff.ScrollInView(ff) then
Result := true;
end;
end;不敢肯定是否可用。
你试试看?
h,hc:HWND;
begin
h:=findwindow('Tform1',nil);
hc:=Findwindowex(h,nil,'Tscroll',nil);
if hc <>0 then
begin
//有滚动条
end;
end;
提前用spy++看看结构是不是Tscroll。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function ScrollBarVisible(H: THandle; Code: Word): Boolean;
var
Style: Longint;
begin
Style := WS_HSCROLL;
if Code = SB_VERT then Style := WS_VSCROLL;
Result := GetWindowLong(H, GWL_STYLE) and Style <> 0;
end;procedure TForm1.Button1Click(Sender: TObject);
var
H: THandle;
begin
H := ListBox1.Handle;
if H<>0 then Memo2.Lines.Add('ok');
if ScrollBarVisible(H, SB_VERT) then
Memo2.Lines.Add('VSCROLL');
if ScrollBarVisible(H, SB_HORZ) then
Memo2.Lines.Add('HSCROLL');
end;procedure TForm1.FormCreate(Sender: TObject);
var
I: integer;
begin
for I:=100 to 1000 do
Listbox1.Items.Add('数据项数据项第'+IntToStr(i));
end;end.对记事本什么的无效。对一般的Form ListBox Memo标准控件还可以。
WS_HSCROLL 水平滚动条
var
dwHandle:THandle;
iResult:Integer;
begin
dwHandle:=$00A40D6A;//窗口句柄
iResult:=GetWindowLong(dwHandle,GWL_STYLE);
if ((iResult and WS_VSCROLL )>0 ) or ( (iResult and WS_HSCROLL )>0) then
begin
ShowMessage('');
end;
WS_VSCROLL 竖直滚动条
WS_HSCROLL 水平滚动条