如何找到窗口上面的一个按钮的句柄。

yuleibo 2002-07-10 05:06:59
用FINDWINDOW可以找到窗口的句柄。可是如何去找到一个窗口里面的按钮的句柄
如果说我找到了记事本的句柄,不小心关闭记事本的时候,他会给我一个提示,是不是保存更改,有三个按钮。我如何找到这三个按钮的句柄,以达到在程序中控制按钮的目的?
我的概念是按钮也应该是类,可是我对这个不太清楚。不知道用什么类,就是记事本的句柄,我也是用GETWINDOW一个一个列举出来的。请高手给指点一个简单的方法。

分数可以再加的。
...全文
863 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuleibo 2002-07-10
  • 打赏
  • 举报
回复
up
hjd_cw 2002-07-10
  • 打赏
  • 举报
回复
我还以为要找标题栏上的 那个 X 呢!理解错误!
dafeifei 2002-07-10
  • 打赏
  • 举报
回复
顺便问一句,QQ的窗口句柄哪位有好方法可以找到呢,它的‘caption’好象是一个随机变化的字符串。
dafeifei 2002-07-10
  • 打赏
  • 举报
回复
不是啊,肯定找得到的,我已经成功了啊
hbutton: hwnd;

hbutton:=findwindowex(hparent,0,nil,'按钮的Caption');//hparent 是该按钮所在的父窗口的句柄;
一定要找到 hparent 才行的。如果按钮有快捷键一定要在 Caption 处加上 (&快捷键字母);
最后,用 sendmessage(hbutton,bm_click,0,0);就可以实现点击了。

你一定要给分我哦!
yuleibo 2002-07-10
  • 打赏
  • 举报
回复
那用什么来找呢?
hjd_cw 2002-07-10
  • 打赏
  • 举报
回复
findwindowex找不到的!肯定!
yuleibo 2002-07-10
  • 打赏
  • 举报
回复
我在用findwindowex的过程中,如果有几个按钮,我应该用哪个函数来处理?
我在找窗口的句柄的时候用了GETWINDOW的NEXTHWND的参数,现在用FINDWINDOW来查找按钮的句柄,如果查找出来的第一个按钮不是我要查找的,那么如何查找下一个按钮呢?
yuleibo 2002-07-10
  • 打赏
  • 举报
回复
我是要看别的程序的句柄,比如说,我在离开电脑的时候,如果别人关闭我的WORD,我的WORD会给出提示是否保存,我可以用程序找到按钮的句柄,然后自动的按下去“是”的按钮。让WORD可以自动保存我的文章。

我现在的问题就是如何去找到这个按钮的句柄,然后如何向这个按钮去发送命令。
zhouzm 2002-07-10
  • 打赏
  • 举报
回复
控件都有Handle, 编程时直接用Button1.Handle可以得到按钮的Handle
纯冰糖 2002-07-10
  • 打赏
  • 举报
回复
用findwindowex,findwindowex(hwnd,0,'tbutton','button1');hwnd是你要观察的窗口的句柄
yuleibo 2002-07-10
  • 打赏
  • 举报
回复
能不能给个源程序,

还有就是按钮的类是什么?

你的这个我怎么看象是DELPHI 上面的WINSDK的帮助。?


yuleibo 2002-07-10
  • 打赏
  • 举报
回复
能不能给个源程序,

还有就是按钮的类是什么?

你的这个我怎么看象是DELPHI 上面的WINSDK的帮助。?


dedemal 2002-07-10
  • 打赏
  • 举报
回复
用findwindowex函数吧!
比如说要找到一个窗体的某一个caption为button1的按钮。
可以这样取得句柄:
findwindowex(hand1,0,'tbutton','button1');
hand1为你要找的那个窗体的句柄!
Drate 2002-07-10
  • 打赏
  • 举报
回复
用它可以找到你要的按钮,不过它不支持NT的,你试试看吧
[Now Supported on Windows NT]

The FindWindowEx function retrieves the handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the given child window.

HWND FindWindowEx(

HWND hwndParent, // handle to parent window
HWND hwndChildAfter, // handle to a child window
LPCTSTR lpszClass, // pointer to class name
LPCTSTR lpszWindow // pointer to window name
);


Parameters

hwndParent

Identifies the parent window whose child windows are to be searched.
If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.

hwndChildAfter

Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.

lpszClass

Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero.

lpszWindow

Points to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.



Return Values

If the function succeeds, the return value is the handle to the window that has the specified class and window names.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧