I'm trying to capture screen and get it's BITMAP structure.
GetObject returns 0, indicating an error.
But GetLastError() is returning 0 as well.
This does not confirm with the API:
http://msdn.microsoft.com/en-us/library/ms929450.aspx
Any help is really appreciated.
Code:
void ScreenSnap::TakeScreenShot()
{
HWND hdesktopWnd = ::GetDesktopWindow();
VERIFY(hdesktopWnd);
RECT rectDesktop;
VERIFY(::GetWindowRect(hdesktopWnd, &rectDesktop));
HDC hDesktopDC = ::GetDC(hdesktopWnd);
VERIFY(hDesktopDC);
HBITMAP hDesktopBitmap = (HBITMAP)::GetCurrentObject(hDesktopDC, OBJ_BITMAP);
VERIFY(hDesktopBitmap);
BITMAP desktopBitmap;
if(!GetObject(hDesktopBitmap, sizeof(BITMAP), &desktopBitmap))
{
DWORD err = ::GetLastError(); // err value is 0 !
That link is for Windows CE. The docs for the regular Win32 version
of GetObject are here:
http://msdn.microsoft.com/en-us/library/dd144904.aspx
> GetObject returns 0, indicating an error.
> But GetLastError() is returning 0 as well.
The Win32 page doesn't mention anything about calling GetLastError, so
arguably the behavior you observed is in accordance with the API.
Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.
I usually tend to get stuck up, and there's nothing in docs that can
help me.
How do you usually approach such deadlocks?
On Sep 2, 1:41 am, Richard Russell <n...@rtrussell.co.uk> wrote:
> On Sep 2, 3:32 am, myprasanna <myprasa...@discussions.microsoft.com>
> wrote:
>
> > This does not confirm with the API:
> >http://msdn.microsoft.com/en-us/library/ms929450.aspx
>
> That link is for Windows CE. The docs for the regular Win32 version
> of GetObject are here:
>
> http://msdn.microsoft.com/en-us/library/dd144904.aspx
>
> > GetObject returns 0, indicating an error.
> > But GetLastError() is returning 0 as well.
>
> The Win32 page doesn't mention anything about calling GetLastError, so
> arguably the behavior you observed is in accordance with the API.
>
> Richard.http://www.rtrussell.co.uk/
> The Win32 page doesn't mention anything about calling GetLastError
It used to. For instance, in the Win32 .hlp file that shipped with BCB6:
"If the function fails, the return value is zero. To get extended error
information, call GetLastError."
--
Remy Lebeau (TeamB)
> BITMAP desktopBitmap;
> if(!GetObject(hDesktopBitmap, sizeof(BITMAP), &desktopBitmap))
> {
Does GetObject() still return 0 when you pass NULL as the last parameter?
If so, then hDesktopBitmap likely does not actually have a valid bitmap
selected into it at that time, even though GetCurrentObject() is apparently
returning one.
Instead of using GetCurrentObject() and GetObject(), you could alternatively
use CreateCompatibleDc(), CreateCompatibleBitmap(), SelectObject(), and
BitBlt() to copy the contents of hDesktopDC to your own bitmap instead.
--
Remy Lebeau (TeamB)
On Sep 2, 11:03 am, "Remy Lebeau" <no.s...@no.spam.com> wrote:
> "myprasanna" <myprasa...@discussions.microsoft.com> wrote in message
> Can we have a DC with no bitmap?
Not if you want to draw on the DC, no. The bitmap provides the physical
storage for the drawn pixel data.
--
Remy Lebeau (TeamB)
According to MSDN there are 4 types of GDI device contexts. The two of
interest to us are 'display' contexts and represent an area of display
memory, and 'memory' contexts that represent an area of memory called a
bitmap.
You cannot select an HBITMAP into a display DC, only a memory DC.
Basically, GetCurrentObject must be returning some kind of fake handle
from GetCurrentObject - the lie is revealed when you call GetObject with
that handle.
If you want a screenshot, you need to create a screen sized bitmap
yourself and BitBlt from the display to that.