Jump to content

  • Log In with Google      Sign In   
  • Create Account


copy screen to sdl_surface


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 johnysums   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 October 2010 - 02:47 AM

Hello, im trying to figure out how you can copy the screen of a separate window open in windows so that i may do something with it. is there any way to copy the screen from a window of another program onto an sdl_surface?? if not, there must at least be a way to print_screen (as when i press the keyboard button) onto an sdl_surface, right??

Sponsor:

#2 johnysums   Members   -  Reputation: 100

Like
0Likes
Like

Posted 18 October 2010 - 05:26 AM

sorry for bumping up my thread, but i really need to know the answer. Ive been doing some searching but i wasnt able to find anything, even in the Alternative Game Lib. section. any ideads ?

#3 SiCrane   Moderators   -  Reputation: 9498

Like
0Likes
Like

Posted 18 October 2010 - 05:36 AM

Do you mind using platform dependent code?

#4 johnysums   Members   -  Reputation: 100

Like
0Likes
Like

Posted 22 October 2010 - 02:15 AM

im only writing this for myself, so no i dont care.

#5 SiCrane   Moderators   -  Reputation: 9498

Like
0Likes
Like

Posted 22 October 2010 - 04:09 AM

The GDI code for creating a HBITMAP containing a screenshot of the desktop looks like this (error checking and resource deallocation code not shown):

HDC hdc = GetDC(NULL); // get the desktop device context
HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself

// get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);

// create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap( hdc, width, height);

// use the previously created device context with the bitmap
SelectObject(hDest, hbDesktop);

// copy from the desktop device context to the bitmap device context
BitBlt( hDest, 0,0, width, height, hdc, 0, 0, SRCCOPY);

Once you've got the info in an HBITMAP you've got a couple of options. The more efficient one is to use the HBITMAP to create an SDL_Surface. Do a search for "HBITMAP to SDL_Surface" to handle that. Or you can write the HBITMAP to a file and then use SDL to load the file. This is highly inefficient but generally requires less code to do if you use the right libraries. Do a search for "HBITMAP to file" or "HBITMAP to BMP" or whatever image format you want to use.

#6 johnysums   Members   -  Reputation: 100

Like
0Likes
Like

Posted 23 October 2010 - 12:04 AM

thanks, thats just what i was looking for. But i guess then there's no way to copy the screen of a separate window (and not just a print_screen of the whole display)? what im trying to do is tell which chess pieces moved in this separate program by taking an image of the program's window and checking the squares. print_screen would work if i keep my prog minimized but it would help if i could my program open on top of the other program and still be able to copy the screen of the window. my guess is there's some restriction on just copying any window open, correct??

#7 clashie   Validating   -  Reputation: 479

Like
0Likes
Like

Posted 23 October 2010 - 03:53 PM

Just use the HDC of the window you want instead of 0.

Also you could use a DIB Section instead and it will give you access to all the pixel data of what you just copied.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS