CStatic

mjwilliamson
mjwilliamson used Ask the Experts™
on
Hi i am trying to display a bitmap image on
a dialog using a static control. I have placed the
control on the dialog using the picture control, in
the properties it comes up as IDC_STATIC so i'm pressuming
so far so good?

When I go to the Class wizard i cannot see it, should
i be able to?

I have a bitmap resource named IDB_BITMAP1

i then have the following code in the OnInitDialog

CStatic pic;
     
pic.Create(_T("Hello"),WS_CHILD|WS_VISIBLE|SS_BITMAP, CRect (10,10,150,200), this, IDC_STATIC);
pic.SetBitmap(::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));


basically it no working :-(

Any help appreciated.

(p.s. i cant believe is so difficult to display
an image in a dialog - but i am new to C++ and MFC)

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
OK first problem solved, Dialog would not let me
add Static control that CW would recognise.

New Dialog, new Static control
IDC_STATIC_BMP

Control Type is Bitmap

In class wizard

IDC_STATIC_BMP maps to CStatic member variable
m_pic

I also have CBitmap variable m_bitmap
in dialog class.

If I set the image property and run app then
image is displayed. If I try to do it at runtime
I get nothing at all.

Code I'm using is below


BOOL CExlDlg::OnInitDialog()
{
     CDialog::OnInitDialog();
     
     // TODO: Add extra initialization here

     //
     m_bitmap.LoadBitmap(IDB_BITMAP2);

     //m_pic.Create(_T("Hello"),WS_CHILD|WS_VISIBLE|SS_BITMAP, CRect (10,10,150,200), this, IDC_STATIC_BMP);
     //m_pic.SetBitmap(::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BITMAP2)));
               
         
     

     HBITMAP hBitmap;
     hBitmap = m_bitmap;

     m_pic.SetBitmap(hBitmap);

     UpdateData(false);

     
     return TRUE;  // return TRUE unless you set the focus to a control
                   // EXCEPTION: OCX Property Pages should return FALSE
}

HEEEEEEEEEEEEEELLP!

Thanks

Author

Commented:
As you can see i've tried a couple of methods
neither work.

Someone must be able to answer this question. Surely!

  m_pic.SetBitmap ( LoadBitmap ( IDB_BITMAP2) );
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
I was using

CDialog(IDD_EXL_CHART).DoModal();

instead of

CExcel dlg;
dlg.DoModal();

when showing the Dialog

arrrrgh

I'll give you points seen as you answered!

Author

Commented:
Can't believe it!
Thanks :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial