CPicture holds a CPicture object and overrides WM_PAINT to call CPicture::Render instead of the normal static control thing. If you specify a URL, clicking the mouse on the picture will launch your browser to that link. ![]() I derived CPictureCtrl from my ubiquitous CStaticLink, so you can specify a URL hyperlink if you like (or just create a string resource with the same ID as the control and picture). ![]() This assumes you have a static control in your dialog, with ID=IDC_IMAGE and an IMAGE resource with the same ID. CPictureDoc is trivial it uses CPicture to hold the picture- class CPictureDoc : public CDocument You can find it in afxctl.h.Īs I mentioned earlier, ImgView is a typical MFC doc/view application with classes CPictureDoc and CPictureView for doc and view. At least the code is trivial.īy the way, I should point out that after writing CPicture, I discovered a little-known MFC class called CPictureHolder that does much of the same thing. If you ever need to call IPicture::get_Handle or some other rare IPicture method, you'll have to add the wrapper yourself, sorry. CPicture encapsulates only those IPicture methods I needed to write ImgView this being because I am such a lazy programmer. CPicture provides the usual wrapper functions to call the underlying IPicture. It holds an ATL CComQIPtr smart pointer to the IPicture interface, which the various Load functions initialize by calling OleLoadPicture. As for the image itself, CPicture looks for a resource type called "IMAGE", so you have to code your RC file like so: IDR_MYPIC IMAGE MOVEABLE PURE "res\\MyPic.jpg" If you pass an empty rect, CPicture uses the image's native size-no stretching. IPicture stretches the image appropriately. What could be easier? CPicture::Render takes a rectangle, the one you want to display your picture in. CPicture even has a Load function to load an image from your resource data, so all you have to do to display a resource picture is write: CPicture pic(ID_MYPIC) // load pic CRect rc(0,0,0,0) // use default rc pic.Render(pDC, rc) // display it ![]() For example, CPicture lets you load a picture directly from a file name, CFile, or CArchive, instead of dealing with streams and CPicture::Render does all the yucky HIMETRIC coordinate conversions that IPicture wants-so you don't have to. CPicture maps cumbersome COM-style parameters into types more friendly to MFC programmers. ImgView is a typical MFC doc/view app that uses a class I wrote, CPicture (see Figure 3), to encapsulate IPicture. IPicture does all the nasties to figure out whether the image is a Windows bitmap, JPEG, or GIF file-it even does icons and metafiles! Naturally, the details are a little tricky, so I wrote a little demo program called ImgView (see Figure 2) to put it all together. rc = // rect to display in // convert rc to HIMETRIC spIPicture->Render(pDC, rc) OleLoadPicture loads the picture from the stream and creates a new IPicture object you can use to display the picture. IStream* pstm = // needs a stream IPicture* pIPicture hr = OleLoadPicture(pstm, 0, FALSE, IID_IPicture, (void**)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |