Class: WinGdi32Ruby::Gdi32
- Inherits:
-
Object
- Object
- WinGdi32Ruby::Gdi32
- Defined in:
- lib/win-gdi32-ruby.rb
Class Method Summary collapse
-
.capture(left, top, right, bottom) ⇒ Object
Captures the window as a bitmap
left
,top
. -
.load_bitmap(filename) ⇒ Object
- Loads a bitmap from a BMP file
filename
- name of file to load Returns
-
an array containing a handle to the bitmap and a handle to the palette
[hbitmap, hpalette]
.
- Loads a bitmap from a BMP file
-
.save_bitmap(hbitmap, filename) ⇒ Object
- Save the specified bitmap to a file
hwnd
- Handle to the main window (used to get the system pallete)
hbitmap
- Handle to the bitmap to save
filename
- Filename for the bitmap Returns
-
Void.
- Handle to the bitmap to save
- Handle to the main window (used to get the system pallete)
- Save the specified bitmap to a file
Class Method Details
.capture(left, top, right, bottom) ⇒ Object
Captures the window as a bitmap
left
,top
.right
,bottom
-
specifies the rectangle to capture
- Returns
-
a bitmap handle
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/win-gdi32-ruby.rb', line 65 def Gdi32.capture(left, top, right, bottom) # create a DC for the screen and a memory DC compatible to screen DC hscr_dc = Gdi32.create_dc hmem_dc = Gdi32.create_compatible_dc(hscr_dc) width = right - left height = bottom - top # create a bitmap compatible with the screen DC hbitmap = Gdi32.create_compatible_bitmap(hscr_dc, width, height) # select new bitmap into memory DC holdbitmap = Gdi32.select_object(hmem_dc, hbitmap) # bitblt screen DC to memory DC Gdi32.bit_blt(hscr_dc, left, top, width, height, hmem_dc) # select old bitmap back into memory DC and get handle to bitmap of the screen hbitmap = Gdi32.select_object(hmem_dc, holdbitmap); # clean up Gdi32.delete_dc(hscr_dc); Gdi32.delete_dc(hmem_dc); # return handle to the bitmap hbitmap end |
.load_bitmap(filename) ⇒ Object
Loads a bitmap from a BMP file
filename
-
name of file to load
- Returns
-
an array containing a handle to the bitmap and a handle to the palette
<tt>[hbitmap, hpalette]</tt>
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/win-gdi32-ruby.rb', line 51 def Gdi32.load_bitmap(filename) sb = bitmap_helper 'OpenBitmap', 'SP', 'I' # Prepare array for return values bm_plt = [0, 0].pack('L*') raise "Failed to load '#{filename}'" unless sb.call(filename, bm_plt ) hbitmap, hpalette = bm_plt.unpack('L*') [hbitmap, hpalette] end |
.save_bitmap(hbitmap, filename) ⇒ Object
Save the specified bitmap to a file
hwnd
-
Handle to the main window (used to get the system pallete)
hbitmap
-
Handle to the bitmap to save
filename
-
Filename for the bitmap
- Returns
-
Void
38 39 40 41 42 43 44 45 |
# File 'lib/win-gdi32-ruby.rb', line 38 def Gdi32.save_bitmap(hbitmap, filename) # Used to get palette hwnd = hbitmap sb = bitmap_helper 'SaveBitmap', 'LLS', 'V' sb.call hwnd, hbitmap, filename end |