Delphiでは、Skype APIを使用することで、連絡先にメッセージを簡単に送信できます。しかし、私がやろうとしているのは、メッセージを送信せずに、現在フォーカスされている連絡先のチャットボックスにメッセージを入力することです。
Winspectorを使用すると、チャットボックスのクラス名はTChatRichEditであり、TChatEntryControlに配置され、TConversationFormに配置され、最後にtSkMainFormに配置されることがわかりました。(明らかに、SkypeクライアントはDelphiでコーディングされています;))
Win APIを使用して、正しいtSkMainForm> TConversationForm> TChatEntryControl> TChatRichEditを見つけて、それにメッセージを入力するにはどうすればよいですか?
これについて行くための最良の方法は何でしょうか?
また、TConversationFormには連絡先の名前も含まれているので、少し簡単になると思いますか?
編集:これは、Windspector Spyのスクリーンショットで、TChatRichEditを示しています。
これが私の現在のコードです:
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のスクリーンショットは次のとおりです。
中止行にブレークポイントを追加しました。
何か案は?