|
Thanks. I think I found the little beast.
|
|
|
|
|
Hello,
I'd like to know the simplest way by which I can capture the entire screen [I dont want that method where we send a Print-Screen-Key and get it in the clipboard]
Can someone give me some elementary steps. Code not needed unless necessary.
Something like
1. get the DC
2. stretch blt it or whatever
3. now get some oher dc
etc...
My GDI sucks! So pardon the absolute stupidity that this post might seem to reflect in the above 3 lines
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
I haven't tried this, so it may not work, but it sounds plausible :
Get the screen DC ( ::GetDC(NULL) )
Get the size of the screen ( ::GetDeviceCaps(HORZRES); ::GetDeviceCaps(VERTRES); )
Create a compatible memory DC (i'm tired of typing <code> and you said it wasn't required )
Create a compatible bitmap of the same size
Select the bitmap in the memory DC
Blit from the screen DC to the memory DC
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|
|
I did this as a demo for one of the chapters in my MFC book. If you want I'll send you the source code.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Thanks Tom. I'd love it if you could mail it to me
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Actually, I'll post the salient code here and mail the entire project to you.
By the way, in case you're wondering why the code is so bunched up, the <pre> tags are screwed up in the forums and don't show the blank lines in the code as they should be rendered.
- In an SDI app, I defined the following global variable in the view class:
CDC* g_pMemoryDC = NULL;
- In a menu handler for screen capture I added the following code. Note that the hiding of the window and sleeping are done just to get the app out of the way so that I can capture the desktop without my app.
if (g_pMemoryDC)
{
delete g_pMemoryDC;
g_pMemoryDC = NULL;
}
g_pMemoryDC = new CDC();
GetParentFrame()->ShowWindow(SW_HIDE);
Sleep(1000);
CDC screenDC;
screenDC.CreateDC("DISPLAY", NULL, NULL, NULL);
int nHeight = screenDC.GetDeviceCaps(HORZRES);
int nWidth = screenDC.GetDeviceCaps(VERTRES);
CBitmap bitmap;
g_pMemoryDC->CreateCompatibleDC(&screenDC);
bitmap.CreateCompatibleBitmap(&screenDC, nWidth, nHeight);
g_pMemoryDC->SelectObject(&bitmap);
g_pMemoryDC->BitBlt(0, 0, nWidth, nHeight, &screenDC, 0, 0, SRCCOPY);
GetParentFrame()->ShowWindow(SW_SHOW);
Invalidate();
- In the OnDraw, I add the following.
if (g_pMemoryDC)
{
CClientDC clientDC(this);
int nWidth = g_pMemoryDC->GetDeviceCaps(HORZRES);
int nHeight = g_pMemoryDC->GetDeviceCaps(VERTRES);
clientDC.BitBlt(0, 0, nWidth, nHeight, g_pMemoryDC, 0, 0, SRCCOPY);
}
That's all there is to it!
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
That's all there is to it!
Thanks a LOT Tom. Now I understand why you are a successful author. Cause you write readable code. Of all the various examples I saw on the net, this one is the clearest and simplest.
Thanks again
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
No problem, Nish. Thanks for the kinds words.
I'm actually working on my demo now and sent you the bare bones bit you needed. When I get finished it will have a capture settings dialog for things like countdown interval in seconds and let you specify if you want the app to beep during the countdown. I'll also include my ImageObject library so that the image can then be saved to JPG or GIF format once captured. It won't be a terribly fancy app, but a neat little demo nonetheless.
Let me know if you're interested and I'll send it to you Monday.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom, do you have a sample that (optionally) includes the mouse cursor in the capture? I expect this would be done by BitBlt'ing the image of the cursor at the appropriate location.
Btw, would it be possible to post your demo at CP? I'm sure a lot of folks (me included) would love to see it!
Thanks!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Ravi Bhavnani wrote:
Tom, do you have a sample that (optionally) includes the mouse cursor in the capture? I expect this would be done by BitBlt'ing the image of the cursor at the appropriate location
Ravi, d you mind me asking why you want this - I'll explain why I'm asking after you respond
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Oh I just thought it would be cool to see the source behind this. Most commercial screen snaggers offer this feature, but I haven't seen any source code examples.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
The reason I ask is that I've recently discovered a major problem with other screen capture programs regarding screen figures in my book. In one of my mouse demos, the client area is divided into the number of areas representing the number of system-available mouse cursor shapes. When the user "mouses over" a given area, the cursor changes into that particular cursor and the text in the client area indicates the current cursor.
However, when I tried to take a screen shot of my application, the screen capture utilities always changes the current cursor to the default cursor! The problem with this is that on my figure, the client area text states one thing and the actual cursor is another. Therefore, as I'm writing this screen capture demo (for the GDI/bitmap chapter), I'm wondering if I'll be able to capture what the cursor truly is. I'm hoping that it's simply an oversight of many screen capture writers and that they just didn't, or care, about this anomoly.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Aha!
Perhaps simple-minded screen capture apps bitblt the cursor obtained from LoadOEMCursor() instead of using GetCursorInfo() . Methinks the latter should return the right cursor, but I haven't tried it.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
That's definitely what I'm hoping.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Ravi Bhavnani wrote:
Btw, would it be possible to post your demo at CP? I'm sure a lot of folks (me included) would love to see it!
Sure. I didn't think too many people would care for it since it's so specific to a given usage of GDI. However, when I finish, I'll definitely post it.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Thanks!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks for the reply, but I don't think this solves my problem. After capturing the screen, I need access to the image data in order to do some processing, and GetDIBits is far too slow. I need to capture the screen into a buffer which I can access, and all this needs to be done as quickly as possible. Any other suggestions? Thanks!
By the way, blt'ing into a DC with a DIBSection is equally slow. I suspect it internally calls GetDIBits.
|
|
|
|
|
Oops! I responded into the wrong thread. Sorry for any confusion caused.
|
|
|
|
|
hello
i was wondering what was wrong with the following code:
lr = strlen(menu);
lr is an intiger,... the reason i want to use strlen is because:
my program accepts a letter for you to tell the computer what you want... when you put in more than one character into the cin << menu, the program breaks down and goes non-stop through the main loop.
thanks for your help!
~SilverShalkin
|
|
|
|
|
The problem is you should be using C++ instead of C. Make menu a std::string and use menu.length() to find out how big it is.
Otherwise, if menu is a char array, try strlen(&menu[0]); It's probably something like that, but I'm not sure - I don't program much C.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
The problem is you should be using C++ instead of C. Make menu a std::string and use menu.length() to find out how big it is.
Hmmm, not everyone want to use STD, I don't like it and try to avoid it when I can. And depending on what you are programming it's not always a good idea. I spend a lot of my time programming server applications where I need all the speed I can get, and a std::string is way slower than a char array
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders Molin wrote:
Hmmm, not everyone want to use STD, I don't like it and try to avoid it when I can.
Why don't you like it ?
Anders Molin wrote:
depending on what you are programming it's not always a good idea.
I have no doubt, but while that may be the case, overall, too many people use clunky C style strings and so on IMO. They are not safe, they are hard to use, but yes, they are faster in some instances. My main beef is that Universities do not teach C++, they teach C with classes.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
Why don't you like it ?
Hmmm, I think most of STL makes things hard to use, yes, I really do...
The strings are slow, the documentation sucks, and I don't like the way you use it...
Christian Graus wrote:
I have no doubt, but while that may be the case, overall, too many people use clunky C style strings and so on IMO. They are not safe, they are hard to use, but yes, they are faster in some instances.
Well, C strings are not that hard to use, sure, there's a lot more that can go wrong, but there's also lot's of bennefits
Christian Graus wrote:
My main beef is that Universities do not teach C++, they teach C with classes.
I don't know about what they teaches, but I'll agree with you on that one
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders Molin wrote:
Hmmm, I think most of STL makes things hard to use, yes, I really do...
The strings are slow, the documentation sucks, and I don't like the way you use it...
I dunno about the string speed, I've never had to stress it. Beyond that, the docs in MSDN suck for a reason, but there are plenty of good books out there, and std::string is a long way from being a central feature. What do you use for containers then ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|