user13342561
user13342561

Reputation:

How capture a window with correct dimensions?

I'm testing for this code example (that use PrintWindow api) to capture a specific window by handle, and saw that window captured is greater than original (when captured with full desktop). There's a possibility to capture the window with same dimensions equals to original?

Thanks in advance.


Edition:

For example suposse that i want capture the body of a site on Internet Explorer:

var
  Title: array [0 .. 255] of Char;
begin
  GetWindowText(GetForegroundWindow, Title, 255);
  if Title <> '' then
  begin
    if ContainsStr(string(Title), '- Internet Explorer') then
    begin
      WindowHandle := FindWindow(nil, PChar(string(Title)));
      WindowHandle := FindWindowEx(WindowHandle, 0, 'Frame Tab', nil);
      WindowHandle := FindWindowEx(WindowHandle, 0, 'TabWindowClass', nil);
      WindowHandle := FindWindowEx(WindowHandle, 0, 'Shell DocObject View',
      nil);
      WindowHandle := FindWindowEx(WindowHandle, 0, 'Internet Explorer_Server', nil); 
    end;
  end;
end;

Then using the code of linked answer, the 1st handle of IE will be with right size on screenshot, already the last (Internet Explorer_Server) will be captured big. I'm searching by a way to offset the size of screenshot to not stretch.

enter image description here


Edition 2:

My goal is align remote mouse clicks on handle. Is true that i already have a solution like you can see in my last comment, but this solution not is working if i'm seeing screenshot only of website body like showed on gif and said above. Then i'm asking about size of screenshot because i think that probaly is it the problem.

Upvotes: 1

Views: 287

Answers (1)

user13342561
user13342561

Reputation:

I discovered the problem!. Happens that in a screen resolution of 1366x768, the screenshot on handle Internet Explorer_Server will be 1366x650, therefore now i must adapt mouse clicks based in this resolution and not on original resolution of screen (1366x768) like done before (linked question).

Server:

X := Round((X * {ResolutionX}1366) / Image1.Width);
Y := Round((Y * {ResolutionY}650) / Image1.Height);

Client:

PostMessage(WindowHandle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(X, Y));
PostMessage(WindowHandle, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(X, Y));

Upvotes: 1

Related Questions