Click here to Skip to main content
14,269,359 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hy there,

I am currently working on MFC dialog, I need to insert pictures dynamically.
Actually I don't want to use the drag drop option of picture already provided. This is static approach however I need to specify an area via code and than load image to that area. This would now be dynamic and my requirement.

Need help urgently.

Thanks.
Posted
Updated 13-Nov-11 7:12am
v4
Comments
Mehdi Gholam 13-Nov-11 2:48am
   
EDIT -> removed extra formatting
Andrew Brock 13-Nov-11 2:59am
   
Can you please explain further (use the improve Question button at the bottom of your question).

Where are you trying to put the image? In a dialog box, on a button, around some text, ...?
Does "without using picture box" mean that you don't want to use a separate control to hold the image, if so, why, or what is stopping this approach?
saybiz 13-Nov-11 12:57pm
   
yeah, actually i m working on mfc dialog.. i don't want to use the drag drop option of picture already provided.. this is static however i need to specify an area via code and than load image to that area..this would now be dynamic and my requirement.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Use CStatic control. And change its property for bit map.
   
Comments
Andrew Brock 13-Nov-11 4:45am
   
I think this is what they are calling a "picture box", could be wrong tho.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use the CBitmap[^] class to construct the image and draw into your view.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

saybiz wrote:
This would now be dynamic and my requirement.

You can use the picture control in the dialog editor still. Give it an ID (near the bottom of the properties pane), for example IDC_PICTURE

Now in the code you can get a handle of the picture control with GetDlgItem(IDC_PICTURE).

Once you have the handle, you can move or resize it with either SetWindowPos[^] or MoveWindow[^]

If you cast the value returned by GetDlgItem to CStatic you can also use the functions in that class to change the picture or anything else.

int width = 100;
int height = 75;
CStatic *pMyPicture = (CStatic *)GetDlgItem(IDC_PICTURE);
pMyPicture ->SetWindowPos(NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE); //Don't reorder control layering, and don't move the top left corner
//This example will only move the bottom right corner to resize
   
Comments
Albert Holguin 14-Nov-11 0:31am
   
This would require the images to be part of the compiled resources... If op means load from file, this wouldn't work. Guess it depends on what op means by "dynamic".
Andrew Brock 14-Nov-11 6:08am
   
No it doesn't. See http://msdn.microsoft.com/en-US/library/b7w5x74z(v=VS.80).aspx
You can load up a bitmap however you want into a HBITMAP and shove that into it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100