CImage image;
// Code to load/create image goes here
// Get a CDC for the image
CDC* pDC = CDC::FromHandle(image.GetDC());
// Use pDC here
image.ReleaseDC();
When you use CImage in an MFC project, note which member functions in your project expect a pointer to a CBitmap object. If you want to use CImage with such a function, like CMenu::AppendMenu, use CBitmap::FromHandle, pass it your CImage HBITMAP, and use the returned CBitmap*.
CMyWnd::OnRButtonDown(int nFlags, CPoint mouse)
{
CMenu menu;
CImage image;
// Code to create menu and load/create image goes here
CBitmap* pBitmap = CBitmap::FromHandle(image.m_hBitmap);
menu.AppendMenu(0, ID_SOMECOMMAND, pBitmap)
menu.TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, mouse.x, mouse.y, this);
} For more examples, see the HttpClient Sample and the ShowImage Sample.
Through CImage, you have access to the actual bits of a DIB section. You can use a CImage object anywhere you previously used a Win32 HBITMAP or DIB section.
Note |
|---|
| The following CImage methods have limitations on their use: |
|
Method
|
Limitation
|
| PlgBlt | Works with only Windows NT 4.0 or later. Will not work on applications running on Windows 95/98 or later. |
| MaskBlt | Works with only Windows NT 4.0 or later. Will not work on applications running on Windows 95/98 or later. |
| AlphaBlend | Works with only Windows 2000, Windows 98, and later systems. |
| TransparentBlt | Works with only Windows 2000, Windows 98, and later systems. |
| Draw | Supports transparency with only Windows 2000, Windows 98, and later systems. |
See CImage Limitations with Earlier Operating Systems for more detailed information about the limitations on these methods.
You can use CImage from either MFC or ATL.
Note |
|---|
| When you create a project using CImage, you must define CString before you include atlimage.h. If your project uses ATL without MFC, include atlstr.h before you include atlimage.h. If your project uses MFC (or if it is an ATL project with MFC support), include afxstr.h before you include atlimage.h. Likewise, you must include atlimage.h before you include atlimpl.cpp. To accomplish this easily, include atlimage.h in your stdafx.h. |