本文整理汇总了C++中CDC::CreateDCW方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::CreateDCW方法的具体用法?C++ CDC::CreateDCW怎么用?C++ CDC::CreateDCW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::CreateDCW方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyFromScreen
/*************************************************************************
*
* CopyScreenToBitmap()
*
* Parameter:
*
* LPRECT lpRect - specifies the window
*
* Return Value:
*
* HDIB - identifies the device-dependent bitmap
*
* Description:
*
* This function copies the specified part of the screen to a device-
* dependent bitmap.
*
*
************************************************************************/
void CDib::CopyFromScreen(const CRect& rectIn)
{
// check for an empty rectangle
if (rectIn.IsRectEmpty())
{
Empty();
return;
}
CDC ScrDC;
CDC MemDC;
// create a DC for the screen and create
// a memory DC compatible to screen DC
ScrDC.CreateDCW(L"DISPLAY", NULL, NULL, NULL);
MemDC.CreateCompatibleDC(&ScrDC);
// get screen resolution
int xScrn = ScrDC.GetDeviceCaps(HORZRES);
int yScrn = ScrDC.GetDeviceCaps(VERTRES);
CRect rect(rectIn);
rect.NormalizeRect();
//make sure bitmap rectangle is visible
if (rect.left < 0)
rect.left = 0;
if (rect.top < 0)
rect.top = 0;
if (rect.right > xScrn)
rect.right = xScrn;
if (rect.bottom> yScrn)
rect.bottom = yScrn;
// create a bitmap compatible with the screen DC
CreateDib( CSize(rect.Width(), rect.Height()), 32);
CBitmap* pBitmap = CBitmap::FromHandle( (HBITMAP)(*this));
//pBitmap->GetBitmap(&bmp);
//ASSERT(false);
//HBITMAP hBitmap = NULL;//C reateCompatibleDIB( ScrDC, rect.Width(), rect.Height());
// select new bitmap into memory DC
CBitmap* pOldBitmap = MemDC.SelectObject(pBitmap);
//HBITMAP hOldBitmap = (HBITMAP)MemDC.SelectObject((hBitmap);
// bitblt screen DC to memory DC
MemDC.BitBlt(0, 0, rect.Width(), rect.Height(), &ScrDC, rect.left, rect.top, SRCCOPY);
//CreatePaletteFromImage(m_palette);
// select old bitmap back into memory DC and get handle to
// bitmap of the screen
//hBitmap = (HBITMAP)MemDC.SelectObject(hOldBitmap);
MemDC.SelectObject(pOldBitmap);
// clean up
ScrDC.DeleteDC();
MemDC.DeleteDC();
}