SendMessage(句柄,WM_SETTEXT)的问题

wq236589 2008-12-09 11:48:02
我想实现向Google Earth的一个子窗口发送字符串、清空子窗口
我用的是SendMessage,在记事本中没有问题
可是我在Google Earth中使用就是不行。
在Google Earth中用SendMessage(WM_SETTEXT )会更改窗口的标题,text不变这是怎么回事,怎么解决这个问题?

...全文
576 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wztimes 2012-05-06
  • 打赏
  • 举报
回复
都是没下文的, 也需要这样的代码呀
wq236589 2008-12-11
  • 打赏
  • 举报
回复
我的问题不在能不能获取句柄而是获取句柄以后怎么向窗口放入字符和清空字符,获取句柄是肯定没问题的但是向窗口发送消息以后修改的不是text文本,而是这个窗口的标题。
wq236589 2008-12-11
  • 打赏
  • 举报
回复
我想用另一个方法实现清空指定窗口文本:

先让指定窗口获得焦点,人后发送退格键信息,

请问怎么实现?

最好把代码写一下,谢谢各位了。
zhao_yong 2008-12-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wq236589 的回复:]
我是这样获取子窗体的代码的,标题和类名使用spyxx查的

Delphi(Pascal) code
var
ck:hwnd;
begin
ck:=FindWindow(nil,PChar('Google Earth Pro '));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('qt_central_widget'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('MainWindowHSplitter'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('LeftPanelVSplitter'));
ck:=FindWindowEx(ck,0,PC…
[/Quote]
你确定你所有的ch都有取到值?有些是采用的保护的,如QQ登录窗口,取不到它的密码的值吧?
wq236589 2008-12-09
  • 打赏
  • 举报
回复
我发送的字符串长度没问题
我只是不明白为什么改变的是窗口标题而不是text文本
filec75 2008-12-09
  • 打赏
  • 举报
回复
不懂,up
starluck 2008-12-09
  • 打赏
  • 举报
回复


WM_SETTEXT 才有接收多少字符,你看下。 GOOGLE那玩意能接受多少???
wq236589 2008-12-09
  • 打赏
  • 举报
回复
如果句柄不对的话为什么改变的是标题啊
wq236589 2008-12-09
  • 打赏
  • 举报
回复
我用spyxx查了一下应该是对的
yinxd6112 2008-12-09
  • 打赏
  • 举报
回复
发送的句柄不对 不是子窗口的
formiss 2008-12-09
  • 打赏
  • 举报
回复
窗口handle不对吧
zhangxiaommmm 2008-12-09
  • 打赏
  • 举报
回复
up
wq236589 2008-12-09
  • 打赏
  • 举报
回复
我是这样获取子窗体的代码的,标题和类名使用spyxx查的

var
ck:hwnd;
begin
ck:=FindWindow(nil,PChar('Google Earth Pro '));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('qt_central_widget'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('MainWindowHSplitter'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('LeftPanelVSplitter'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('Search'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('Search'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('unnamed'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('搜索'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('searchTabWidget'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('tab pages'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('fly'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('mFlyFrame'));
ck:=FindWindowEx(ck,0,PChar('QWidget'),PChar('mFlyCombo'));
Result :=FindWindowEx(ck,0,PChar('QWidget'),PChar('combo edit'));
end;

wq236589 2008-12-09
  • 打赏
  • 举报
回复
可是我用记事本实验的时候就没有事 可以写进字符串并没有改变标题啊
tjg5202 2008-12-09
  • 打赏
  • 举报
回复
有可能还是句柄的问题吧
nanchangfantasy 2008-12-09
  • 打赏
  • 举报
回复
SendMessage(
(HWND) hWnd, // handle to destination window
WM_SETTEXT, // message to send
(WPARAM) wParam, // not used; must be zero
(LPARAM) lParam // window-text string (LPCTSTR)
);
For a combo box, the text is the contents of the edit-control portion of the combo box. For a button, the text is the button name. For other windows, the text is the window title
看明白了吗,一般其他的窗体,像你所说的就是改变窗体Caption也叫做 title
作者: 三角猫 出处: http://www.zu14.cn/ 版权归 三角猫 和 真有意思网 所有,转载请注明出处 using System; using System.Collections.Generic; using System.Text; namespace QQAutoMsg { /// /// 消息发送 /// internal static class QQMsgSender { /// /// 发送消息 /// /// 所以已打开的QQ窗体的列表 /// 消息内容 internal static void Go(List qqChatWindows, string msg) { foreach (EnumQQChatWindows.QQChatWindow win in qqChatWindows) { SendMsg(win.WindowHwnd, msg); } } /// /// 根据窗体句柄,找到输入框和发送按钮,发送消息出去 /// /// 聊天窗口句柄 /// 消息内容 private static void SendMsg(IntPtr hWnd, string msg) { if (NativeMethods.IsWindow(hWnd)) //确认该聊天窗口仍然有效 { ////找到 发送 按钮 IntPtr hwndButton = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "Button", "发送(S)"); if (IntPtr.Zero != hwndButton) { ////找到窗体顺序上的第一个RichEdit20A控件,其实就是消息显示框 IntPtr hwndRichEdit = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "RichEdit20A", null); ////利用spy++,可以看到消息输入框的父窗体是类名为 AfxWnd42 的控件 ////在顺序上是显示框的下一个窗体 if (IntPtr.Zero != hwndRichEdit) { ////找到 AfxWnd42 这个窗体 hwndRichEdit = NativeMethods.GetWindow(hwndRichEdit, NativeMethods.GW_HWNDNEXT); if (IntPtr.Zero != hwndRichEdit) { ////这才是真正的消息输入框 hwndRichEdit = NativeMethods.FindWindowEx(hwndRichEdit, IntPtr.Zero, "RichEdit20A", null); if (hwndRichEdit != IntPtr.Zero) { ////发送消息,因为QQ屏蔽了 WM_SETTEXT, WM_PASTE 命令,所有采用 EM_REPLACESEL 来实现 NativeMethods.SendMessage(hwndRichEdit, NativeMethods.EM_REPLACESEL, IntPtr.Zero, msg); ////给发送按钮发 鼠标单击消息 NativeMethods.SendMessage(hwndButton, NativeMethods.BM_CLICK, IntPtr.Zero, IntPtr.Zero); } } } } } } } }

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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