Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Transfer a picture or icon from box to a CStatic (Read 4340 times)
rcruzmar
YaBB Newbies
*
Offline



Posts: 25
Location: FL
Joined: Sep 19th, 2007
Transfer a picture or icon from box to a CStatic
Sep 24th, 2007 at 10:52pm
Print Post  
Hello,

I've been looking around at different forum messages here but can't seem to find the answer I am looking for... ???

I need to extract (lack of a better word) the Picture of a box control and display it in a CStatic control using SetBitmap or SetIcon.

I placed the following code...

m_PictCtrl.SetBitmap((HBITMAP)boxItem.GetPicture().GetHandle());

... but all I get is the image displayed at full size but I can only see the center of the image. I can't seem to be able to have the image resized within the control. Might be a MFC functionality.

If I get the properties of a control with an image in it from the Resources, I get no image displayed. It seems I can only display images which were loaded from a file.

What am I missing? I hope you can point me in the right direction.

Thanks fro your help.

Rolando
« Last Edit: Sep 25th, 2007 at 3:24pm by rcruzmar »  
Back to top
 
IP Logged
 
rcruzmar
YaBB Newbies
*
Offline



Posts: 25
Location: FL
Joined: Sep 19th, 2007
Re: Transfer a picture or icon from box to a CStat
Reply #1 - Sep 24th, 2007 at 11:48pm
Print Post  
Unless there is another way, I found some code which allws me to take an HBITMAP and save it to a file. After this is done I load the file into the CStatic and it is displayed as I want it. Grin

Now, this only works with box items which have the image loaded with the LoadPicture method. If the picture of the box was loaded using LoadPictrureFromRes then I do not have an image. Undecided BTW, these resource images are icon images.

Thanks for the help

Rolando
« Last Edit: Sep 25th, 2007 at 3:25pm by rcruzmar »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Transfer a picture or icon from box to a CStat
Reply #2 - Sep 25th, 2007 at 7:50am
Print Post  
Hi,

You could use the IPicture::Render() method to draw the image in your own HDC. E.g. call it from the WM_PAINT handle of your dialog.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rcruzmar
YaBB Newbies
*
Offline



Posts: 25
Location: FL
Joined: Sep 19th, 2007
Re: Transfer a picture or icon from box to a CStat
Reply #3 - Sep 25th, 2007 at 12:30pm
Print Post  
I'm not sure that this answerrs my question. ???

I need to know if I have access to any picture stored in a BoxItem which was loaded with the LoadPictureFromRes method and if so does the GetPIcture method return it as an HBITMAP or HICON depending on what the original image was created as.

What I mean by that is, if the source image used to create the custom resource was an icon does that mean the GetPicture method returns the data as HICON or can I still use HBITMAP. NOTE: I've changed the custom image in the resource from an icon to a bitmap but I get the same result.

I can extract and display images from the BoxItem using (HBITMAP)boxItem.GetPicture() but only if they are loaded from the LoadPicture method otherwise I get a blank control where the image gets displayed.

Thanks for your help.

Rolando
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Transfer a picture or icon from box to a CStat
Reply #4 - Sep 25th, 2007 at 1:00pm
Print Post  
This just lets you draw images without having to save them in temporary files first.

If you insist on using temporary files, try calling the IPicture::SaveAsFile method(). Another option is to query the IPicture object for the IPersistStream interface, and then call the IPersistStream::Save() method. This is how FlowChartX writes images when you call its SaveToFile method:

[code]
bool PersistenceHelper::savePicture(IPicture* picture)
{
     ULONG written = 0;
     if (picture)
     {
           ULARGE_INTEGER ulSize;
           CComQIPtr<IPersistStream> pPerStr = picture;
           pPerStr->GetSizeMax(&ulSize);

           stream->Write(&ulSize, sizeof(ulSize), &written);
           pPerStr->Save(stream, FALSE);
           return true;
     }
     ...
}
[/code]

So if the flowchart's SaveToFile and LoadFromFile methods save/load your images successfully, the code above should work fine.

Stoyan
  
Back to top
 
IP Logged
 
rcruzmar
YaBB Newbies
*
Offline



Posts: 25
Location: FL
Joined: Sep 19th, 2007
Re: Transfer a picture or icon from box to a CStat
Reply #5 - Sep 25th, 2007 at 9:58pm
Print Post  
Thanks for your help in this.

Rolando
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint