Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

when the size of the web browser become bigger, hBmp and hBmp2 r

0 views
Skip to first unread message

Jakein2006

unread,
Dec 4, 2006, 3:30:00 AM12/4/06
to
I use the following code to copy the picture in the web browser to the
clipboard, when the size of the web browser is small my code run with no
problem, but when the size of the web browser become bigger, hBmp and hBmp2
return null, please tell me why and how to solve the problem.

I appreciate your help.


HDC hDCMem = CreateCompatibleDC(NULL);
HDC hDCMem2 = CreateCompatibleDC(NULL);

CRect rect;

::GetClientRect(hSrcWnd, &rect);
HBITMAP hBmp = NULL;
HBITMAP hBmp2 = NULL;

HDC hDC = ::GetDC(hSrcWnd);
hBmp = CreateCompatibleBitmap(hDC, rect.Width(), rect.Height());
hBmp2 = CreateCompatibleBitmap(hDC, rect.Width() - TOTAL_OFFSETX,
rect.Height() - TOTAL_OFFSETY);

HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
HGDIOBJ hOld2 = SelectObject(hDCMem2, hBmp2);
::SendMessage(hSrcWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN |
PRF_CLIENT | PRF_ERASEBKGND );
::BitBlt(hDCMem2, 0,0, rect.Width() - TOTAL_OFFSETX, rect.Height() -
TOTAL_OFFSETY, hDCMem, TOPLEFT_OFFSETX, TOPLEFT_OFFSETY, SRCCOPY);
::ReleaseDC(hSrcWnd, hDC);
SelectObject(hDCMem, hOld);
DeleteObject(hDCMem);
SelectObject(hDCMem2, hOld2);
DeleteObject(hDCMem2);

::OpenClipboard(hSrcWnd);

EmptyClipboard();
SetClipboardData(CF_BITMAP, hBmp2);
// SetClipboardData(CF_BITMAP, hBmp);
CloseClipboard();
--
jake

Igor Tandetnik

unread,
Dec 4, 2006, 8:32:07 AM12/4/06
to
"Jakein2006" <pen...@163.com> wrote in message
news:7233FBFC-623C-4C6D...@microsoft.com

>>> BitBlt(hDCMem2, 0,0, rect.Width() - TOTAL_OFFSETX, rect.Height() -
> TOTAL_OFFSETY, hDCMem, TOPLEFT_OFFSETX, TOPLEFT_OFFSETY, SRCCOPY);

What's the relationship between TOTAL_OFFSET[X,Y] and
TOPLEFT_OFFSET[X,Y] ?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Jakein2006

unread,
Dec 4, 2006, 8:49:00 AM12/4/06
to
I define them as follows:

#define TOPLEFT_OFFSETX 12
#define TOPLEFT_OFFSETY 17
#define TOTAL_OFFSETX 70
#define TOTAL_OFFSETY 70

#define WM_HTML_MESSAGE (WM_USER+100)

i appreciate your help.

--
jake

Igor Tandetnik

unread,
Dec 4, 2006, 8:54:03 AM12/4/06
to
> I use the following code to copy the picture in the web browser to the
> clipboard, when the size of the web browser is small my code run with
> no problem, but when the size of the web browser become bigger,
> hBmp and hBmp2 return null

Do you mean CreateCompatibleBitmap returns NULL? What does GetLastError
return right after the call fails?

When you say "bigger", exactly how big? What size is the rectangle when
the call begins to fail?

Jakein2006

unread,
Dec 4, 2006, 7:15:00 PM12/4/06
to
Hi, when I use GetLastError(), the error code is 8(no enough storage memory),
the rect size is 2000*2000,

so please help me figure out how to solve this problem, how to copy the
image into clipboard?

I appreciate your help.
--
jake

Igor Tandetnik

unread,
Dec 4, 2006, 8:56:16 PM12/4/06
to
"Jakein2006" <pen...@163.com> wrote in message
news:FFB1400D-24F4-4FC2...@microsoft.com

> Hi, when I use GetLastError(), the error code is 8(no enough storage
> memory), the rect size is 2000*2000,

Try creating a DIB with CreateDIBSection, rather than a DDB with
CreateCompatibleBitmap. I seem to remember there are limits on how large
a DDB can be.

Jakein2006

unread,
Dec 4, 2006, 9:59:00 PM12/4/06
to
I hope that one expert can give me one example of how to creating a DIB with
CreateDIBSection.

I appreciate your help.
--
jake

Igor Tandetnik

unread,
Dec 4, 2006, 10:04:58 PM12/4/06
to
"Jakein2006" <pen...@163.com> wrote in message
news:080753BF-88E5-4A5E...@microsoft.com

> I hope that one expert can give me one example of how to creating a
> DIB with CreateDIBSection.

I assume you have studied the documentation for this function, and found
it lacking. Do you have any specific issue that the documentation failed
to clarify for you?

0 new messages