Click to See Complete Forum and Search --> : Capture #2 -
.pcbrainbuster
November 22nd, 2007, 02:31 PM
Sup dudes,
Now that I'm working on a DC that's on a static control I need to know how to capture the whole screen qand blit it to the screen and also scale it down to the size of my control.
Thanks.
LoKi_79
November 22nd, 2007, 04:08 PM
Sup dudes,
Now that I'm working on a DC that's on a static control I need to know how to capture the whole screen qand blit it to the screen and also scale it down to the size of my control.
Thanks.
you just get the screen DC and use StretchBlt instead of BitBlt.
but why do you want the whole screen? do you want a bitmap of the desktop?
http://msdn2.microsoft.com/en-US/library/ms532314.aspx
.pcbrainbuster
November 22nd, 2007, 04:25 PM
I already know that I need StretchBlt but don't know how to set it up exactly. Also how do you get a 'screenshot' of a specific window and not the whole screen? Finally, is there any difference between using CreateDC("Display", NULL, NULL, NULL) and GetWindowDC(NULL)?
Thanks.
LoKi_79
November 22nd, 2007, 04:40 PM
Also how do you get a 'screenshot' of a specific window and not the whole screen? just use the window handle that you want instead of display or null.
Finally, is there any difference between using CreateDC("Display", NULL, NULL, NULL) and GetWindowDC(NULL)? CreateDC() makes a new DC based on the parmeters - you have to destroy it again using DeleteDC().
GetWindowDC() gets the existing DC that came with the window when it was created and you have to ReleaseDC() it when you are done so other processes can use it.
.pcbrainbuster
November 22nd, 2007, 05:04 PM
Well here's my try at it but only part of the screen seems to show up in the control -
i would guess that your TempPoint.x and TempPoint.y are not your destination origin?
BOOL StretchBlt(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
DWORD dwRop // raster operation code
);
LoKi_79
November 22nd, 2007, 06:10 PM
BTW I tried to supply a handle but my compiler said there was another problem, it said you need to use a type const char *.
Any ideas?
Thanks.
cast it explicitly, so if the function wants an HDC then use (HDC)myHDC?
.pcbrainbuster
November 22nd, 2007, 06:13 PM
Ahh I see, by the way TempPoint is the correct placement. Have a look at my BitBlt from my WM_PAINT message, tell me if its wrong -
what is your TempPoint? that seems like the reason you are not getting the whole image.
unless PS.rcPaint.left == PS.rcPaint.top == 0, then your widths and heights would be wrong.
LoKi_79
November 22nd, 2007, 06:30 PM
Sure, here you go - MainDC = CreateDC(hWnd, NULL, NULL, NULL);
Thanks.
HDC CreateDC(
LPCTSTR lpszDriver, // driver name
LPCTSTR lpszDevice, // device name
LPCTSTR lpszOutput, // not used; should be NULL
CONST DEVMODE* lpInitData // optional printer data
);
the first argument has to be a (pointer to a) string, not a HWND.
you want GetWindowDC(hWnd) and then CreateCompatibleDC if you want your own one before you release the original.
Marc G
November 23rd, 2007, 04:28 AM
Try PrintWindow (http://msdn2.microsoft.com/en-us/library/ms535695.aspx) to get a screenshot of a window because if you use the blit method the window that you want to capture has to be visible on the screen.
.pcbrainbuster
November 23rd, 2007, 04:49 AM
Marc G: My compiler doesn't seem to support that function :(
Loki79: I tried but nothing changed, also in my WM_LBUTTONDOWN message TempPoint is the coordinates of the MDC relative to the my program's client area, if I don't use it then there is a offset problem with the MDC as well as the TDC, currently I have a issue with the TDC.
Now that you know this please review the code by me above(for the capture).
May I just ask how many years/months you have of experience(Marc G and Loki79)?
Thanks.
LoKi_79
November 23rd, 2007, 06:28 AM
in my WM_LBUTTONDOWN message TempPoint is the coordinates of the MDC relative to the my program's client area, if I don't use it then there is a offset problem with the MDC as well as the TDC, currently I have a issue with the TDC.
Now that you know this please review the code by me above(for the capture).
can you post a screen shot? is the offset always the same? and is it similar magnitude to your TempPoint? it seems like you are making hard work for yourself - if you line everything up in the first place there would not be an offset??
May I just ask how many years/months you have of experience(Marc G and Loki79)?
i've only been using WinAPI since january this year. i'm technicaly a physicist and used to do everything in console apps before.
Marc G
November 23rd, 2007, 07:43 AM
Marc G: My compiler doesn't seem to support that function :(It's not compiler related. Try to download the latest platform SDK from MS.
May I just ask how many years/months you have of experience(Marc G and Loki79)?15 years or something programming expierence.
.pcbrainbuster
November 23rd, 2007, 08:05 AM
Well I'm not sure that a screenshot will even show what is wrong because the TDC flashes because I still haven't figured out how to double buffer :( Please point me to a link as I think I may understand it, this time... :)
This time may I ask your age? BTW, I started with C++ in July :)
Thanks.
Marc G
November 23rd, 2007, 08:38 AM
29
LoKi_79
November 23rd, 2007, 09:30 AM
Well I'm not sure that a screenshot will even show what is wrong because the TDC flashes because I still haven't figured out how to double buffer :( Please point me to a link as I think I may understand it, this time... :) you mean a link about double buffering? there are loads of links and examples in your thread on screen flickering.
This time may I ask your age? BTW, I started with C++ in July :) you should be able to work it out from the name, i was born in 1979 ;) (it is 28)
i would look carefully at the code Marc has posted in the other thread. start with a blank project and copy things over making sure you understand each step. try to get it working without the dragging things first (as that is 50% of the code), and then add it in later.
i don't think you will find more specific advice than that code?
.pcbrainbuster
November 23rd, 2007, 09:37 AM
The problem is not the dragging, its the whole offset issue, try basing your DC on a static control then try to draw on it, your temporary lines will be all over the place(exaggeration).
Thanks.
LoKi_79
November 23rd, 2007, 10:08 AM
The problem is not the dragging, its the whole offset issue, try basing your DC on a static control then try to draw on it, your temporary lines will be all over the place(exaggeration).
Thanks.
i'll have a go tonight - but i think you are trying to use a static control for a purpose that it was not intended to be used for...
what you could do is create a proper child window instead of your static control (which will handle all your messages etc..) and then create a static control inside that which will display your bitmap without needing to do any other jobs.
.pcbrainbuster
November 23rd, 2007, 10:19 AM
I'm quite confused, but I'll wait :) And thanks :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.