class << Graphics
CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
SRCCOPY = 0xCC0020
RtlMoveMemory = Win32API.new("kernel32", "RtlMoveMemory", "ipi", "i")
RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
DwCount = (1600 * 800 * 4)# * 2
@@lpBits = "\000" * DwCount
#---------------------------------------------------------------------------#
# snap_to_bitmap #
#---------------------------------------------------------------------------#
def snap_to_bitmap2()
xy = Extra.get_reso #获取分辨率
width = xy[0]
height = xy[1]
hb = Bitmap.new(width, height)
rgbs = self.bitmap_data(0,0,width,height)
RtlMoveMemory.call(hb.address, rgbs, width * height * 4)
hb.export("test")
return hb
end
#---------------------------------------------------------------------------#
# bitmap_data #
#---------------------------------------------------------------------------#
def bitmap_data(s_w,s_h,width,height)
hScrDC = Win32API.new("User32.dll","GetDC",["L"],"L").call(Win32API.new("User32.dll","GetDesktopWindow",[],"L").call())
hMemDC = CreateCompatibleDC.call(hScrDC)
hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
hOldBitmap = SelectObject.call(hMemDC, hBitmap)
win_pos = "\0\0\0\0\0\0\0\0"
ScreenToClient.call(HWnd, win_pos)
win_pos = win_pos.unpack("LL")
xy = Extra.get_reso
BitBlt.call(hMemDC, s_w, s_h, xy[0], xy[1], hScrDC, 0, 0, SRCCOPY)
hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
# 释放所有东西
DeleteDC.call(hScrDC)
DeleteDC.call(hMemDC)
DeleteObject.call(hBitmap)
DeleteObject.call(hOldBitmap)
DeleteObject.call(hBitmap2)
return @@lpBits
end
#---------------------------------------------------------------------------#
# 用户窗口的位置 #
#---------------------------------------------------------------------------#
def xsrc
return self.point[0]
end
#---------------------------------------------------------------------------#
# 用户窗口的位置 #
#---------------------------------------------------------------------------#
def ysrc
return self.point[1]
end
#---------------------------------------------------------------------------#
# 那个点 #
#---------------------------------------------------------------------------#
def point
point = [0,0].pack("LL")
ScreenToClient.call(HWnd, point)
return point.unpack("LL")
end
end