Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: ForeverZer0 on December 04, 2010, 08:38:40 pm

Title: Someone with Ruby/Win32API knowledge needed!
Post by: ForeverZer0 on December 04, 2010, 08:38:40 pm
As you may have noticed, I have been exploring many of the features of the Win32API module, but I am utterly stumped on something.

What I am trying to do is to find a way to retrieve data off the clipboard and set as a bitmap object in Ruby, but without the use of an external DLL. Basically it can do the same thing as the Screenshot.dll (I already have methods to have a bitmap object save to a PNG file if needed). This would be no problem in later versions of Ruby with the WINOLE module to pass the clipboard data to MSPaint or whatever, have it save, then load it normally, but I can't seem to figure out how exactly to read the data I get properly. Here's what I got for creating the image:


  Keybd_Event = Win32API.new('user32', 'keybd_event', 'LLLL', '')
 
  def capture
    Keybd_Event.call(0x12, 0, 0, 0) # ALT Down
    Keybd_Event.call(0x2C, 0, 0, 0) # PRINT SCREEN Down
    Keybd_Event.call(0x2C, 0, 2, 0) # PRINT SCREEN Up
    Keybd_Event.call(0x12, 0, 2, 0) # ALT Up
  end


This is the same as ALT + Print Screen being pressed, which sets a bitmap image to the clipboard.

Now, for reading it, this is what I got so far:


  OpenClipboard = Win32API.new('user32', 'OpenClipboard', 'L', 'L')
  GetClipboardData = Win32API.new('user32', 'GetClipboardData', 'L', 'L')
  CloseClipboard = Win32API.new('user32', 'CloseClipboard', '', 'L')
 
  # Pretty sure I will need these, but not sure yet how to use properly.
  GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'LL', 'L')
  GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L')
  GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'L', 'L')
  GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'L', '')
 
  Memcpy = Win32API.new('ntdll', 'memcpy', 'PPL', 'L')
  #Memcpy = Win32API.new('crtdll', 'memcpy', 'PPL', 'L')
 
 
  def read
    OpenClipboard.call(0)
    image = GetClipboardData.call(8)
    CloseClipboard.call


    # What should go here?
   
   
  end


There is two major things I am unsure of.



Any help that could be offered in this would be much appreciated.
Title: Re: Someone with Ruby/Win32API knowledge needed!
Post by: Blizzard on December 05, 2010, 05:41:13 am
http://msdn.microsoft.com/en-us/library/ms649039(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ff729168(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/dd183375(v=VS.85).aspx

You probably have separate the array into two blocks, one of them being the bitmapdata structure (which you can most probably just get rid of, but probably you will have to analyze it to get the format data of the bitmap) and one being the actual data.
Look up String#pack and String#unpack to learn how to convert the data.
Title: Re: Someone with Ruby/Win32API knowledge needed!
Post by: ForeverZer0 on December 05, 2010, 12:54:00 pm
Beautiful. Thank you!

I don't know why I couldn't get them to pop up on a google search...
Title: Re: Someone with Ruby/Win32API knowledge needed!
Post by: Blizzard on December 05, 2010, 04:36:21 pm
I put in specifically GetClipboardData and then I clicked a few links on the page to gather those few links.
Title: Re: Someone with Ruby/Win32API knowledge needed!
Post by: ForeverZer0 on December 05, 2010, 04:37:39 pm
I kept searching the same thing, but including the word "ruby" in there.
Title: Re: Someone with Ruby/Win32API knowledge needed!
Post by: Blizzard on December 05, 2010, 04:47:32 pm
Yeah, you probably shouldn't have done that. xD If you want WinAPI functions, just type them into Google without anything. Among the first links are usually the MSDN documentation pages for the function you are looking for.