Link to home
Start Free TrialLog in
Avatar of mjwilliamson
mjwilliamson

asked on

CStatic

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)

Avatar of mjwilliamson
mjwilliamson

ASKER

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
As you can see i've tried a couple of methods
neither work.

Someone must be able to answer this question. Surely!
ASKER CERTIFIED SOLUTION
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
Can't believe it!
Thanks :)