Link to home
Start Free TrialLog in
Avatar of shakir77
shakir77

asked on

Unable to view Image in picture control

I am trying to load picture in picture control .
But it On running application No image is seen in the Picture control...it shows blank.

Code i have written in InitDialog is:

CBitmap m_bmp;
VERIFY(m_bmp.LoadBitmap(IDB_PICTURE));
m_pictureToShow.SetBitmap(m_bmp);
m_pictureToShow.UpdateWindow();

where m_pictureToShow is CStatic defined thru Control Window.


for debugging i just changed to
if( m_pictureToShow.SetBitmap(m_bmp) == NULL)
    AfxMessageBox("SetBitMap failed");

& it is showing SetBitMap is returning NULL.
can u pls point out what exactly the problem is ...
or am i doing something wrong .????
Avatar of AlexFM
AlexFM

Picture control should have SS_BITMAP style. In the dialog resource editor right-click picture control and select Bitmap type.
Avatar of shakir77

ASKER

picture control Type is already set to BitMap.
Still not showing..??????? any reason.
SetBitmap function is defined as:
HBITMAP SetBitmap( HBITMAP hBitmap );

So you need:
m_pictureToShow.SetBitmap((HBITMAP)m_bmp.m_hObject);


Hi Shakir77,
Try this.

Add a bitmap in your workspace. Now select the picture control that you have added on the dialog. now go to the property of the picture control, Select Type: as Bitmap, and select the "Image: BITMAP_ID ". This image is the id of the Bitmap that is there in your resource. now close the proerty dialog and you will see the bitmap.

Try it, All the best
Thanks and Regards.
Zfact
hi zfact
I cannot set Image value to BITMAP_ID as this ID will be decided on runtime based on some condition from the lot of available Images.

and AlexFM, i tried using your solution still it is failing in VERIFY .
i used VERIFY(m_pictureToShow.SetBitmap((HBITMAP)m_bmp.m_hObject));

any solution ????????/
even without VERIFY ,
m_pictureToShow.SetBitmap((HBITMAP)m_bmp.m_hObject)
no error is coming but no Image seen ...its only blank
Try to select image in dialog template, as zfact writes. Do you see it?
AlexFm yr solution works....thanx
but one more problem actually BITMAP ID's i have stored in access table.
when i get thru recordset for that index
rs.GetFieldValue(index,csVal);

i'll get BITMAP ID value in CString variable.
how do i change csVal to UINT so that it is accepted by LoadBitmap().

ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

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
Hi shakir77,
Try this, it will work.

//Add The Bitmpm as shown below
     CBitmap bm1,bm2;
     bm1.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP1));
     bm2.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP2));
     

//Try changeing the bitmap with respect to your requirements as shown below.
     m_ctrlBitMapD.SetBitmap(bm1);
     m_ctrlBitMapD.SetBitmap(bm2);

Try It, All The Best,
Thanks & Regards
Zfact.
Hi shakir77,
Try this, it will work.

//Add The Bitmpm as shown below
     CBitmap bm1,bm2;
     bm1.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP1));
     bm2.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP2));
     

//Try changeing the bitmap with respect to your requirements as shown below.
     m_ctrlBitMapD.SetBitmap(bm1);
     m_ctrlBitMapD.SetBitmap(bm2);

Try It, All The Best,
Thanks & Regards
Zfact.
Thanx AlexFM , your both solution worked very well.