Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I work with vs2013 + OpenGL.
The program is a MFC dialog project. In the main dialog, a custom control and a copy button are laid. When this program is executed, a graph is drawn with OpenGL in the custom control. When the copy button is clicked, the graph is copied into the clipbord in bmp format.
In the past, my computer was 32-bit with the OS of win7, and this program can run successfully. However, when the same program runs on the new computer with 64-bit and win10, the function of copy cannot work.
Following is the main code, in which CGraphCtrl and CUsingGlut32Dlg are the classes corresponding to the custom control and main dialog respectively.
C++
void CGraphCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting

//Draw a rectangle and "X" in it with MFC
CRect rc;
GetClientRect(&rc);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(&rc);
dc.MoveTo(0, 0);
dc.LineTo(rc.right, rc.bottom);
dc.MoveTo(rc.right, 0);
dc.LineTo(0, rc.bottom);

//draw red cube with OpenGL
if (!wglMakeCurrent(m_hDC, m_hRC))
{
CString msg= _T("wglMakeCurrent err");
AfxMessageBox(msg);
}
DrawGraph(); //draw a red cube
SwapBuffers(m_hDC);
wglMakeCurrent(m_hDC, NULL);
}


void CGraphCtrl::CopyBmpToClipBoard(HBITMAP hBitmap)
{
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
}

void CUsingGlut32Dlg::OnBnClickedButtonCopy()
{
//m_GraphCtrl.WriteBmpToFile(hBitmap, _T("WriteBmpToFile.bmp"));
HBITMAP hBitmap = m_GraphCtrl.GetBmpHandle();
m_GraphCtrl.CopyBmpToClipBoard(hBitmap);
}

The HGLRC of OpenGL is created with PFD_DOUBLEBUFFER, which means the OpenGL graph is drawn with double buffers.
When this program run on the 32-bit computer with win7, the OpenGL graph can be copied successfully, but will fail on the 64-bit computer with win10.

What I have tried:

the OpenGL graph can be copied sussfully on 32-bit computer with OS of win7
Posted
Updated 28-May-16 7:24am
v2
Comments
Richard MacCutchan 28-May-16 10:52am    
You are falling into the trap that seems all too common among modern developers, of assuming that all calls to Windows API (and some other) functions always succeed. Check the result of the call to SetClipboardData to see whether it succeeded or not.
KarstenK 28-May-16 13:27pm    
Run it as 32-bit process on Windows 10 to check whether it is a 32/64 bit problem or Windows 10 issue. May some of your input data is invalid for 64 bit.

Are you using some lib for OpenGL? Maybe it isnt the 64 bit version linked in...
Member 12549784 30-May-16 2:54am    
thanks to Richard and Karstenk for my question.
I find that the copy will success when the HGLRC OF OpenGL is initialized with PFD_SUPPORT_GDI instead of PFD_DOUBLEBUFFER. That means the OpenGL graph is drawn with single buffers. So is it the SwapBuffers(m_hDC) that calls the problem?
KarstenK 30-May-16 4:30am    
MS writes that you cant use you BOTH flags at the time.
Member 12549784 2-Jun-16 5:18am    
I do not use them at the same time. I means that the results should be same when either PFD_SUPPORT_GDI or PFD_DOUBLEBUFFER is used. However, the results are not.
Following is the new test code, in which, when m_GDI is true, the OpenGL is initialized with PFD_SUPPORT_GDI, otherwise, it is initialized with PFD_DOUBLEBUFFER. If this program is run on 64-bit computer, it will disply a cube with a transparent or non-transparent rectangle on it when m_GDI is true or false, respectively.

void CGraphCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting

if (m_GDI)
{
InitOpenGL1(dc.m_hDC); // Init OpenGL using PDF_SUPPORT_GDI
m_hRC = wglCreateContext(dc.m_hDC);
wglMakeCurrent(dc.m_hDC, m_hRC);

DrawGraph(); // draw a red cube with OpenGL
glFlush();
//SwapBuffers(dc.m_hDC);

wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hRC);
}
else
{
InitOpenGL2(dc.m_hDC); // Init OpenGL using PDF_DOUBLEBUFFER
m_hRC = wglCreateContext(dc.m_hDC);
wglMakeCurrent(dc.m_hDC, m_hRC);

DrawGraph(); // draw a red cube with OpenGL
//glFlush();
SwapBuffers(dc.m_hDC);

wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hRC);
}

//Draw a rectangle with MFC
CRect rc;
GetClientRect(&rc);
rc.InflateRect(-rc.Width() / 4, -rc.Height() / 4);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(&rc);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900