Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Getting screenshot of Windows?

This thread is locked; no one can reply to it. rss feed Print
Getting screenshot of Windows?
ITM
Member #798
November 2000
avatar

I'm just wondering whether getting a screenshot of Windows is possible or not... (I mean getting the result of the associated keyboard touch) And if so, in what way? Can I do that without creating a winallegro application?

deps
Member #3,858
September 2003
avatar

if you press printscreen, the screenshot is in the clipboard. just paste it.
And it is possible to create a winallegro application, there is code for it here somewhere, iirc.

---
Layers are good, all good things have layers, like onions. Good things also stink. - Trezker
I now have a page and a blog!

ITM
Member #798
November 2000
avatar

Sorry, it wasn't clear...
I want to get that from an allegro program :)

miran
Member #2,407
June 2002

Take a look at the source of that screen breaking game spellcaster made a while ago. It grabs a Windows screenshot and then it lets you destroy it with a multitude of fun weapons. I can't remember what it's called right now, just look at spell's profile...

--
sig used to be here

FMC
Member #4,431
March 2004
avatar

http://www.allegro.cc/depot/project.php?_id=861
is the project's page.

This is some relevant code that might help you:

1void grabDesktop() {
2 HWND hwnd;
3 HDC ddc;
4 RECT sz;
5 
6 hwnd = GetDesktopWindow();
7 ddc = GetDC(hwnd);
8 
9 GetWindowRect(hwnd, &sz);
10 
11 mdc = CreateCompatibleDC(ddc);
12 hbmp = CreateCompatibleBitmap(ddc, sz.right, sz.bottom);
13 SelectObject(mdc, hbmp);
14 BitBlt(mdc, 0, 0, sz.right, sz.bottom, ddc, 0, 0, SRCCOPY);
15 
16 
17 ReleaseDC(hwnd, ddc);
18}

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

ITM
Member #798
November 2000
avatar

Excellent, thanks a lot Mithrandir, I'm poor at windows programming :D
I'll check that as soon as possible once back at home !

FMC
Member #4,431
March 2004
avatar

Glad of having helped, but remember that the code is not of my creation, Spellcaster did it :P

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

spellcaster
Member #1,493
September 2001
avatar

Well, while that part grabs the dektop, you should check the complete startup code. The order of the grabbing and the install calls is important.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

ITM
Member #798
November 2000
avatar

Heh thanks a lot Spellcaster.. BTW, what's the command line that you use in order to compile it?

BAF
Member #2,981
December 2002
avatar

with allegro static. Or edit the .c file and remove the define ALLEGRO_STATICLINK

i did that, and it worked for me w/ gcc agression.c -o agression -lalleg -mwindows

btw-- it segfaults here on the bitblt. :( i wanted to beat up my desktop too.

ITM
Member #798
November 2000
avatar

I get weird errors like undefined reference to 'screen' or 'system_driver' if I add ALLEGRO_STATICLINK 1
Otherwise,it just crashes (4.1.15 WIP)

ReyBrujo
Moderator
January 2001
avatar

What is your full command line?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

ITM
Member #798
November 2000
avatar

Same as BAF's one

spellcaster
Member #1,493
September 2001
avatar

You have to link against the static version of allegro :)

Quote:

btw-- it segfaults here on the bitblt. i wanted to beat up my desktop too.

Download the precompiled version if you have problems compiling it.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

ReyBrujo
Moderator
January 2001
avatar

gcc agression.c -o agression -lalleg_s -mwindows for statically linked, yep.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

BAF
Member #2,981
December 2002
avatar

plus all the libs it needs. I just removed the static link and compiled with -lalleg. The precompiled one crashes too. (windows xp)

Go to: