Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading a Bitmap from Clipboard

Started by rtr1129 Nov 18, 2000 at 12:07 AM 0 replies 600+ views
Original Post
rtr1129
rtr1129
Ok, here''s my code.
  
void UpdateDisplay(HWND hwnd)
{
	HBITMAP hbm = (HBITMAP)GetClipboardData(CF_BITMAP);
	HDC source, dest;
	RECT rect;

	GetClientRect(hwnd, ▭);
	
	dest = GetDC(hwnd);
	source = CreateCompatibleDC(0);
	SelectObject(source,hbm);
	BitBlt(dest,0,0,rect.right, rect.bottom, source,0,0,SRCCOPY);
	DeleteDC(source);
	DeleteObject(hbm);
	ReleaseDC(hwnd,dest);
}
  
I get nothing but a black screen. Earlier in my program I generated a button press of the PRINT SCREEN key to put something in the clipboard, and I verified that after I ran my program it did in fact copy the screen to the clipboard. I also verified that there is in fact a bitmap of the type CF_BITMAP in the clipboard using the IsClipboardFormatAvailable(CF_BITMAP) function. So as far as I can tell, I have a valid handle to a bitmap. Any ideas?
Gladiator
Gladiator
Here is some code that should work for you:

  
void UpdateDisplay( HWND hwnd )
{
BITMAP bmp_info;
HBITMAP hBmp,
hOldBmp;
HDC hDC,
hMemDC;

//

// Is there a bitmap in the clipboard?

//

if ( IsClipboardFormatAvailable( CF_BITMAP ) != FALSE )
{
//

// If so, open the clipboard and get the bitmap

//

OpenClipboard( hwnd );

hBmp = (HBITMAP) GetClipboardData( CF_BITMAP );

//

// Create a memory DC for the bitmap

//

hDC = GetDC( hwnd );
hMemDC = CreateCompatibleDC( 0 );
hOldBmp = (HBITMAP) SelectObject( hMemDC, hBmp );

//

// Get information about the bitmap. We need the width and height to blit it

//

GetObject( hBmp, sizeof( BITMAP ), &bmp_info );

//

// Copy the memory DC to the screen DC

//

BitBlt( hDC, 0, 0, bmp_info.bmWidth, bmp_info.bmHeight, hMemDC, 0, 0, SRCCOPY );

//

// Dispose of anything we don't need

//

SelectObject(hMemDC, hOldBmp );
DeleteDC( hMemDC );
ReleaseDC( hwnd, hDC );

//

// Finally close the clipboard, and allow other applications to use it

//

CloseClipboard( );
}
}


Hope this helps!

-------------------------------
"Mind your own damn business!!!" - Gladiator

..-=gLaDiAtOr=-..

Edited by - Gladiator on November 19, 2000 11:14:41 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.