Skip to content

Commit a73f02a

Browse files
author
Greg Van Liew
authored
Merge pull request MicrosoftDocs#83 from Microsoft/master
Merge master to live
2 parents f471c58 + c243063 commit a73f02a

205 files changed

Lines changed: 1690 additions & 2713 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/atl-mfc-shared/reference/cimage-class.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,31 @@ class CImage
141141
`CImage` cannot be selected into a new [CDC](../../mfc/reference/cdc-class.md). `CImage` creates its own **HDC** for the image. Because an `HBITMAP` can only be selected into one **HDC** at a time, the `HBITMAP` associated with the `CImage` cannot be selected into another **HDC**. If you need a `CDC`, retrieve the **HDC** from the `CImage` and give it to [CDC::FromHandle](../../mfc/reference/cdc-class.md#cdc__fromhandle.
142142

143143
## Example
144-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#70](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#70)] -->
144+
```cpp
145+
// Get a CDC for the image
146+
CDC* pDC = CDC::FromHandle(m_myImage.GetDC());
147+
148+
// Use pDC here
149+
pDC->Rectangle(0, 40, 100, 50);
150+
151+
m_myImage.ReleaseDC();
152+
```
145153
146154
When you use `CImage` in an MFC project, note which member functions in your project expect a pointer to a [CBitmap](../../mfc/reference/cbitmap-class.md) object. If you want to use `CImage` with such a function, like [CMenu::AppendMenu](../../mfc/reference/cmenu-class.md#cmenu__appendmenu, use [CBitmap::FromHandle](../../mfc/reference/cbitmap-class.md#cbitmap__fromhandle, pass it your `CImage` `HBITMAP`, and use the returned `CBitmap*`.
147155
148156
## Example
149-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#71](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#71)]-->
157+
```cpp
158+
void CMyDlg::OnRButtonDown(UINT nFlags, CPoint point)
159+
{
160+
UNREFERENCED_PARAMETER(nFlags);
161+
162+
CBitmap* pBitmap = CBitmap::FromHandle(m_myImage);
163+
m_pmenuPop->AppendMenu(0, ID_BMPCOMMAND, pBitmap);
164+
ClientToScreen(&point);
165+
m_pmenuPop->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, point.x,
166+
point.y, this);
167+
}
168+
```
150169

151170
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.
152171

@@ -439,8 +458,11 @@ BOOL CreateEx(int nWidth,
439458
### Example
440459
The following example creates a 100x100 pixel bitmap, using 16 bits to encode each pixel. In a given 16-bit pixel, bits 0-3 encode the red component, bits 4-7 encode green, and bits 8-11 encode blue. The remaining 4 bits are unused.
441460

442-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#69](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#69)]-->
443-
461+
```cpp
462+
DWORD adwBitmasks[3] = { 0x0000000f, 0x000000f0, 0x00000f00 };
463+
m_myImage.CreateEx(100, 100, 16, BI_BITFIELDS, adwBitmasks, 0);
464+
```
465+
444466
## <a name="cimage__destroy"></a> CImage::Destroy
445467
Detaches the bitmap from the `CImage` object and destroys the bitmap.
446468
@@ -627,7 +649,12 @@ static HRESULT GetExporterFilterString(CSimpleString& strExporters,
627649
628650
For example:
629651
630-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#73](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#73)] -->
652+
```cpp
653+
//First filter in the list will be titled "All Image Files", and
654+
//will accept files with any extension supported by any exporter.
655+
CImage::GetExporterFilterString( strExporters, aguidFileTypes,
656+
_T("All Image Files"));
657+
```
631658

632659
`dwExclude`
633660
Set of bit flags specifying which file types to exclude from the list. Allowable flags are:
@@ -709,7 +736,12 @@ static HRESULT GetImporterFilterString(CSimpleString& strImporters,
709736

710737
For example:
711738

712-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#74](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#74)] -->
739+
```cpp
740+
//First filter in the list will be titled "All Image Files", and
741+
//will accept files with any extension supported by any importer.
742+
CImage::GetImporterFilterString( strImporters, aguidFileTypes,
743+
_T("All Image Files"));
744+
```
713745
714746
`dwExclude`
715747
Set of bit flags specifying which file types to exclude from the list. Allowable flags are:
@@ -1434,7 +1466,33 @@ BOOL TransparentBlt(HDC hDestDC,
14341466
This method is applicable to Microsoft Windows 2000, Windows 98, and later systems.
14351467
14361468
### Example
1437-
<!-- FIXME [!CODE [NVC_ATLMFC_Utilities#199](../CodeSnippet/VS_Snippets_Cpp/NVC_ATLMFC_Utilities#199)] -->
1469+
```cpp
1470+
// Performs a transparent blit from the source image to the destination
1471+
// image using the images' current transparency settings
1472+
BOOL TransparentBlt(CImage* pSrcImage, CImage* pDstImage, int xDest, int yDest,
1473+
int nDestWidth, int nDestHeight)
1474+
{
1475+
HDC hDstDC = NULL;
1476+
BOOL bResult;
1477+
1478+
if(pSrcImage == NULL || pDstImage == NULL)
1479+
{
1480+
// Invalid parameter
1481+
return FALSE;
1482+
}
1483+
1484+
// Obtain a DC to the destination image
1485+
hDstDC = pDstImage->GetDC();
1486+
1487+
// Perform the blit
1488+
bResult = pSrcImage->TransparentBlt(hDstDC, xDest, yDest, nDestWidth, nDestHeight);
1489+
1490+
// Release the destination DC
1491+
pDstImage->ReleaseDC();
1492+
1493+
return bResult;
1494+
}
1495+
```
14381496

14391497
## See Also
14401498
[Device-Independent Bitmaps](http://msdn.microsoft.com/library/windows/desktop/dd183562)

0 commit comments

Comments
 (0)