--lua
local ffi = require("ffi")
local shell = ffi.load('Shell32.dll')
local C = ffi.C
local GA_ROOTOWNER = 3
local SW_SHOW = 5
ffi.cdef[[
int GetAncestor(int hwnd, unsigned int gaFlags);
typedef struct { long left; long top; long right; long bottom;} RECT;
typedef struct { int cbSize; RECT rcWindow; RECT rcClient; int dwStyle; int dwExStyle;
int dwWindowStatus; int cxWindowBorders; int cyWindowBorders; short atomWindowType; short wCreatorVersion;} WINDOWINFO;
bool GetWindowInfo(int hwnd, WINDOWINFO* pwi);
int ShellExecuteA(int hwnd, const char* lpOperation, const char* lpFile, const char* lpParameters, const char* lpDirectory, int nShowCmd);
]]
local wi = ffi.new('WINDOWINFO')
C.GetWindowInfo(C.GetAncestor(workwindow(), GA_ROOTOWNER), wi)
local pos_client_x = wi.rcClient.left - wi.rcWindow.left
local pos_client_y = wi.rcClient.top - wi.rcWindow.top
local width_client = wi.rcClient.right - wi.rcClient.left
local height_client = wi.rcClient.bottom - wi.rcClient.top
-- привязка к окну Ctrl+A
local path_to_screen = [[C:\window.bmp]] -- путь для скрина
printscreen (C.GetAncestor(workwindow(), GA_ROOTOWNER), pos_client_x, pos_client_y, width_client, height_client, path_to_screen)
shell.ShellExecuteA(0, 'open', path_to_screen, '', '', SW_SHOW)