Trying to show a picture in a CStatic control

  • Thread starter Thread starter sbrothy
  • Start date Start date
S

sbrothy

Guest
if (!MyLoadImage(CString("res/logo-large.png"), m_BmpLogo))
::PrintError(GetLastError(), _T("LoadImage: "));

CStatic *pCtrl = reinterpret_cast<CStatic *>(m_Dlg.GetDlgItem(IDC_STATIC_LOGO));
ASSERT(pCtrl);

//pCtrl->ModifyStyle(0, SS_BITMAP);
pCtrl->SetBitmap(m_BmpLogo);
pCtrl->ShowWindow(SW_SHOW);


m_BmpLogo is a member of the class to ensure it doesn't go out of scope. If I add the ModifyStyle line the outline of my control disappears completely but still noyjing is shown.

The MyLoadImageImage is defained as follows and should handle both png and jpg:


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LoadImage()
// Load png and jpeg at least....
BOOL MyLoadImage(CString path, CBitmap &b)
{
CImage image;
HRESULT hr = image.Load(path); // just change extension to load jpg
if (S_OK != hr)
{
PrintError(hr, _T("CImage::Load: "));
return FALSE;
}

HBITMAP hBitmap = NULL;
try
{
hBitmap = image.Detach();
}
catch (CException *e)
{
SYSError(_T("CImage::Detach: "));
// e->Dump(*new CDumpContext(NULL));
e->ReportError();
e->Delete();
return FALSE;
}
catch (...)
{
SYSError(_T("CImage::Detach: "), FALSE);
return FALSE;
}

if(!b.Attach(hBitmap))
{
SYSError(_T("Bitmap::Attach: "));
DeleteObject(hBitmap);

return FALSE;
}
ASSERT(hBitmap);

return TRUE;
}



No matter what I do nothing is shown. What am I doing wrong?


TIA,

Søren

Continue reading...
 
Back
Top