Troudeloup
asked on
how do I feed hwnd to screencapture?
this is by using windows sdk and I am calling its functions and objects.
I have my handle from this line
HWND hwnd = FindWindow(NULL,"Notepad") ;
how do I feed it to this function?
note that this function is from a demonstration of how to capture screen.
Void CaptureScreen()
{
int nScreenWidth = GetSystemMetrics(SM_CXSCRE EN);
int nScreenHeight = GetSystemMetrics(SM_CYSCRE EN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDeskto pDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hD esktopDC,
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hC aptureBitm ap);
BitBlt(hCaptureDC,0,0,nScr eenWidth,n ScreenHeig ht,
hDesktopDC,0,0,SRCCOPY|CAP TUREBLT);
SaveCapturedBitmap(hCaptur eBitmap); //Place holder - Put your code
//here to save the captured image to disk
ReleaseDC(hDesktopWnd,hDes ktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitma p);
}
and then eventually I want to use this function to get pixel color data in RGB form, how do I feed hdc from above to this function?
COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
what does this function return?
thanks for reading
I have my handle from this line
HWND hwnd = FindWindow(NULL,"Notepad")
how do I feed it to this function?
note that this function is from a demonstration of how to capture screen.
Void CaptureScreen()
{
int nScreenWidth = GetSystemMetrics(SM_CXSCRE
int nScreenHeight = GetSystemMetrics(SM_CYSCRE
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDeskto
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hD
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hC
BitBlt(hCaptureDC,0,0,nScr
hDesktopDC,0,0,SRCCOPY|CAP
SaveCapturedBitmap(hCaptur
//here to save the captured image to disk
ReleaseDC(hDesktopWnd,hDes
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitma
}
and then eventually I want to use this function to get pixel color data in RGB form, how do I feed hdc from above to this function?
COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
what does this function return?
thanks for reading
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
in your code example,
return hBitmap
is this what I feed to getpixel?
return hBitmap
is this what I feed to getpixel?
ASKER
a problem, I don't get your code is doing.
BitBlt(hCaptureDC,0,0,nScr eenWidth,n ScreenHeig ht,
hDesktopDC,0,0,SRCCOPY|CAP TUREBLT);
where is the equivalent of this one?
BitBlt(hCaptureDC,0,0,nScr
hDesktopDC,0,0,SRCCOPY|CAP
where is the equivalent of this one?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
void CaptureWindow(HWND hWnd) // maybe I need to split this into 3 functions
// see below
{
RECT rect;
if (!GetWindowRect(hWnd, &rect))
return NULL;
HDC hWindowDC = ::GetDC(hWnd);
if (!hWindowDC)
return NULL;
HDC hCaptureDC = CreateCompatibleDC(hWindow DC);
if (!hCaptureDC)
return NULL;
HBITMAP hBitmap = CreateCompatibleBitmap(hWi ndowDC, rect.right-rect.left+1, rect.top-rect.bottom+1));
if (!hBitmap) {
DeleteDC(hCaptureDC);
return NULL;
}
HBITMAP oldBmp = (HBITMAP)SelectObject(hCap tureDC, hBitmap);
int result = PrintWindow(hWnd, hCaptureDC, 0);
// does it help speed to keep the same DC and then reuse it by capturing onto it?
// if it helps, i would do
//
// // a function to create a empty DC, return it
// // capture onto this DC, return it
// // finishe with the DC, run below
// // to use this DC, see bottom
// cleaning tasks before returning
SelectObject(hCaptureDC, oldBmp);
DeleteDC(hCaptureDC);
DeleteObject(hBitmap);
}
// you can use getpixel right here, passing hCaptureDC
//I need to access a lot of points with a function like this
//so I need to return hCaptureDC from above function somehow
getpixel ( ?type, hCaptureDC, x, y)
{
// place holder
return color;
}
does this make sense?
// see below
{
RECT rect;
if (!GetWindowRect(hWnd, &rect))
return NULL;
HDC hWindowDC = ::GetDC(hWnd);
if (!hWindowDC)
return NULL;
HDC hCaptureDC = CreateCompatibleDC(hWindow
if (!hCaptureDC)
return NULL;
HBITMAP hBitmap = CreateCompatibleBitmap(hWi
if (!hBitmap) {
DeleteDC(hCaptureDC);
return NULL;
}
HBITMAP oldBmp = (HBITMAP)SelectObject(hCap
int result = PrintWindow(hWnd, hCaptureDC, 0);
// does it help speed to keep the same DC and then reuse it by capturing onto it?
// if it helps, i would do
//
// // a function to create a empty DC, return it
// // capture onto this DC, return it
// // finishe with the DC, run below
// // to use this DC, see bottom
// cleaning tasks before returning
SelectObject(hCaptureDC, oldBmp);
DeleteDC(hCaptureDC);
DeleteObject(hBitmap);
}
// you can use getpixel right here, passing hCaptureDC
//I need to access a lot of points with a function like this
//so I need to return hCaptureDC from above function somehow
getpixel ( ?type, hCaptureDC, x, y)
{
// place holder
return color;
}
does this make sense?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yeah that's one i planned to use.
would it help it to run faster if I keep the same dc?
would it help it to run faster if I keep the same dc?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how about doing this in 3 functions?
1st to return dc with capture on it
2nd given dc return getpixel
3rd release dc.
1st to return dc with capture on it
2nd given dc return getpixel
3rd release dc.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i am, not sure how to do it, you mean
HDC hWindowDC = ::GetDC(hWnd);
byte bytecolor = getpixel ( hWindowDC, x, y );
?
HDC hWindowDC = ::GetDC(hWnd);
byte bytecolor = getpixel ( hWindowDC, x, y );
?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that't ALL I need ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HDC hWindowDC = ::GetDC(hWnd);
(?) COLORREF GetPixel( HDC hWindowDC, int x, int y );
I have problem with the (?) part.
I didn't get the type of variable I need to store the values
also, how do I convert those values into
int red
int green
int blue
?
(?) COLORREF GetPixel( HDC hWindowDC, int x, int y );
I have problem with the (?) part.
I didn't get the type of variable I need to store the values
also, how do I convert those values into
int red
int green
int blue
?
ASKER
oh party begins with that :p
ASKER
https://www.experts-exchange.com/questions/22983831/how-do-I-save-a-screen-shot.html
please take a look of this.
please take a look of this.
ASKER
{
int nScreenWidth = GetSystemMetrics(SM_CXSCRE
int nScreenHeight = GetSystemMetrics(SM_CYSCRE
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDeskto
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hD
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hC
// I run this to prepare to capture screen, and after this I can run
// I run this to capture. but I can't make it out the part to pass it to the getpixel function
BitBlt(hCaptureDC,0,0,nScr
hDesktopDC,0,0,SRCCOPY|CAP
SaveCapturedBitmap(hCaptur
//Place holder - Put your code
//here to save the captured image to disk
// what does this do?
ReleaseDC(hDesktopWnd,hDes
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitma
// I run these 3 only when I am done capturing right?
}