本文整理匯總了C++中BitBlt函數的典型用法代碼示例。如果您正苦於以下問題:C++ BitBlt函數的具體用法?C++ BitBlt怎麽用?C++ BitBlt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BitBlt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DrawMine
static void DrawMine( HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed )
{
MINEBMP_OFFSET offset = BOX_BMP;
if( col == 0 || col > p_board->cols || row == 0 || row > p_board->rows )
return;
if( p_board->status == GAMEOVER ) {
if( p_board->box[col][row].IsMine ) {
switch( p_board->box[col][row].FlagType ) {
case FLAG:
offset = FLAG_BMP;
break;
case COMPLETE:
offset = EXPLODE_BMP;
break;
case QUESTION:
/* fall through */
case NORMAL:
offset = MINE_BMP;
}
} else {
switch( p_board->box[col][row].FlagType ) {
case QUESTION:
offset = QUESTION_BMP;
break;
case FLAG:
offset = WRONG_BMP;
break;
case NORMAL:
offset = BOX_BMP;
break;
case COMPLETE:
/* Do nothing */
break;
default:
WINE_TRACE("Unknown FlagType during game over in DrawMine\n");
break;
}
}
} else { /* WAITING or PLAYING */
switch( p_board->box[col][row].FlagType ) {
case QUESTION:
if( !IsPressed )
offset = QUESTION_BMP;
else
offset = QPRESS_BMP;
break;
case FLAG:
offset = FLAG_BMP;
break;
case NORMAL:
if( !IsPressed )
offset = BOX_BMP;
else
offset = MPRESS_BMP;
break;
case COMPLETE:
/* Do nothing */
break;
default:
WINE_TRACE("Unknown FlagType while playing in DrawMine\n");
break;
}
}
if( p_board->box[col][row].FlagType == COMPLETE
&& !p_board->box[col][row].IsMine )
offset = (MINEBMP_OFFSET) p_board->box[col][row].NumMines;
BitBlt( hdc,
(col - 1) * MINE_WIDTH + p_board->mines_rect.left,
(row - 1) * MINE_HEIGHT + p_board->mines_rect.top,
MINE_WIDTH, MINE_HEIGHT,
hMemDC, 0, offset * MINE_HEIGHT, SRCCOPY );
}
示例2: switch
void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
{
void *retval = NULL;
switch ( dataFormat )
{
#ifndef __WXWINCE__
case wxDF_BITMAP:
{
BITMAP bm;
HBITMAP hBitmap = (HBITMAP) GetClipboardData(CF_BITMAP);
if (!hBitmap)
break;
HDC hdcMem = CreateCompatibleDC((HDC) NULL);
HDC hdcSrc = CreateCompatibleDC((HDC) NULL);
HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, hBitmap);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
HBITMAP hNewBitmap = CreateBitmapIndirect(&bm);
if (!hNewBitmap)
{
SelectObject(hdcSrc, old);
DeleteDC(hdcMem);
DeleteDC(hdcSrc);
break;
}
HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hNewBitmap);
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight,
hdcSrc, 0, 0, SRCCOPY);
// Select new bitmap out of memory DC
SelectObject(hdcMem, old1);
// Clean up
SelectObject(hdcSrc, old);
DeleteDC(hdcSrc);
DeleteDC(hdcMem);
// Create and return a new wxBitmap
wxBitmap *wxBM = new wxBitmap;
wxBM->SetHBITMAP((WXHBITMAP) hNewBitmap);
wxBM->SetWidth(bm.bmWidth);
wxBM->SetHeight(bm.bmHeight);
wxBM->SetDepth(bm.bmPlanes);
retval = wxBM;
break;
}
#endif
case wxDF_METAFILE:
case CF_SYLK:
case CF_DIF:
case CF_TIFF:
case CF_PALETTE:
case wxDF_DIB:
wxLogError(_("Unsupported clipboard format."));
return NULL;
case wxDF_OEMTEXT:
dataFormat = wxDF_TEXT;
// fall through
case wxDF_TEXT:
{
HANDLE hGlobalMemory = ::GetClipboardData(dataFormat);
if (!hGlobalMemory)
break;
DWORD hsize = ::GlobalSize(hGlobalMemory);
if (len)
*len = hsize;
char *s = new char[hsize];
if (!s)
break;
LPSTR lpGlobalMemory = (LPSTR) GlobalLock(hGlobalMemory);
memcpy(s, lpGlobalMemory, hsize);
GlobalUnlock(hGlobalMemory);
retval = s;
break;
}
default:
{
HANDLE hGlobalMemory = ::GetClipboardData(dataFormat);
if ( !hGlobalMemory )
break;
DWORD size = ::GlobalSize(hGlobalMemory);
if ( len )
*len = size;
void *buf = malloc(size);
//.........這裏部分代碼省略.........
示例3: CSize
DWORD CmdDrawZoom::CmdDrawAjustZooming::SetPoint(DWORD MouseAction, CPoint pt)
{
CmdDrawZoom *p = dynamic_cast<CmdDrawZoom*>(m_pOwner);
if (enCmdMouseNone == MouseAction)
{
LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo();
if (NULL == pTempInfo)
{
return FALSE;
}
CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y);
size.cx = max(size.cx, 24);
size.cy = max(size.cy, 24);
pTempInfo->SetFinalSize(size);
if (pTempInfo->isPenDraw) {
int width = pTempInfo->m_image.GetWidth();
int height = pTempInfo->m_image.GetHeight();
if (width<size.cx || height<size.cy)
{
int newWidth = max(width, size.cx);
int newHeight = max(height, size.cy);
CxImage tempImage = pTempInfo->m_image;
pTempInfo->m_image.Create(newWidth, newHeight, 24, CXIMAGE_FORMAT_PNG);
RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1);
pTempInfo->m_image.SetTransIndex(0);
pTempInfo->m_image.SetTransColor(rgb);
HDC memdcOrg = CreateCompatibleDC(NULL);
HBITMAP hbitmapOrg = tempImage.MakeBitmap();
HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg);
HDC memdc = CreateCompatibleDC(NULL);
HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap();
HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap);
BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY);
pTempInfo->m_image.CreateFromHBITMAP(hbitmap);
SelectObject(memdc, pOldGDIOBJ);
DeleteObject(hbitmap);
DeleteDC(memdc);
SelectObject(memdcOrg, pOldGDIOBJOrg);
DeleteObject(hbitmapOrg);
DeleteDC(memdcOrg);
}
}
p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner);
}
else if (enCmdMouseLUp == MouseAction)
{
LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo();
if (NULL == pTempInfo)
{
return FALSE;
}
CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y);
size.cx = max(size.cx, 24);
size.cy = max(size.cy, 24);
pTempInfo->SetFinalSize(size);
if (pTempInfo->isPenDraw) {
int width = pTempInfo->m_image.GetWidth();
int height = pTempInfo->m_image.GetHeight();
if (width<size.cx || height<size.cy)
{
CxImage tempImage = pTempInfo->m_image;
pTempInfo->m_image.Create(size.cx, size.cy, 24, CXIMAGE_FORMAT_PNG);
RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1);
pTempInfo->m_image.SetTransIndex(0);
pTempInfo->m_image.SetTransColor(rgb);
HDC memdcOrg = CreateCompatibleDC(NULL);
HBITMAP hbitmapOrg = tempImage.MakeBitmap();
HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg);
HDC memdc = CreateCompatibleDC(NULL);
HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap();
HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap);
BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY);
pTempInfo->m_image.CreateFromHBITMAP(hbitmap);
SelectObject(memdc, pOldGDIOBJ);
DeleteObject(hbitmap);
DeleteDC(memdc);
SelectObject(memdcOrg, pOldGDIOBJOrg);
DeleteObject(hbitmapOrg);
DeleteDC(memdcOrg);
}
}
p->m_pReceiver->SaveFile();
p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner);
p->m_pDsState = &p->m_dsZoomBgn;
p->m_pReceiver->SetCursor();
p->m_nDrawState = enDrawIdle;
}
return TRUE;
}
示例4: abs
BOOL CDIB::SetBitmap(HBITMAP hBitmap, HPALETTE hPal /*= NULL*/)
{
// DeleteObject();
if (!hBitmap)
return FALSE;
// Get dimensions of bitmap
BITMAP bm;
if (!::GetObject(hBitmap, sizeof(bm),(LPVOID)&bm))
return FALSE;
bm.bmHeight = abs(bm.bmHeight);
HDC hDC = GetWindowDC(NULL);
HPALETTE hOldPal = NULL;
m_iColorTableSize = NumColorEntries(bm.bmBitsPixel, BI_RGB);
// Initialize the BITMAPINFOHEADER in m_DIBinfo
BITMAPINFOHEADER& bih = m_DIBinfo.bmiHeader;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = bm.bmWidth;
bih.biHeight = bm.bmHeight;
bih.biPlanes = 1; // Must always be 1 according to docs
bih.biBitCount = bm.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biSizeImage = BytesPerLine(bm.bmWidth, bm.bmBitsPixel) * bm.bmHeight;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
GetColorTableEntries(hDC, hBitmap);
// If we have a palette supplied, then set the palette (and hance DIB color
// table) using this palette
if (hPal)
SetPalette(hPal);
if (hPal)
{
hOldPal = SelectPalette(hDC, m_hPal, FALSE);
RealizePalette(hDC);
}
// Create it!
m_hBitmap = CreateDIBSection(hDC, (const BITMAPINFO*) m_DIBinfo, m_iColorDataType, &m_ppvBits, NULL, 0);
if (hOldPal)
SelectPalette(hDC, hOldPal, FALSE);
hOldPal = NULL;
if (! m_hBitmap)
{
TRACE0("Unable to CreateDIBSection\n");
return FALSE;
}
// If palette was supplied then create a palette using the entries in the DIB
// color table.
if (! hPal)
CreatePalette();
// Need to copy the supplied bitmap onto the newly created DIBsection
HDC hMemDC = CreateCompatibleDC(hDC);
HDC hCopyDC = CreateCompatibleDC(hDC);
if (! hMemDC || ! hCopyDC)
{
TRACE0("Unable to create compatible DC's\n");
//AfxThrowResourceException();
}
if (m_hPal)
{
SelectPalette(hMemDC, m_hPal, FALSE); RealizePalette(hMemDC);
SelectPalette(hCopyDC, m_hPal, FALSE); RealizePalette(hCopyDC);
}
HBITMAP hOldMemBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);
HBITMAP hOldCopyBitmap = (HBITMAP) SelectObject(hCopyDC, m_hBitmap);
BitBlt(hCopyDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldMemBitmap);
SelectObject(hCopyDC, hOldCopyBitmap);
if (m_hPal)
{
HGDIOBJ hObj = ::GetStockObject(DEFAULT_PALETTE);
SelectObject(hMemDC, hObj);
SelectObject(hCopyDC, hObj);
}
ReleaseDC(NULL, hDC);
return TRUE;
}
示例5: WndProc
//.........這裏部分代碼省略.........
doChooseColor(hEdit);
break;
case ID_FILE_OPEN:
OPENFILENAME ofn;
TCHAR szFile[260];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("All Files *.*\0*.*\0Text Files *.txt\0*.TXT\0 Doc Files\0*.TXT;*.DOC;*.BAK\0");
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = _T("C:\\");
ofn.lpstrTitle = _T("My Application - Open file");
ofn.lpstrDefExt = _T("txt");
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn) == TRUE) {
PAINTSTRUCT ps;
HDC hdc = GetDC(hWnd);
// HDC hdcDestination;
HBITMAP hbitmap = (HBITMAP)::LoadImage(NULL, ofn.lpstrFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// MessageBox(NULL, ofn.lpstrFile, _T("Selected file"), MB_OK);
//hdc = getOb
HDC memDC = CreateCompatibleDC(hdc);
SelectObject(memDC, hbitmap);
RECT rect;
GetClientRect(hWnd, &rect);
BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, memDC, 0, 0, SRCCOPY);
}
break;
case ID_FILE_SAVE:
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
char szFileName[MAX_LOADSTRING];
ZeroMemory(szFileName, MAX_LOADSTRING);
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = _T("All Files(*.*)\0 * .*\0Bmp Files(*.bmp)\0 * .bmp\0Text Files(*.txt)\0 * .txt\0");
ofn.lpstrFile = (LPWSTR)szFileName;
ofn.nMaxFile = MAX_LOADSTRING;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = (LPCWSTR)L"bmp";
GetSaveFileName(&ofn);
PBITMAPINFO PBi = CreateBitmapInfoStruct(hWnd, hBitmap);
CreateBMPFile(hWnd, ofn.lpstrFile, PBi, hBitmap, hdc);
/*save = 1;*/
}
break;
case ID_FILE_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
示例6: CreateCompatibleDC
// TODO code: optimise airspace drawing (same as DrawAirSpace())
// draw airspace using alpha blending
//static
void MapWindow::DrawTptAirSpace(HDC hdc, const RECT rc) {
// since standard GDI functions (brushes, pens...) ignore alpha octet in ARGB
// color value and don't set it in the resulting bitmap, we cannot use
// perpixel alpha blending, instead we use global opacity for alpha blend
// (same opacity for all pixels); for fully "transparent" areas (without
// airspace) we must copy destination bitmap into source bitmap first so that
// alpha blending of such areas results in the same pixels as origin pixels
// in destination
CAirspaceList::const_iterator it;
CAirspaceList::const_reverse_iterator itr;
const CAirspaceList& airspaces_to_draw = CAirspaceManager::Instance().GetNearAirspacesRef();
int airspace_type;
bool found = false;
bool borders_only = (GetAirSpaceFillType() == asp_fill_ablend_borders);
HDC hdcbuffer = NULL;
HBITMAP hbbufferold = NULL, hbbuffer = NULL;
if (borders_only) {
// Prepare layers
hdcbuffer = CreateCompatibleDC(hdc);
hbbuffer = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
hbbufferold = (HBITMAP)SelectObject(hdcbuffer, hbbuffer);
BitBlt(hdcbuffer, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS );
SelectObject(hdcbuffer, GetStockObject(NULL_PEN));
BitBlt(hDCMask, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS );
SelectObject(hDCMask, hAirspaceBorderPen);
SelectObject(hDCMask, GetStockObject(HOLLOW_BRUSH));
}
// Draw airspace area
if (1) {
CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef());
if (borders_only) {
// Draw in reverse order!
// The idea behind this, is lower top level airspaces are smaller. (statistically)
// They have to be draw later, because inside border area have to be in correct color,
// not the color of the bigger airspace above this small one.
for (itr=airspaces_to_draw.rbegin(); itr != airspaces_to_draw.rend(); ++itr) {
if ((*itr)->DrawStyle() == adsFilled) {
airspace_type = (*itr)->Type();
if (!found) {
found = true;
ClearTptAirSpace(hdc, rc);
}
// set filling brush
SelectObject(hdcbuffer, GetAirSpaceSldBrushByClass(airspace_type));
(*itr)->Draw(hdcbuffer, rc, true);
(*itr)->Draw(hDCMask, rc, false);
}
}//for
} else {
// Draw in direct order!
for (it=airspaces_to_draw.begin(); it != airspaces_to_draw.end(); ++it) {
if ((*it)->DrawStyle() == adsFilled) {
airspace_type = (*it)->Type();
if (!found) {
found = true;
ClearTptAirSpace(hdc, rc);
}
// set filling brush
SelectObject(hDCTemp, GetAirSpaceSldBrushByClass(airspace_type));
(*it)->Draw(hDCTemp, rc, true);
}
}//for
}//else borders_only
}//mutex release
// alpha blending
if (found) {
if (borders_only) {
#if (WINDOWSPC<1)
TransparentImage(hdcbuffer,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
hDCMask,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
RGB_WHITE
);
TransparentImage(hDCTemp,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
hdcbuffer,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
RGB_BLACK
);
#else
TransparentBlt(hdcbuffer,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
hDCMask,
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
RGB_WHITE
);
//.........這裏部分代碼省略.........
示例7: GetSourceCoordinates
void Scope::CaptureScreen()
{
GetSourceCoordinates(&m_intScreenCapX, &m_intScreenCapY);
// calculate coordinates of source rectangle
RECT SourceRect;
SourceRect.left = m_intScreenCapX;
SourceRect.top = m_intScreenCapY;
SourceRect.right = SourceRect.left + m_intSrcWidth * 2 + long((m_intSBSOffset + m_intImageSeparation) / m_fltZoom);
SourceRect.bottom = SourceRect.top + m_intSrcHeight;
// blit a copy of the screen so you don't have to draw on the screen DC
BITMAP WinCopyBMInfo;
GetObjectW(m_winCopyBM, sizeof(BITMAP), &WinCopyBMInfo);
BitBlt(m_winCopyDC, 0, 0, WinCopyBMInfo.bmWidth, WinCopyBMInfo.bmHeight, m_winDC, 0, 0, SRCCOPY | CAPTUREBLT);
//Draw the cursor
m_GlobalCursor.cbSize = sizeof(CURSORINFO);
GetCursorInfo(&m_GlobalCursor);
if (m_GlobalCursor.flags == CURSOR_SHOWING) {
ICONINFO CursorInfo;
GetIconInfo((HICON)m_GlobalCursor.hCursor, &CursorInfo);
DrawIconEx(m_winCopyDC,
m_GlobalCursor.ptScreenPos.x, m_GlobalCursor.ptScreenPos.y,
m_GlobalCursor.hCursor,
int(m_intCursorWidth * m_fltZoom), int(m_intCursorHeight * m_fltZoom),
0, NULL, DI_COMPAT | DI_NORMAL);
DeleteObject(CursorInfo.hbmColor);
DeleteObject(CursorInfo.hbmMask);
}
// Rotate and offset the desktop
// Build the destination parallelogram using glm
glm::vec2 pts_vec2[3];
pts_vec2[0] = glm::vec2(0, 0);
pts_vec2[1] = glm::vec2(m_intMainDisplayWidth, 0);
pts_vec2[2] = glm::vec2(0, m_intMainDisplayHeight);
glm::vec2 center(m_intMainDisplayWidth / 2, m_intMainDisplayHeight / 2);
const float roll = -m_fltRoll;
glm::mat2 R = glm::mat2(cos(roll), -sin(roll), sin(roll), cos(roll));
glm::mat2 S = glm::mat2(m_fltZoom, 0, 0, m_fltZoom);
// Transform the points and convert to GDI format
POINT pts[3];
for (int i = 0; i < 3; ++i) {
// Move to origin [0, 0]
pts_vec2[i] -= center;
// Scale (zoom)
pts_vec2[i] = S * pts_vec2[i];
// Offset according to HMD orientation
pts_vec2[i].x -= m_intScreenCapX;
pts_vec2[i].y -= m_intScreenCapY;
// Rotate
pts_vec2[i] = R * pts_vec2[i];
// Move back
pts_vec2[i] += center;
// Convert to GDI format
pts[i].x = pts_vec2[i].x;
pts[i].y = pts_vec2[i].y;
}
// Clear the back buffer
RECT ClearRect = {0, 0, m_intMainDisplayWidth, m_intMainDisplayHeight};
FillRect(m_BackDC, &ClearRect, (HBRUSH)COLOR_WINDOWTEXT);
// Blit the rotated desktop to back buffer
PlgBlt(m_BackDC, pts, m_winCopyDC, 0, 0, m_intMainDisplayWidth, m_intMainDisplayHeight, NULL, 0, 0);
}
示例8: Test_Rectangle
void Test_Rectangle(void)
{
HDC hdc;
HBITMAP hBmp;
BOOL ret;
HBRUSH hBrush;
HPEN hPen;
COLORREF color;
hdc = CreateCompatibleDC(NULL);
ok(hdc != NULL, "Failed to create the DC!\n");
hBmp = CreateCompatibleBitmap(hdc, 4, 4);
ok(hBmp != NULL, "Failed to create the Bitmap!\n");
hBmp = SelectObject(hdc, hBmp);
ok(hBmp != NULL, "Failed to select the Bitmap!\n");
hBrush = CreateSolidBrush(RGB(0, 0, 0));
ok(hBrush != NULL, "Failed to create a solid brush!\n");
hBrush = SelectObject(hdc, hBrush);
ok(hBrush != NULL, "Failed to select the brush!\n");
/* Blank the bitmap */
ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
ok(ret, "BitBlt failed to blank the bitmap!\n");
/* Try inverted rectangle coordinates */
ret = Rectangle(hdc, 0, 2, 2, 0);
ok(ret, "Rectangle failed!");
color = GetPixel(hdc, 0, 0);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 0, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 0);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 1, 1);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
ok(ret, "BitBlt failed to blank the bitmap!\n");
/* Try well ordered rectangle coordinates */
ret = Rectangle(hdc, 0, 0, 2, 2);
ok(ret, "Rectangle failed!");
color = GetPixel(hdc, 0, 0);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 0, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 0);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 1, 1);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
/* tests with NULL pen */
hPen = SelectObject(hdc, GetStockObject(NULL_PEN));
/* Blank the bitmap */
ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
ok(ret, "BitBlt failed to blank the bitmap!\n");
ret = Rectangle(hdc, 0, 0, 3, 3);
ok(ret, "Rectangle failed!");
color = GetPixel(hdc, 0, 0);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 0, 2);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 0);
ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 1, 1);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
SelectObject(hdc, hPen);
/* Same tests with GM_ADVANCED */
ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n");
/* Blank the bitmap */
ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
ok(ret, "BitBlt failed to blank the bitmap!\n");
/* Try inverted rectangle coordinates */
ret = Rectangle(hdc, 0, 2, 2, 0);
ok(ret, "Rectangle failed!");
color = GetPixel(hdc, 0, 0);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 2);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 0, 2);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 2, 0);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
color = GetPixel(hdc, 1, 1);
ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
ok(ret, "BitBlt failed to blank the bitmap!\n");
//.........這裏部分代碼省略.........
示例9: mainwnd_proc
// ====================================================
// ウィンドウプロシージャー
// ====================================================
LRESULT CALLBACK mainwnd_proc(HWND hwnd, UINT msgid, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
LPRECT prc;
RECT r;
switch(msgid) {
case WM_MOUSEMOVE: /* マウスカーソル移動 */
gr.mouse_x=LOWORD(lparam); /* マウスカーソルの位置取得 */
gr.mouse_y=HIWORD(lparam);
return 0;
case WM_CREATE:
return 0;
case WM_SIZE:
InvalidateRect(hwnd,NULL,FALSE);
UpdateWindow (hwnd); // 再描畫
// SetWindowPos(hwMain, NULL, 0, 0,
// gr.client_rect.right - gr.client_rect.left,
// gr.client_rect.bottom - gr.client_rect.top,
// SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
return 0;
case WM_SIZING:
prc = (LPRECT) lparam;
switch(wparam) {
case WMSZ_TOP:
case WMSZ_TOPLEFT:
case WMSZ_TOPRIGHT:
case WMSZ_BOTTOMLEFT:
case WMSZ_LEFT:
prc->left = prc->right - (gr.client_rect.right
- gr.client_rect.left);
prc->top = prc->bottom - (gr.client_rect.bottom
- gr.client_rect.top);
break;
case WMSZ_BOTTOM:
case WMSZ_BOTTOMRIGHT:
case WMSZ_RIGHT:
prc->right = prc->left + (gr.client_rect.right
- gr.client_rect.left);
prc->bottom = prc->top + (gr.client_rect.bottom
- gr.client_rect.top);
break;
}
return 0;
case WM_PAINT:
{ int x,y;
GetClientRect(hwnd,&r); /* クライアント領域取得 */
x=(r.right -gr.width) /2; /* ビットマップの表示位置計算 */
y=(r.bottom-gr.height)/2;
hdc=BeginPaint(gr.hwMain,&ps);
BitBlt(hdc,x,y,gr.width,gr.height,gr.hdcMem,0,0,SRCCOPY);
EndPaint(gr.hwMain,&ps);
}
SetEvent(gr.paint_event);
// BringWindowToTop(gr.hwMain);
return 0;
case WM_KEYDOWN:
if(wparam == VK_ESCAPE) {
gr.esc_flag = 1;
gr.end_flag = 1;
SetEvent(gr.esc_event);
}
if(lparam & (1 << 30))
return 0;
if(wparam == VK_F5) {
hdc = GetDC(gr.hwMain);
redraw(hdc, &gr.client_rect);
ReleaseDC(gr.hwMain, hdc);
return 0;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
SetEvent(gr.hitanykey_event);
return 0;
case WM_DESTROY:
DeleteDC(gr.hdcMem); /* デバイスコンテキスト開放 */
gr.hdcMem = NULL;
#if 0
DeleteObject(gr.hBMP); /* ビットマップ開放 */
gr.hBMP = NULL;
if( gr.lpBuf ) {
//.........這裏部分代碼省略.........
示例10: x11_copy_to_screen
/*****************************************************************************
* x11_copy_to_screen
*
* Helper function that blts the front buffer contents to the target window
*
* Params:
* This: Surface to copy from
* rc: Rectangle to copy
*
*****************************************************************************/
void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc)
{
IWineD3DSurfaceImpl *front = This->front_buffer;
if(front->resource.usage & WINED3DUSAGE_RENDERTARGET) {
POINT offset = {0,0};
HWND hDisplayWnd;
HDC hDisplayDC;
HDC hSurfaceDC = 0;
RECT drawrect;
TRACE("(%p)->(%p): Copying to screen\n", front, rc);
hSurfaceDC = front->hDC;
hDisplayWnd = This->win_handle;
hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
if(rc) {
TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
}
/* Front buffer coordinates are screen coordinates. Map them to the destination
* window if not fullscreened
*/
if(This->presentParms.Windowed) {
ClientToScreen(hDisplayWnd, &offset);
}
#if 0
/* FIXME: This doesn't work... if users really want to run
* X in 8bpp, then we need to call directly into display.drv
* (or Wine's equivalent), and force a private colormap
* without default entries. */
if (front->palette) {
SelectPalette(hDisplayDC, front->palette->hpal, FALSE);
RealizePalette(hDisplayDC); /* sends messages => deadlocks */
}
#endif
drawrect.left = 0;
drawrect.right = front->resource.width;
drawrect.top = 0;
drawrect.bottom = front->resource.height;
#if 0
/* TODO: Support clippers */
if (front->clipper)
{
RECT xrc;
HWND hwnd = ((IWineD3DClipperImpl *) front->clipper)->hWnd;
if (hwnd && GetClientRect(hwnd,&xrc))
{
OffsetRect(&xrc,offset.x,offset.y);
IntersectRect(&drawrect,&drawrect,&xrc);
}
}
#endif
if (rc) {
IntersectRect(&drawrect,&drawrect,rc);
}
else {
/* Only use this if the caller did not pass a rectangle, since
* due to double locking this could be the wrong one ...
*/
if (front->lockedRect.left != front->lockedRect.right) {
IntersectRect(&drawrect,&drawrect,&front->lockedRect);
}
}
BitBlt(hDisplayDC,
drawrect.left-offset.x, drawrect.top-offset.y,
drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
hSurfaceDC,
drawrect.left, drawrect.top,
SRCCOPY);
ReleaseDC(hDisplayWnd, hDisplayDC);
}
}
示例11: paintArea
//.........這裏部分代碼省略.........
hdc = BeginPaint(hwnd, &ps);
if (hdc == NULL)
xpanic("error beginning Area repaint", GetLastError());
// very big thanks to Ninjifox for suggesting this technique and helping me go through it
// first let's create the destination image, which we fill with the windows background color
// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
rdc = CreateCompatibleDC(hdc);
if (rdc == NULL)
xpanic("error creating off-screen rendering DC", GetLastError());
// the bitmap has to be compatible with the window
// if we create a bitmap compatible with the DC we just created, it'll be monochrome
// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
rbitmap = CreateCompatibleBitmap(hdc, xrect.right - xrect.left, xrect.bottom - xrect.top);
if (rbitmap == NULL)
xpanic("error creating off-screen rendering bitmap", GetLastError());
prevrbitmap = (HBITMAP) SelectObject(rdc, rbitmap);
if (prevrbitmap == NULL)
xpanic("error connecting off-screen rendering bitmap to off-screen rendering DC", GetLastError());
rrect.left = 0;
rrect.right = xrect.right - xrect.left;
rrect.top = 0;
rrect.bottom = xrect.bottom - xrect.top;
if (FillRect(rdc, &rrect, areaBackgroundBrush) == 0)
xpanic("error filling off-screen rendering bitmap with the system background color", GetLastError());
i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy);
if (i == NULL) // cliprect empty
goto nobitmap; // we need to blit the background no matter what
// now we need to shove realbits into a bitmap
// technically bitmaps don't know about alpha; they just ignore the alpha byte
// AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx
ZeroMemory(&bi, sizeof (BITMAPINFO));
bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bi.bmiHeader.biWidth = (LONG) dx;
bi.bmiHeader.biHeight = -((LONG) dy); // negative height to force top-down drawing;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = (DWORD) (dx * dy * 4);
// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
// now for the trouble: CreateDIBSection() allocates the memory for us...
ibitmap = CreateDIBSection(NULL, // Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
&bi, DIB_RGB_COLORS, &ppvBits, 0, 0);
if (ibitmap == NULL)
xpanic("error creating HBITMAP for image returned by AreaHandler.Paint()", GetLastError());
// now we have to do TWO MORE things before we can finally do alpha blending
// first, we need to load the bitmap memory, because Windows makes it for us
// the pixels are arranged in RGBA order, but GDI requires BGRA
// this turns out to be just ARGB in little endian; let's convert into this memory
dotoARGB(i, (void *) ppvBits, FALSE); // FALSE = not NRGBA
// the second thing is... make a device context for the bitmap :|
// Ninjifox just makes another compatible DC; we'll do the same
idc = CreateCompatibleDC(hdc);
if (idc == NULL)
xpanic("error creating HDC for image returned by AreaHandler.Paint()", GetLastError());
previbitmap = (HBITMAP) SelectObject(idc, ibitmap);
if (previbitmap == NULL)
xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError());
// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
blendfunc.BlendOp = AC_SRC_OVER;
blendfunc.BlendFlags = 0;
blendfunc.SourceConstantAlpha = 255; // only use per-pixel alphas
blendfunc.AlphaFormat = AC_SRC_ALPHA; // premultiplied
if (AlphaBlend(rdc, 0, 0, (int) dx, (int) dy, // destination
idc, 0, 0, (int) dx, (int)dy, // source
blendfunc) == FALSE)
xpanic("error alpha-blending image returned by AreaHandler.Paint() onto background", GetLastError());
// clean up after idc/ibitmap here because of the goto nobitmap
if (SelectObject(idc, previbitmap) != ibitmap)
xpanic("error reverting HDC for image returned by AreaHandler.Paint() to original HBITMAP", GetLastError());
if (DeleteObject(ibitmap) == 0)
xpanic("error deleting HBITMAP for image returned by AreaHandler.Paint()", GetLastError());
if (DeleteDC(idc) == 0)
xpanic("error deleting HDC for image returned by AreaHandler.Paint()", GetLastError());
nobitmap:
// and finally we can just blit that into the window
if (BitBlt(hdc, xrect.left, xrect.top, xrect.right - xrect.left, xrect.bottom - xrect.top,
rdc, 0, 0, // from the rdc's origin
SRCCOPY) == 0)
xpanic("error blitting Area image to Area", GetLastError());
// now to clean up
if (SelectObject(rdc, prevrbitmap) != rbitmap)
xpanic("error reverting HDC for off-screen rendering to original HBITMAP", GetLastError());
if (DeleteObject(rbitmap) == 0)
xpanic("error deleting HBITMAP for off-screen rendering", GetLastError());
if (DeleteDC(rdc) == 0)
xpanic("error deleting HDC for off-screen rendering", GetLastError());
EndPaint(hwnd, &ps);
}
示例12: DrawIconSatnHue
void DrawIconSatnHue (
HDC hDC,
int px,
int py,
HICON IconHop,
int size_x,
int size_y,
UINT istepIfAniCur, // index of frame in animated cursor
HBRUSH hbrFlickerFreeDraw, // handle to background brush
UINT diFlags, // icon-drawing flags
int apply_satnhue,
int saturationValue,
int hueIntensity
)
{
if (0 == apply_satnhue || (saturationValue >= 255 && hueIntensity <= 0)) {
DrawIconEx(hDC, px, py, IconHop, size_x, size_y, istepIfAniCur, hbrFlickerFreeDraw, diFlags);
return;
}
BITMAPINFOHEADER bv4info;
ZeroMemory(&bv4info,sizeof(bv4info));
bv4info.biSize = sizeof(bv4info);
bv4info.biWidth = size_x;
bv4info.biHeight = size_y * 3;
bv4info.biPlanes = 1;
bv4info.biBitCount = 32;
bv4info.biCompression = BI_RGB;
BYTE* pixels;
HBITMAP bufbmp = CreateDIBSection(NULL, (BITMAPINFO*)&bv4info, DIB_RGB_COLORS, (PVOID*)&pixels, NULL, 0);
if (NULL == bufbmp)
return;
HDC bufdc = CreateCompatibleDC(hDC);
HGDIOBJ other = SelectObject(bufdc, bufbmp);
// draw the required three things side by side
// background for hue
BitBlt(bufdc, 0, 0, size_x, size_y, hDC, px, py, SRCCOPY);
// background for icon
BitBlt(bufdc, 0, size_y, size_x, size_y, hDC, px, py, SRCCOPY);
// icon, in colors
DrawIconEx(bufdc, 0, size_y, IconHop, size_x, size_y, 0, NULL, DI_NORMAL);
// icon mask
DrawIconEx(bufdc, 0, size_y*2, IconHop, size_x, size_y, 0, NULL, DI_MASK);
perform_satnhue(pixels, size_x, size_y, saturationValue, hueIntensity);
BitBlt(hDC, px, py, size_x, size_y, bufdc, 0, 0, SRCCOPY);
DeleteObject(SelectObject(bufdc, other));
DeleteDC(bufdc);
}
示例13: WinMain
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE,
LPSTR,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
int width = windowWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
int height = windowHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"IF, THEN", /* Title Text */
WS_CAPTION, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
width, /* The programs width */
height, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, SW_SHOW);
/* Run the message loop. It will run until GetMessage() returns 0 */
HDC hdc = GetDC(hwnd);
hBufferDC = CreateCompatibleDC(hdc);
hBufferBmp = CreateCompatibleBitmap(hdc, windowWidth, windowHeight);
hOldBufferBmp = (HBITMAP)SelectObject(hBufferDC, hBufferBmp);
DWORD lastTime = GetTickCount();
NextLevel();
while (!bGameOver)
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
bGameOver = true;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (bGameOver)
break;
if (GetAsyncKeyState(VK_ESCAPE))
break;
updateGame();
PaintGame(hBufferDC);
BitBlt(hdc, 0, 0, windowWidth, windowHeight, hBufferDC, 0, 0, SRCCOPY);
do
Sleep(0);
while (GetTickCount() - lastTime < 15);
lastTime = GetTickCount();
}
SelectObject(hBufferDC, hOldBufferBmp);
DeleteObject(hBufferBmp);
DeleteObject(hBufferDC);
ReleaseDC(hwnd, hdc);
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return 0;
}
示例14: CreateDC
HBITMAP CSplashScreen::CopyScreenToBitmap(CRect& rect/*lpRect 代表選定區域*/)
{
HDC hScrDC; // 屏幕設備描述表
HDC hMemDC; // 內存設備描述表
HBITMAP hBitmap, hOldBitmap; // 位圖句柄
int nX, nY, nX2, nY2; // 選定區域坐標
int nWidth, nHeight; // 位圖寬度和高度
int xScrn, yScrn; // 屏幕分辨率
// 確保選定區域不為空矩形
//if (IsRectEmpty(lpRect))
//{
// return NULL;
//}
//為屏幕創建設備描述表
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
//為屏幕設備描述表創建兼容的內存設備描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 獲得選定區域坐標
//nX = lpRect -> left;
//nY = lpRect -> top;
//nX2 = lpRect -> right;
//nY2 = lpRect -> bottom;
nX = rect.left;
nY = rect.top;
nX2 = rect.right;
nY2 = rect.bottom;
// 獲得屏幕分辨率
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//nX = (xScrn - rect.Width())/2;
//nY = (yScrn - rect.Height())/2;
//nX2 = xScrn - nX + rect.Width();
//nY2 = yScrn - nY + rect.Height();
//確保選定區域是可見的
if (nX<0)
nX = 0;
if (nY<0)
nY = 0;
if (nX2 > xScrn)
nX2 = xScrn;
if (nY2 > yScrn)
nY2 = yScrn;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
// 創建一個與屏幕設備描述表兼容的位圖
hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
// 把新位圖選到內存設備描述表中
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
// 把屏幕設備描述表拷貝到內存設備描述表中
BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);
//得到屏幕位圖的句柄
hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
//清除
DeleteDC(hScrDC);
DeleteDC(hMemDC);
//返回位圖句柄
return hBitmap;
}
示例15: dc
void CSplashScreen::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC dcMem;
GetWindowRect(&rect);//獲得要抓圖的區域
m_hbm = CopyScreenToBitmap(rect);//抓圖
GetObject(m_hbm, sizeof(m_bitmap),&m_bitmap);//獲得抓到的圖的尺寸
if (dcMem.CreateCompatibleDC(&dc))
{
SelectObject(dcMem, m_hbm);
BitBlt(dc,0,0,m_bitmap.bmWidth, m_bitmap.bmHeight, dcMem,0 ,0, SRCCOPY);
//m_image->Draw(dc.m_hDC,m_bitmap.bmWidth/2 - 380/2,m_bitmap.bmHeight/2 - 350/2,380,350);
m_image->Draw(dc.m_hDC, m_rtImg.left, m_rtImg.top, -1, -1);
DrawText(&dc);
//CRect rc(0, m_bitmap.bmHeight/2 + 70, m_bitmap.bmWidth ,m_bitmap.bmHeight);
//LOGFONT lf = {0};
//lf.lfHeight = 26;
//lf.lfWeight = FW_BOLD;
//lf.lfQuality = afxData.bWin95 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY;
//_tcscpy(lf.lfFaceName, _T("Arial"));
//
//CFont font;
//font.CreateFontIndirect(&lf);
//CFont* pOldFont = dc.SelectObject(&font);
//CString strAppVersion;
//strAppVersion.Format(_T("eMule %u.%u%c VeryCD"), CGlobalVariable::m_nVersionMjr, CGlobalVariable::m_nVersionMin, _T('a') + CGlobalVariable::m_nVersionUpd);
//
//rc.top += 30;
//rc.top += dc.DrawText(strAppVersion, &rc, DT_CENTER | DT_NOPREFIX);
//if (pOldFont)
//{
// dc.SelectObject(pOldFont);
//}
//font.DeleteObject();
//rc.top += 8;
//lf.lfHeight = 14;
//lf.lfWeight = FW_NORMAL;
//lf.lfQuality = afxData.bWin95 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY;
//_tcscpy(lf.lfFaceName, _T("Arial"));
//font.CreateFontIndirect(&lf);
//pOldFont = dc.SelectObject(&font);
//dc.DrawText(_T("Copyright (C) 2002-2006 Merkur"), &rc, DT_CENTER | DT_NOPREFIX);
//if (pOldFont)
//{
// dc.SelectObject(pOldFont);
//}
//font.DeleteObject();
}
}