function MyGetClassName(Handle: THandle): string; var buf: array[0..255] of Char; begin if GetClassName(Handle, buf, SizeOf(buf)) > 0 then begin Result := buf; end else begin Result := ''; end; end;
function MyGetWindowText(hWnd: THandle): string; var len: Integer; begin Result := ''; len := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0); if len > 0 then begin SetLength(Result, len +1); len := SendMessage(hWnd, WM_GETTEXT, len +1, Integer(PChar(Result))); if len > 0 then begin SetLength(Result, len); end else begin Result := ''; end; end; end;
function FindFormByClass(const AClassName: string): TForm; var i: Integer; begin Result := nil; for i := 0 to Application.ComponentCount -1 do begin if Application.Components[i].ClassNameIs(AClassName) then begin Result := TForm(Application.Components[i]); Exit; end; end; end;
function MyGetRoleText(Acc: IAccessible; varChild: OleVariant): string; var varRole : OleVariant; Len: Integer; begin Result := ''; if Acc.get_accRole(varChild, varRole) = S_OK then begin if TVariantArg(varRole).vt = VT_I4 then begin Len := GetRoleTextW(TVariantArg(varRole).lVal, nil, 0); SetLength(Result, Len); GetRoleTextW(TVariantArg(varRole).lVal, PWideChar(Result), Len + 1); end; end; end;
function GetDialogMsgText(Handle: THandle): string; var clsName: string; frmMsg: TForm; lblMsg: TLabel; h: THandle; i: Integer; childCount: Integer; acc: IAccessible; oChild: IDispatch; s: WideString; begin Result := ''; if Handle = 0 then Exit;
clsName := MyGetClassName(Handle); if SameText('TMessageForm', clsName) then begin frmMsg := FindFormByClass('TMessageForm'); if Assigned(frmMsg) then begin lblMsg := frmMsg.FindComponent('Message') as TLabel; if Assigned(lblMsg) then begin Result := lblMsg.Caption; end; end; end else if SameText('#32770', clsName) then begin h := FindWindowEx(Handle, 0, 'DirectUIHWND', nil); if h <> 0 then begin /// DirectUI if AccessibleObjectFromWindow(h, OBJID_CLIENT, IID_IAccessible, acc) = S_OK then begin if S_OK = acc.Get_accChildCount(childCount) then begin for i := 1 to childCount do begin if (S_OK = acc.Get_accChild(i, oChild)) and SameText('text', MyGetRoleText(oChild as IAccessible, 0)) then begin s := ''; if (S_OK = IAccessible(oChild).Get_accName(0, s)) and (s <> '') then begin Result := s; Break; end; end; end; end; end; end else begin /// Tradiontal dialog h := 0; repeat h := FindWindowEx(Handle, h, 'Static', nil); if h <> 0 then begin Result := MyGetWindowText(h); end; until (h = 0) or (Result <> ''); end; end; end;
----------------------------------------------
-广袤璀璨的银河,永无止境的梦想(梦无止境游银河) 博客挂了……
谢谢各位帮助,用了非常麻烦的方式实现了, 在调用dll中的函数时,启动hooh api检测DrawText,如果获取到内容,用FindWindow找弹窗,找到弹窗后发送SendMessage将弹窗关闭,再调用程序中通用的弹窗,将内容显示 bahamut8348说的方法不会用,用setwindowlongptr替换哪个函数?我试了替换消息函数,想抓取WM_PAINT消息中的内容,再调用程序中已有的弹窗显示内容,但窗体已经显示了才能用FindWindow找到句柄,不再触发WM_PAINT消息,没有抓到消息 SetWindowLong(WH, GWL_WNDPROC, LongInt(MakeObjectInstance(GridProc))); procedure TForm1.GridProc(var Meg: Tmessage); begin if Meg.Msg = WM_PAINT then begin Memo1.Lines.Add('没有抓到消息'); end; end;
----------------------------------------------
-