2

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.

Coringa
  • 406
  • 2
  • 12
  • Just FYI, you don't need `FindWindow()`, as you already have the `HWND` from `GetForegroundWindow()`. If there are multiple IE windows open to the same site, your `FindWindow()` is not guaranteed to find the correct window. – Remy Lebeau May 04 '21 at 15:53
  • @RemyLebeau, i know. But on IE, if you want perform mouse clicks by handle on website body, is possible only on handle where classname is *Internet Explorer_Server*. – Coringa May 04 '21 at 16:09
  • 1
    I know that. I was referring only to your `FindWindow(nil, PChar(string(Title)))` call, not the `FindWindowEx()` calls. You can get rid of that `FindWindow()` call, just save the `HWND` from `GetForegroundWindow()` to your `WindowHandle` variable, eg: `WindowHandle := GetForegroundWindow(); GetWindowText(WindowHandle, Title, 255); ... WindowHandle := FindWindowEx(WindowHandle, ...);` – Remy Lebeau May 04 '21 at 16:12
  • @RemyLebeau, see my **Edition 2**. – Coringa May 04 '21 at 16:24
  • So if I understand you correctly, the issue is that the screenshot stretches when in F11 mode, correct? I tried to reproduce this ([my code](https://pastebin.com/kLPTkjBS)), I get a bigger screenshot when IE is in F11 mode but the bmp is not stretched. – whosrdaddy May 06 '21 at 10:56
  • @whosrdaddy, then, i not understand why seems that i see stretched, filling all space of "viewer", as full desktop. See gif above more carefully. I think that right is screenshot of handle *`Internet Explorer_Server`* with same dimensions, like showed when taked a capture of full desktop. **"`So if I understand you correctly, the issue is that the screenshot stretches when in F11 mode, correct?`"** - And no, i'm not in F11 mode – Coringa May 06 '21 at 13:46
  • so the gif shows the difference between handle of Explorer_Server and main window, I understand now, If I test this my BMP does not stretch. Can you edit your question and provide a complete example that exhibits this behavior? – whosrdaddy May 06 '21 at 14:31

1 Answers1

2

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));
Coringa
  • 406
  • 2
  • 12
  • 1
    The difference looks to be the task bar size. The task bar can be moved to the sides of the screen, set to auto-hide or resized. To test make the taskbar large and on the left. – Brian May 06 '21 at 20:11