gpt4 book ai didi

windows - 通过 WinAPI 和 Delphi 在 Skype 客户端中查找和使用当前事件的聊天框?

转载 作者:可可西里 更新时间:2023-11-01 09:56:37 26 4
gpt4 key购买 nike

在 Delphi 中,通过使用 Skype API,我可以相当轻松地向联系人发送消息。但是,我想做的是在当前关注的联系人的聊天框中输入消息,而不发送消息。

通过Winspector,我发现Chatbox的Classname是TChatRichEdit,放在一个TChatEntryControl上,然后放在TConversationForm上,最后放在tSkMainForm上。 (显然 Skype 客户端是用 Delphi 编写的;))

如何使用 Win API 找到正确的 tSkMainForm>TConversationForm>TChatEntryControl>TChatRichEdit,然后在其中输入消息?

解决此问题的最佳方法是什么?

此外,TConversationForm 还包含联系人的姓名,所以我想这样会更容易一些吧?

编辑:这是 Windspector Spy 的屏幕截图,显示了 TChatRichEdit:

Winspector Spy

这是我当前的代码:

function GetConversationWindow(Wnd: HWnd; P: LParam): Bool; stdcall;
var
Param: PGetConversationParam;
ProcID: DWord;
// WndClass docs say maximum class-name length is 256.
ClassName: array[0..256] of Char;
WindowTitle: array[0..256] of Char;
begin
Result := True; // assume it doesn't match; keep searching
Param := PGetConversationParam(P);

GetWindowThreadProcessID(Wnd, @ProcID);
if ProcID <> Param.ProcID then
Exit;

if GetClassName(Wnd, ClassName, Length(ClassName)) = 0 then
Exit;
if StrComp(ClassName, 'TConversationForm') <> 0 then
Exit;

if SendMessage(Wnd, wm_GetText, Length(WindowTitle), LParam(@WindowTitle[0])) = 0 then
Exit;
if Param.ContactName = WindowTitle then begin
Param.Result := Wnd;
Result := False;
end;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
Param: TGetConversationParam;
RichEditWnd, ControlWnd : HWND;
ParentWnd : HWND;
begin
//Param.ProcID := GetSkypeProcessID;
Param.ContactName := 'xSky Admin';
ParentWnd := FindWindowEx(0,0,'tSkMainForm',nil);

if EnumChildWindows(ParentWnd,@GetConversationWindow, LParam(@Param)) then
Abort; // Didn't find it.

// Param.Result holds the conversation window's handle. Now walk its children.
ControlWnd := FindWindowEx(Param.Result, 0, 'TChatEntryControl', nil);
if ControlWnd = 0 then
Abort; // Conversation doesn't have an entry control

RichEditWnd := FindWindowEx(ControlWnd, 0, 'TChatRichEdit', nil);
if RichEditWnd = 0 then
Abort;

ShowMessage('Got it!');
end;

我从未到达 ShowMessage。

这是我的 IDE 在 Debug模式下的截图:

IDE in Debug Mode

我在中止行添加了一个断点。

有什么想法吗?

最佳答案

像这样:

var
aHandle : cardinal;
begin
aHandle := FindWindow(PWideChar('TChatRichEdit'), nil);
result := aHandle <> 0;
if result then
PostMessage(aHandle, WM_...);

然后你就有了那个窗口的句柄。您可以使用 WM_SETTEXT 或其他东西来输入文本。但是 Skype 使用 WM_COPYDATA 与其他程序通信,反之亦然。您应该在 StackOverflow 中搜索它。

关于windows - 通过 WinAPI 和 Delphi 在 Skype 客户端中查找和使用当前事件的聊天框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5714542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com