各位大虾: 我想从给定标题的窗口里,定位给定标题的一个标签按钮。如何实现,我的参考程序代码如下。针对我的程序代码,本人有点迷茫,请各位大虾指点迷途:procedure TForm1.Button2Click(Sender: TObject);
var
win_cap, //待查找的主窗体标题
btn_cap: string; //待查找的标签标题 hd, //待查找的主窗体句柄
hdl: hwnd; //遍历主窗体各子控件句柄 ctl_text: array[0..254] of char; //各子控件标题
begin
win_cap := 'flash 作品欣赏 - Microsoft Internet Explorer';
btn_cap := '投我一票'; //获取主窗体句柄
hd := FindWindow(nil,pchar(win_cap)); //获取成功则提取主窗体第一子控件窗口句柄
if hd >0 then
hdl := getWindow(hd,GW_CHILD+GW_HWNDFIRST); //遍历主窗体各子控件
while hdl > 0 do
begin
//获取子控件标题
if GetWindowText(hdl, @ctl_text, 255)>0 then
begin
//与待定位按钮标题比较,一致则查找成功
if pos(btn_cap,StrPas(@ctl_text))>0 then
showmessage('哈哈,就是你...');
end;
hdl := getwindow(hdl,GW_HWNDNEXT);
end; showMessage('结束了...');
end;1、为何GetWindowText总是返回一个空字符串,无任何信息
2、如何正确定位到该控件,如果有懂的,一定要将程序代码调试无误,本人对分绝不吝啬! 谢谢大家!~
var
win_cap, //待查找的主窗体标题
btn_cap: string; //待查找的标签标题 hd, //待查找的主窗体句柄
hdl: hwnd; //遍历主窗体各子控件句柄 ctl_text: array[0..254] of char; //各子控件标题
begin
win_cap := 'flash 作品欣赏 - Microsoft Internet Explorer';
btn_cap := '投我一票'; //获取主窗体句柄
hd := FindWindow(nil,pchar(win_cap)); //获取成功则提取主窗体第一子控件窗口句柄
if hd >0 then
hdl := getWindow(hd,GW_CHILD+GW_HWNDFIRST); //遍历主窗体各子控件
while hdl > 0 do
begin
//获取子控件标题
if GetWindowText(hdl, @ctl_text, 255)>0 then
begin
//与待定位按钮标题比较,一致则查找成功
if pos(btn_cap,StrPas(@ctl_text))>0 then
showmessage('哈哈,就是你...');
end;
hdl := getwindow(hdl,GW_HWNDNEXT);
end; showMessage('结束了...');
end;1、为何GetWindowText总是返回一个空字符串,无任何信息
2、如何正确定位到该控件,如果有懂的,一定要将程序代码调试无误,本人对分绝不吝啬! 谢谢大家!~
解决方案 »
- 用adoquery执行sql存储过程或函数时怎么返回结果消息
- 日期查询问题,查询出来无法显示查询结果
- cxGrid的2个小问题???
- dxTreeList 控件求和的功能应用,请高手帮帮忙。
- 请问我如何判断一个窗口界面是否打开,谢谢各位了,小弟急
- 请问什么是分组报表,Delphi中自带的QReport有分组报表功能吗?
- 急!delphi中数据导出至excel的问题
- 有谁可以告诉我如何给分
- 时间的问题
- 请问TClientData中某条记录进行Delete是否真的删除,能否只是对删除的记录做删除标记而不是真正的删除?
- 请问高手:我想实现如下打印功能该如何设计?(不使用数据库,手动输入后按格式打印)
- 谢谢帮忙!!!!
var
szFull: array[0..MAX_PATH] of Char; //Buffer for window caption
begin
Result := Wnd <> 0;
if Result then
begin
GetWindowText(Wnd, szFull, SizeOf(szFull)); // put window text in buffer
if (Pos(SL[0], StrPas(szFull)) > 0) // Test for text
and (SL.IndexOfObject(TObject(Wnd)) < 0) // Test for duplicate handles
then SL.AddObject(StrPas(szFull), TObject(Wnd)); // Add item to list
EnumChildWindows(Wnd, @EnumChildProc, Longint(SL)); //Recurse into child windows
end;
end; function ClickButton(ParentWindow: Hwnd; ButtonCaption: string): Boolean;
var
SL: TStringList;
H: hWnd;
begin
SL := TStringList.Create;
try
SL.AddObject(ButtonCaption, nil); // First item in list is text to find
EnumChildWindows(ParentWindow, @EnumChildProc, Longint(SL));
H := 0;
case SL.Count of
1: ShowMessage('Window text not found.');
2: H := hWnd(SL.Objects[1]);
else
ShowMessage('Ambiguous text detected.');
end;
finally
SL.Free;
end;
Result := H <> 0;
if Result then PostMessage(H, BM_CLICK, 0, 0);
end;
ClickButton(hdl, btn_cap);
for I := 0 to ComponentCount - 1 do
begin
if (Components[I] is TLabel) then
begin
TLabel(Components[I]].left:=0;
end;
/// ComonentCount 属性好象只有TWinControl 派生类有.
用 WebBrowser1 來控制procedure TForm1.Button1Click(Sender: TObject);
var
ovElements: OleVariant;
i: Integer;
begin
ovElements := WebBrowser1.OleObject.Document.forms.item(0).elements;
for i := 0 to (ovElements.Length - 1) do
if (ovElements.item(i).tagName = 'INPUT') and
(ovElements.item(i).type = 'SUBMIT') and
(ovElements.item(i).Value = 'Recent Charges') then
ovElements.item(i).Click;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ov : OleVariant;
begin
ov := wb.OleObject.Document.All.Item('btnVote', 0); //找到那个按钮
ov.OnClick;
end;
for i := 0 to (ovElements.Length - 1) do
begin
if (ovElements.Item(i).tagName = 'INPUT') and (ovElements.Item(i).type = 'radio') and
(ovElements.Item(i).Value = 'c') then
begin
ovElements.item(i).Checked := true;
wb.OleObject.Document.Forms.Item(0).Submit;
end;
要换成ov := wb.OleObject.document.all.item('submsg', 0); {按名找到那个发送按钮}
ov.Click; {这样表单就submit了,用上面的.Submit好象不是想要的结果}