Getting Error "ChoosePixelFormat failed"

Hi all,

I m using Visual3d_View::Print function to print the view on CDC, i m getting "ChoosePixelFormat failed" error. Can anybody explain me, why?

Thanks in advance,

Ashesh

m-aronsson's picture

The ChoosePixelFormat function is used to select the context type to use for OpenGL, you have tried to select a pixelformat that is not supported, there can be many reason for this. do you have problems with other OpenGL applications ? if not then you have to poke around a little in your setup and try tofigure out what causes the problem.

Mikael

Ashesh Vashi's picture

Hi Mikael,

Thanks for your advice, i found that i was not passing the actual object of HDC ( Handle of Device Context, but was passing the CDC object, so it was giving me error at that time...) But it has been resolved but at the same time i m also getting the error with SetPixelFormat function just next call of that function. Because SetPixelFormat function allows only one time Pixel Formatting, it's returning error#1 ( which is Invalid Functino call in Windows). Still i m facing the problem in it.. If you can help me out, it will be gr8..

This is the some code from my application:

void MyAppView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
pInfo->SetMaxPage(1);
Invalidate(TRUE);

// Intially, I was using this code to get the picture of the View in a bitmap and
// print that bitmap in my code. But as it is taking snap of the view, I m not
// gettting the perfect result. But on some computer it's taking Snap of view,
// while on some, it's taking snap of whole Frame including ToolBar and MenuBar..
// So i decided to use print function of the OpenCascade
/*
Handle(Aspect_Window) anAspectWindow = myView->Window();
Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
HWND hWindow = (HWND)aWNTWindow->HWindow();
CBitmap mybitmap;

RECT r;
::GetClientRect(hWindow,&r);

int WindowWidth=r.right;
int WindowHeight=r.bottom;
HDC hDCWindow=::GetDC(hWindow);
CDC* dcWindow = CDC::FromHandle( hDCWindow);
m_CDC.CreateCompatibleDC( dcWindow);
mybitmap.CreateCompatibleBitmap(dcWindow,WindowWidth,WindowHeight);
m_CDC.SelectObject(&mybitmap);
dcWindow->SelectObject(CBitmap::FromHandle((HBITMAP)aWNTWindow->HPixmap()));
m_CDC.BitBlt( r.left, r.top,WindowWidth,WindowHeight,dcWindow,0,0,SRCCOPY);
::ReleaseDC(hWindow,hDCWindow);
*/

// m_CDC is a memeber variable of MyAppView - object of CDC
CRect r;
GetClientRect( &r);

m_CDC.CreateCompatibleDC( pDC);
CBitmap l_bitmap;

l_bitmap.CreateCompatibleBitmap( pDC, r.Width(), r.Height());
m_CDC.SelectObject( &l_bitmap);

// myView is object of V3d_View
myView->View()->Print( m_CDC.m_hDC, true, NULL);
}

void MyAppView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
m_CDC.DeleteDC();
}

void MyAppView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
ASSERT(pDC) ;
ASSERT(pInfo) ;
CRect l_Rect;
GetWindowRect( &l_Rect);

CRect& l_DrawRect = pInfo->m_rectDraw;
double l_Wratio = l_Rect.Width() / ( double) l_DrawRect.Width();
double l_Hratio = l_Rect.Height() / ( double) l_DrawRect.Height();

if( l_Wratio > l_Hratio )
pDC->StretchBlt(0, 0, l_DrawRect.Width(), (int)(l_Rect.Height() / l_Wratio), &m_CDC, 0, 0, l_Rect.Width(), l_Rect.Height(), SRCCOPY);
else
pDC->StretchBlt(0, 0, (int)( l_Rect.Width() / l_Hratio), l_DrawRect.Height(), &m_CDC, 0, 0, l_Rect.Width(), l_Rect.Height(), SRCCOPY);
}

Help me if you can..
Thank you for your reply...

Ashesh