Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Win32API, Ruby, Clipboard/DC, HALP!

Name: Anonymous 2007-02-03 19:10

To go straight to the problem: i need ruby, to without my help, be able to retrive window contents in the form of a  bitmap or other image format.

My first approach was to with BitBlt or similar functions to simply toss over it to some ruby object and then read from that. It failed horribly as i was unable to get the DC handle to any such thing.

So i figured, "printscreen put the shit into a bitmap format. that will probably be a easier approach!"
okay, i do printscreens with keybd_event. no problem there, but how the fuck should i acess the data then? the win32 documentation babbles on about opening the clipboard to be able to read from it, something which also requires you to do a EmptyClipboard call or some shit, effectively annihilating whatever data is in the clipboard already. Not that it matters as my program runs without a window for which i can get the handle to, and the way to associate the clipboard to active task fails.

so could anyone help me with these issues, or suggest another way to do this?

as of now the only way i've got left is to have the shit pasted into paint and saved and then acessed. but that's a horribly inefficient method, i'd like to be able to acess it without having to do a hellish amount of unnessecary tasks or writing to harddrive, as i will need to have this repeated quite often

Name: Anonymous 2007-02-03 20:54

I remember my Win32Api class i had last summer. It still makes me cry at night.

Name: Anonymous 2007-02-03 21:00

This might help you: How to get the handle of a console Window. Console windows, besides shitty, are speshul in Win32, and they made sure you cannot treat them like windows even though they are, for some stupid design criteria. There's a trick to do it though. Since I don't know Ruby, here's C for it, it should be pretty easy to port.

HWND FindConsoleHandle()
 {
  static LPCTSTR temptitle = _T("{98C1C303-2A9E-11d4-9FF5-006067718D04}");
  TCHAR title[512];
  TCHAR me[64];
  wsprintf(me, _T("%s-%08x"), temptitle, GetCurrentProcessID());
  if(GetConsoleTitle(title, sizeof(title)/sizeof(TCHAR)) == 0)
    return NULL;
  SetConsoleTitle(me);
  HWND wnd = FindWindow(NULL, me);
  SetConsoleTitle(title);
  return wnd;
 }

Name: Anonymous 2007-02-04 7:50

Round trip all your information through XML!  That'll really help out if your employer tracks function points, too.  Makes you look way more productive.

/hopes his boss isn't reading this.

Name: Anonymous 2007-02-04 7:55

It's a project i do on my own, so i'm the boss.

And it seems like ruby ain't the very best thing for doing this sort of work, which means off i go to learn C.

Name: Anonymous 2007-02-04 8:00

Perhaps you just need a binary standard to toss your window information through?  I vaguely recall reading somewhere that there's some sort of COM support for Ruby out there and that it's not nearly as uglifying as it is for C/C++.

Going via an image strikes me as trying to solve the wrong problem...

Name: Anonymous 2007-02-04 9:55

>>6
Well, the plan is to make an AI that understands the principles of navigation for 3rd/1st person games(and essentially real life too, but it's easier to start with enviroments not requiring extra hardware).

As for COM support and binary standards, i have no clue what those are.

Using win32api in ruby doesn't seem to work that well, as it tries to convert bignums into strings by itself and otherwise being quite undocumented. So i'm thinking, how hard could it be to do a piece of code in other language that returns a bitmap, or just a color information array/string?

Name: Anonymous 2007-02-04 14:37

>>2
Ewww... the horror, take it away!

Name: Anonymous 2007-02-04 14:54

Anyway, i fixed it. I managed to get a bitmap handle from clipboard and used GetBitmapBits on it. Didn't know the color information were in BGR format though. sure made the colors fancy looking when you swap the channels.

Name: Anonymous 2007-02-04 15:26

Yeah, I've run into the BGR thing before.  Ironically, the docs I was reading said it was RGB.  I think that bit swap is probably the only in-line assembly I've ever written in a non-academic environment. 

Name: Anonymous 2009-01-14 15:09

lol tripfags

Name: Anonymous 2009-03-06 10:14

Image format converter but   then again if   I was attracted   to moved to   a root directory   when you do   timing on x86   and some others   When you write   a shell script   but much slower   but much easier   to implement a   max function Why.

Name: Anonymous 2009-08-16 23:20

Lain.

Name: Anonymous 2010-06-25 14:48

WARNING: NECRO POST

Name: Sgt.Kabu䈽鮕kiman얎믷 2012-05-28 22:27

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List