PDA

View Full Version : OpenGL to bitmap not working on Windows 10



Dilworth
01-06-2016, 11:33 AM
My code captures a window to the Clipboard as a bmp that I can paste into many other programs. This works fine if the window has only simple graphics, but for an OpenGL window, when I paste the bmp all I get is an empty frame when running Windows 10.

The problem did not show up under Windows XP and 7, so it looks like a W10 problem. Here is the code I use to do the capture:

void CmyOGLView::makeBitMap()
{
CBitmap BitmapClip; // taken from Young, page 1105
CClientDC ClientDC (this);
CDC MemDC;
RECT Rect;

GetClientRect( &Rect );
BitmapClip.CreateCompatibleBitmap
( &ClientDC,
Rect.right - Rect.left,
Rect.bottom - Rect.top);
MemDC.CreateCompatibleDC( &ClientDC );
MemDC.SelectObject( &BitmapClip );

MemDC.BitBlt
(0,
0,
Rect.right - Rect.left,
Rect.bottom - Rect.top,
&ClientDC,
0,
0,
SRCCOPY );

::CloseClipboard();
if ( !OpenClipboard() )
return;

HANDLE WH;
BOOL WB;

WB = ::EmptyClipboard();
WH = ::SetClipboardData( CF_BITMAP, BitmapClip.m_hObject );
BitmapClip.Detach();
::CloseClipboard();
}

Can anyone figure out why the bitmap is not captured in W10? The return values of WH and WB look fine.

mhagain
01-06-2016, 12:05 PM
Was the DWM disabled on the Windows 7 machine it worked on? This may be a DWM problem rather than a Windows 10 problem, and if so, it would also be expected to fail on 8 and 8.1 as they also no longer allow the DWM to be disabled.

Dilworth
01-06-2016, 02:11 PM
Was the DWM disabled on the Windows 7 machine it worked on? This may be a DWM problem rather than a Windows 10 problem, and if so, it would also be expected to fail on 8 and 8.1 as they also no longer allow the DWM to be disabled.

I never touched DWM, so I can't say. It worked on every W7 machine out there, though, and also on XP. What's weird is that the same code can save ordinary graphics windows bitmaps just fine. But not from an OpenGL window. Is there any plausible reason for that?

How can I test W10 for a DWM problem?

mhagain
01-07-2016, 02:57 AM
What's weird is that the same code can save ordinary graphics windows bitmaps just fine. But not from an OpenGL window. Is there any plausible reason for that?

Because OpenGL isn't ordinary graphics.

Seriously - do you have access to a Windows 7 machine you can test on? I don't mean a VM, I mean an actual physical Windows 7 machine.

Dilworth
01-07-2016, 06:51 AM
Yes, I have tested the same program, same version, on a native W7 PC, and the bitmap copy and paste work perfectly.