Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Display picture from image file

0 views
Skip to first unread message

Rich

unread,
Oct 14, 2002, 6:51:17 PM10/14/02
to
I've found that the standard "Picture" control can display an image from a
file onto a dialog form ... but the file image is compiled it ... not loaded
from the image file when run.

Is there a simple way to load an image file into the "picture" control when
running?


Jeff Partch

unread,
Oct 14, 2002, 7:19:45 PM10/14/02
to
"Rich" <rcomro...@earthlink.net> wrote in message
news:FTHq9.33852$OB5.2...@newsread2.prod.itd.earthlink.net...

I think it's pretty simple. Just call LoadImage/LR_LOADFROMFILE to get the HANDLE (HBITMAP, HICON or
HCURSOR) for the file based image, and then SendMessage the "Picture" control an STM_SETIMAGE with
the appropriate IMAGE_BITMAP, IMAGE_ICON or IMAGE_CURSOR in the WPARAM and the HANDLE returned by
LoadImage in the LPARAM. If you use ClassWizard to map your "Picture" control to a CStatic member
variable, you could also take advantage of its specialized wrapper functions: SetBitmap, SetIcon or
SetCursor.

--
Jeff Partch [MVP]


Rich

unread,
Oct 14, 2002, 8:15:55 PM10/14/02
to
I made a little test ... had to over-ride the type on the 3rd SendMessage
parameter, but worked!
(my image control was "m_Picture")
It IS pretty simple. Is it anything close to this easy to have the image
scale to the size of the picture object?

---------

void CPictureDlg::OnShowPictureFromFile()
{
HANDLE image_handle;
image_handle = LoadImage(0,"picture.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_Picture.SendMessage(STM_SETIMAGE, IMAGE_BITMAP, (long) image_handle);
}

"Jeff Partch" <je...@mvps.org> wrote in message
news:#jC2#f9cCHA.2780@tkmsftngp08...

Ajay Kalra

unread,
Oct 15, 2002, 1:31:29 AM10/15/02
to
CStatic::SetBitmap wraps what you did.

--
Ajay Kalra
ajay....@autodesk.com


"Rich" <rcomro...@earthlink.net> wrote in message

news:%6Jq9.34114$OB5.2...@newsread2.prod.itd.earthlink.net...

Jeff Partch

unread,
Oct 15, 2002, 10:12:54 AM10/15/02
to
"Rich" <rcomro...@earthlink.net> wrote in message
news:%6Jq9.34114$OB5.2...@newsread2.prod.itd.earthlink.net...

> I made a little test ... had to over-ride the type on the 3rd SendMessage
> parameter, but worked!
> (my image control was "m_Picture")
> It IS pretty simple. Is it anything close to this easy to have the image
> scale to the size of the picture object?


Well, XP adds the SS_REALSIZECONTROL style, but that's the only 'easy' way I see and I've never used
it so I can't recommend it because of that and the platform limitation it imposes. Otherwise, I
think you'd have to pass your HBITMAP through a routine that does a CreateCompatibleDC,
CreateCompatibleBitmap, SelectObject, StretchBlt, <Clean up> sort of thing, and pass the resultant
HBITMAP to STM_SETIMAGE or CStatic::SetBitmap.

--
Jeff Partch [MVP]


0 new messages