void DrawBitmap(HDC hdc, int x, int y, HBITMAP hBitmap) { HBITMAP hOldbm; HDC hMemDC; BITMAP bm; POINT ptSize, ptOrg; hMemDC = CreateCompatibleDC(hdc); hOldbm = (HBITMAP)SelectObject(hMemDC, hBitmap); if (hOldbm) { SetMapMode(hMemDC, GetMapMode(hdc)); GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize, 1); ptOrg.x = 0; ptOrg.y = 0; DPtoLP(hMemDC, &ptOrg, 1); BitBlt(hdc, x, y, ptSize.x, ptSize.y, hMemDC, ptOrg.x, ptOrg.y, SRCCOPY); SelectObject(hMemDC, hOldbm); } DeleteDC(hMemDC); }
/* WinDrawBitmap must be used for drawing bitmaps on screen. For reasons of efficiency it uses memory device context, BitBlt, and bitmap handle. */ void WinDrawBitmap (int w, int h, int destx, int desty, HBITMAP hbmp, OSPictContext context ) { HDC compatibleDC; POINT size, origin, dest; HGDIOBJ prevObj; size.x = w; size.y = h; origin.x = 0; origin.y = 0; dest.x = destx; dest.y = desty; // Create a compatible device context compatibleDC = CreateCompatibleDC (context->hDC); if (compatibleDC == NULL) rMessageBox (NULL,MB_APPLMODAL,"WinDrawBitmap","CreateCompatibleDC failed"); // Select bitmap into compatible device context prevObj = SelectObject (compatibleDC, hbmp); SetMapMode (compatibleDC, GetMapMode (context->hDC)); DPtoLP (context->hDC, &size, 1); DPtoLP (context->hDC, &dest, 1); DPtoLP (compatibleDC, &origin, 1); BitBlt (context->hDC, dest.x, dest.y, size.x, size.y, compatibleDC, origin.x, origin.y, SRCCOPY); SelectObject (compatibleDC, prevObj); DeleteDC (compatibleDC); } /* WinDrawBitmap */
// petzold, pp 621-622 void DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart) { BITMAP bm; HDC hdcMem; POINT ptSize, ptOrg; hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, hBitmap); SetMapMode(hdcMem, GetMapMode(hdc)); GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize, 1); ptOrg.x = 0; ptOrg.y = 0; DPtoLP(hdcMem, &ptOrg, 1); BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y, SRCCOPY); DeleteDC(hdcMem); }
static void DrawBitmap(HDC hdc, HBITMAP hBitmap, int x, int y, int rop) { BITMAP bm; HDC hdcMem; POINT ptSize, ptOrg; HBITMAP tmp; ASSERT(hdc != NULL); ASSERT(hBitmap != NULL); hdcMem = CreateCompatibleDC(hdc); ASSERT(hdcMem != NULL); CHECK_RETURN(tmp = SelectObject(hdcMem, hBitmap)); SetMapMode(hdcMem, GetMapMode(hdc)); GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize, 1); ptOrg.x = 0; ptOrg.y = 0; DPtoLP(hdcMem, &ptOrg, 1); BitBlt(hdc, x, y, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y, rop); SelectObject(hdcMem, tmp); DeleteDC(hdcMem); }
void DrawMinimizeBox ( TDialog * Dialog, BOOL pressed ) { int BitmapId ; // Ne dessiner le bouton que si son état a changé if ( pressed ) BitmapId = OBM_REDUCED ; else BitmapId = OBM_REDUCE ; // Charger la bitmap prédéfinie HDC WindowDC, MemDC ; HBITMAP HBitmap ; POINT PObjectPlacement, PSize, POrigin ; BITMAP BitmapInfo ; WindowDC = GetWindowDC ( Dialog -> HWindow ) ; MemDC = CreateCompatibleDC ( WindowDC ) ; HBitmap = LoadBitmap ( NULL, ( LPSTR ) BitmapId ) ; if ( HBitmap == NULL ) { DeleteDC ( MemDC ) ; ReleaseDC ( Dialog -> HWindow, WindowDC ) ; return ; } SelectObject ( MemDC, HBitmap ) ; SetMapMode ( MemDC, GetMapMode ( WindowDC ) ) ; GetObject ( HBitmap, sizeof ( BITMAP ), ( LPSTR ) & BitmapInfo ) ; PSize. x = BitmapInfo. bmWidth ; PSize. y = BitmapInfo. bmHeight ; DPtoLP ( WindowDC, & PSize, 1 ) ; POrigin. x = POrigin. y = 0 ; DPtoLP ( MemDC, & POrigin, 1 ) ; GetObjectOrigin ( Dialog, WS_MINIMIZEBOX, PObjectPlacement, PSize ) ; BitBlt ( WindowDC, PObjectPlacement. x, PObjectPlacement. y, PSize. x, PSize. y, MemDC, POrigin. x, POrigin. y, SRCCOPY ) ; // Ménage DeleteDC ( MemDC ) ; DeleteObject ( HBitmap ) ; ReleaseDC ( Dialog -> HWindow, WindowDC ) ; }
// Generic algorithm for axes display: width height in device coordinate void ShowAxes(HDC hDC, int width, int height) { POINT corner[2]; // display axes for the area [10, 10, width-10, height-10] corner[0].x = 10; corner[0].y = 10; corner[1].x = width - 10; corner[1].y = height - 10; // covert to logical coordinate DPtoLP(hDC, corner, 2); // we need to display a 10x2 point arrow, convert to device coordinate, then to logical SIZE s = { 10, 2 }; PointToDevice(hDC, s); DeviceToLogical(hDC, s); // X-axis Arrow(hDC, min(corner[0].x, corner[1].x), 0, max(corner[0].x, corner[1].x), 0, s.cx, s.cy); // Y-axis Arrow(hDC, 0, min(corner[0].y, corner[1].y), 0, max(corner[0].y, corner[1].y), s.cx, s.cy); }
//================================================================================================ //--------------------------------------------------------------+++--> Create a Font For the Clock: HFONT CreateMyFont(char* fontname, int fontsize, LONG weight, LONG italic, int angle) { //--+++--> LOGFONT lf; POINT pt; HDC hdc; WORD langid; char s[11]; int cp, i; BYTE charset; int FontQty; memset(&lf, 0, sizeof(LOGFONT)); langid = (WORD)GetMyRegLong("Format", "Locale", (int)GetUserDefaultLangID()); FontQty = GetMyRegLong("Clock", "FontQuality", CLEARTYPE_QUALITY); cp = CP_ACP; if(GetLocaleInfo(langid, LOCALE_IDEFAULTANSICODEPAGE, s, 10) > 0) { char *p; p = s; cp = 0; while('0' <= *p && *p <= '9') cp = cp * 10 + *p++ - '0'; if(!IsValidCodePage(cp)) cp = CP_ACP; } charset = 0; for(i = 0; codepage_charset[i].cp; i++) { if(cp == codepage_charset[i].cp) { charset = codepage_charset[i].charset; break; } } hdc = GetDC(NULL); // find a font named "fontname" if(charset == 0) charset = GetTextCharset(hdc); lf.lfCharSet = charset; if(EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0)) { lf.lfCharSet = OEM_CHARSET; if(EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0)) { lf.lfCharSet = ANSI_CHARSET; EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0); } } pt.x = 0; pt.y = MulDiv(fontsize, GetDeviceCaps(hdc, LOGPIXELSY), 72); DPtoLP(hdc, &pt, 1); lf.lfHeight = -pt.y; ReleaseDC(NULL, hdc); lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0; lf.lfWeight = weight; lf.lfItalic = (BYTE)italic; lf.lfUnderline = 0; lf.lfStrikeOut = 0; if(angle >0) lf.lfEscapement = angle; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = FontQty; // This Just HAD To be Adjustable. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; strcpy(lf.lfFaceName, fontname); return CreateFontIndirect(&lf); }
void CDC::HIMETRICtoLP(LPSIZE lpSize) const { ASSERT(AfxIsValidAddress(lpSize, sizeof(SIZE))); HIMETRICtoDP(lpSize); DPtoLP(lpSize); }
void CDC::DPtoHIMETRIC(LPSIZE lpSize) const { ASSERT(AfxIsValidAddress(lpSize, sizeof(SIZE))); int nMapMode; if (this != NULL && (nMapMode = GetMapMode()) < MM_ISOTROPIC && nMapMode != MM_TEXT) { // when using a constrained map mode, map against physical inch ((CDC*)this)->SetMapMode(MM_HIMETRIC); DPtoLP(lpSize); ((CDC*)this)->SetMapMode(nMapMode); } else { // map against logical inch for non-constrained mapping modes int cxPerInch, cyPerInch; if (this != NULL) { ASSERT_VALID(this); ASSERT(m_hDC != NULL); // no HDC attached or created? cxPerInch = GetDeviceCaps(LOGPIXELSX); cyPerInch = GetDeviceCaps(LOGPIXELSY); } else { cxPerInch = afxData.cxPixelsPerInch; cyPerInch = afxData.cyPixelsPerInch; } ASSERT(cxPerInch != 0 && cyPerInch != 0); lpSize->cx = MulDiv(lpSize->cx, HIMETRIC_INCH, cxPerInch); lpSize->cy = MulDiv(lpSize->cy, HIMETRIC_INCH, cyPerInch); } }
static void handleLButtonDown(HWND hDlg, LPARAM lParam) { SetCapture(hDlg); /* Get the (x,y) of the pointer when the left * mouse button is pressed. */ ptBegin.x = LOWORD(lParam); ptBegin.y = HIWORD(lParam); DPtoLP(hdc, &ptBegin, 1); //ScreenToClient(hDlg,&ptBegin); if(ptBegin.x <= maxSize && ptBegin.x >= 0 && ptBegin.y <= maxSize && ptBegin.y >= 0 ) { ptOld = ptBegin; inside = TRUE; } else { inside = FALSE; } } /* close handleMouseDown() */
void View::InitView (FP xmin, FP xmax, FP ymin, FP ymax) { HDC hdc; RECT rect; POINT client; hdc = GetDC (hWnd); GetClientRect (hWnd, &rect); client.x = rect.right - rect.left; client.y = rect.bottom - rect.top; DPtoLP (hdc, &client, 1); ReleaseDC (hWnd, hdc); MaxScalex = (xmax - xmin) / (client.x * 0.75); MaxScaley = (ymin - ymax) / (client.y * 0.75); Scalex = MaxScalex; Scaley = MaxScaley; Org.x = (client.x * 0.125) - (xmin / MaxScalex); Org.y = (client.y * 0.875) - (ymin / MaxScaley); }
HFONT CreFntFix (HDC hDC, WORD usPntSiz, RECT rCltRec) { WORD usWrkSiz; WORD usLogExt; WORD usDevExt; HFONT hFixFnt; /********************************************************************/ /********************************************************************/ if (0 == (usDevExt = rCltRec.bottom)) return (NULL); DPtoLP (hDC, (LPPOINT) &rCltRec, 2); usLogExt = abs (rCltRec.top - rCltRec.bottom); /********************************************************************/ /* Point size in logical points: */ /* = (PntSiz * DevPnt/inch * 1/72 in/pt) * LogPnt/DevPnt */ /********************************************************************/ usWrkSiz = (WORD) (((DWORD) usPntSiz * (DWORD) GetDeviceCaps (hDC, LOGPIXELSY) * (DWORD) usLogExt) / (72L * (DWORD) usDevExt)); /********************************************************************/ /* Create font using size without descent */ /********************************************************************/ hFixFnt = CreateFont (- (short) usWrkSiz, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, 0, 0, DEFAULT_QUALITY, FF_MODERN, (LPSTR) FNTFIXNAM); return (hFixFnt); }
static void PaintBlock(HWND hwnd) { HDC hdc, hdcMem; HBITMAP hBitmap, oldhBitmap; BITMAP bm; POINT ptSize; HPALETTE old_hpal; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); hBitmap = LoadBitmap((HINSTANCE)GetWindowLong(hCtrlBlock, GWL_HINSTANCE), "AboutBMP"); if (calife_list->numcolor() == 256) { old_hpal = SelectPalette(hdc, calife_list->hpal(), 0); RealizePalette(hdc); } hdcMem = CreateCompatibleDC(hdc); oldhBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap); GetObject(hBitmap, sizeof (BITMAP), (LPSTR) &bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize, 1); BitBlt(hdc, 0, 0, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY); if (calife_list->numcolor() == 256) SelectPalette(hdc, old_hpal, 0); SelectObject(hdcMem, oldhBitmap); DeleteDC(hdcMem); ReleaseDC(hCtrlBlock, hdc); DeleteObject(hBitmap); EndPaint(hwnd, &ps); }
/* * @implemented * */ BOOL WINAPI GetCurrentPositionEx(HDC hdc, LPPOINT lpPoint) { PDC_ATTR Dc_Attr; if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE; if ( lpPoint ) { if ( Dc_Attr->ulDirty_ & DIRTY_PTLCURRENT ) // have a hit! { lpPoint->x = Dc_Attr->ptfxCurrent.x; lpPoint->y = Dc_Attr->ptfxCurrent.y; DPtoLP ( hdc, lpPoint, 1); // reconvert back. Dc_Attr->ptlCurrent.x = lpPoint->x; // save it Dc_Attr->ptlCurrent.y = lpPoint->y; Dc_Attr->ulDirty_ &= ~DIRTY_PTLCURRENT; // clear bit } else { lpPoint->x = Dc_Attr->ptlCurrent.x; lpPoint->y = Dc_Attr->ptlCurrent.y; } } else { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } return TRUE; }
/*********************************************************************** * GetClipBox (GDI32.@) */ INT WINAPI GetClipBox( HDC hdc, LPRECT rect ) { RECT visrect; INT ret; DC *dc = get_dc_ptr( hdc ); if (!dc) return ERROR; update_dc( dc ); if (get_dc_region( dc )) { ret = GetRgnBox( get_dc_region( dc ), rect ); } else { ret = is_rect_empty( &dc->vis_rect ) ? ERROR : SIMPLEREGION; *rect = dc->vis_rect; } if (get_dc_device_rect( dc, &visrect ) && !intersect_rect( rect, rect, &visrect )) ret = NULLREGION; if (dc->layout & LAYOUT_RTL) { int tmp = rect->left; rect->left = rect->right - 1; rect->right = tmp - 1; } DPtoLP( hdc, (LPPOINT)rect, 2 ); release_dc_ptr( dc ); TRACE("%p => %d %s\n", hdc, ret, wine_dbgstr_rect( rect )); return ret; }
void SetHIMETRICtoDP(HDC hdc, SIZE* sz) { POINT pt; int nMapMode = GetMapMode(hdc); if (nMapMode < MM_ISOTROPIC && nMapMode != MM_TEXT) { // when using a constrained map mode, map against physical inch SetMapMode(hdc, MM_HIMETRIC); pt.x = sz->cx; pt.y = sz->cy; LPtoDP(hdc, &pt, 1); sz->cx = pt.x; sz->cy = pt.y; SetMapMode(hdc, nMapMode); } else { // map against logical inch for non-constrained mapping modes int cxPerInch, cyPerInch; cxPerInch = GetDeviceCaps(hdc, LOGPIXELSX); cyPerInch = GetDeviceCaps(hdc, LOGPIXELSY); sz->cx = MulDiv(sz->cx, cxPerInch, HIMETRIC_INCH); sz->cy = MulDiv(sz->cy, cyPerInch, HIMETRIC_INCH); } pt.x = sz->cx; pt.y = sz->cy; DPtoLP(hdc, &pt, 1); sz->cx = pt.x; sz->cy = pt.y; }
void View::GetLimits (FP& x1, FP& x2, FP& y1, FP& y2) { HDC hdc; RECT rect; POINT client; hdc = GetDC (hWnd); GetClientRect (hWnd, &rect); client.x = rect.right - rect.left; client.y = rect.bottom - rect.top; DPtoLP (hdc, &client, 1); ReleaseDC (hWnd, hdc); POINT p1,p2; p1.x = client.x * 0.125; p1.y = client.y * 0.125; GetWorldPos (p1, x1, y2); p2.x = client.x * 0.875; p2.y = client.y * 0.875; GetWorldPos (p2, x2, y1); }
static void setup_clipping( HWND hwnd, HDC hdc ) { RECT rc; GetClientRect( hwnd, &rc ); DPtoLP( hdc, (POINT *)&rc, 2 ); IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom ); }
/*********************************************************************** * ICONTITLE_Paint */ static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive ) { RECT rect; HFONT hPrevFont; HBRUSH hBrush; COLORREF textColor = 0; if( bActive ) { hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION); textColor = GetSysColor(COLOR_CAPTIONTEXT); } else { if( GetWindowLongPtrA( hwnd, GWL_STYLE ) & WS_CHILD ) { hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND); if( hBrush ) { INT level; LOGBRUSH logBrush; GetObjectA( hBrush, sizeof(logBrush), &logBrush ); level = GetRValue(logBrush.lbColor) + GetGValue(logBrush.lbColor) + GetBValue(logBrush.lbColor); if( level < (0x7F * 3) ) textColor = RGB( 0xFF, 0xFF, 0xFF ); } else hBrush = GetStockObject( WHITE_BRUSH ); } else { hBrush = GetStockObject( BLACK_BRUSH ); textColor = RGB( 0xFF, 0xFF, 0xFF ); } } GetClientRect( hwnd, &rect ); DPtoLP( hDC, (LPPOINT)&rect, 2 ); FillRect( hDC, &rect, hBrush ); hPrevFont = SelectObject( hDC, hIconTitleFont ); if( hPrevFont ) { WCHAR buffer[80]; INT length = GetWindowTextW( owner, buffer, sizeof(buffer)/sizeof(buffer[0]) ); SetTextColor( hDC, textColor ); SetBkMode( hDC, TRANSPARENT ); DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) ); SelectObject( hDC, hPrevFont ); } return (hPrevFont != 0); }
// Convert size in device coordinate to logical coordinate void DeviceToLogical(HDC hDC, SIZE & size) { POINT p[2] = { 0, 0, size.cx, size.cy }; DPtoLP(hDC, p, 2); size.cx = abs(p[1].x - p[0].x); size.cy = abs(p[1].y - p[0].y); }
// This function clears the graphics screen (with the background color) and // moves the current point to (0,0) // void cleardevice( ) { HDC hDC; WindowData* pWndData = BGI__GetWindowDataPtr( ); int color; // Background color to fill with RECT rect; // The rectangle to fill HRGN hRGN; // The clipping region (if any) int is_rgn; // Whether or not a clipping region is present POINT p; // Upper left point of window (convert from device to logical points) HBRUSH hBrush; // Brush in the background color // Convert from BGI color to RGB color color = converttorgb( pWndData->bgColor ); hDC = BGI__GetWinbgiDC( ); // Even though a viewport may be set, this function clears the entire screen. // Compute the origin in logical coordinates. p.x = 0; p.y = 0; DPtoLP( hDC, &p, 1 ); rect.left = p.x; rect.top = p.y; rect.right = pWndData->width; rect.bottom = pWndData->height; // Get the current clipping region, if any. The region object must first // be created with some valid region. If the GetClipRgn function // succeeds, the region info will be updated to reflect the new region. // However, this does not create a new region object. That is, this // simply overwrites the memory of the old region object and we don't have // to worry about deleting the old region. hRGN = CreateRectRgn( 0, 0, 5, 5 ); is_rgn = GetClipRgn( hDC, hRGN ); // If there is a clipping region, select none if ( is_rgn != 0 ) SelectClipRgn( hDC, NULL ); // Fill hDC with background color hBrush = CreateSolidBrush( color ); FillRect( hDC, &rect, hBrush ); DeleteObject( hBrush ); // Move the CP back to (0,0) (NOT viewport relative) moveto( p.x, p.y ); // Select the old clipping region back into the device context if ( is_rgn != 0 ) SelectClipRgn( hDC, hRGN ); // Delete the region DeleteRgn( hRGN ); BGI__ReleaseWinbgiDC( ); RefreshWindow( NULL ); }
HFONT CRetrySplashScreen::CreateDialogFont (HDC hdc, TCHAR *szFaceName, int ptSize, DWORD dwWeight, BOOL bUnderline) { POINT pt; FLOAT cxDPI, cyDPI; HFONT hFont; LOGFONT lf; int iDeciPtWidth = 0; int iDeciPtHeight = 10 * ptSize; int iSavedDC = SaveDC(hdc); SetGraphicsMode (hdc, GM_ADVANCED); ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); SetViewportOrgEx (hdc, 0,0, NULL); SetWindowOrgEx (hdc, 0,0, NULL); cxDPI = (FLOAT) GetDeviceCaps(hdc, LOGPIXELSX); cyDPI = (FLOAT) GetDeviceCaps(hdc, LOGPIXELSY); pt.x = (int) (iDeciPtWidth * cxDPI / 72); pt.y = (int) (iDeciPtHeight * cyDPI / 72); DPtoLP(hdc, &pt, 1); lf.lfHeight = - (int) (fabs ((double) pt.y) / 10.0 + 0.5); lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = dwWeight; lf.lfItalic = 0; lf.lfUnderline = (bUnderline ? 1 : 0); lf.lfStrikeOut = 0; lf.lfCharSet = 0; lf.lfOutPrecision = 0; lf.lfClipPrecision = 0; lf.lfQuality = 0; lf.lfPitchAndFamily = 0; TCHAR szLocaleData[BUFFER_SIZE]; int iRet = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGCOUNTRY, szLocaleData, BUFFER_SIZE); if (strncmp(szLocaleData, "Japan", 5) != 0){ strcpy (lf.lfFaceName, szFaceName); } else { strcpy (lf.lfFaceName, TEXT("MS UI Gothic")); } hFont = CreateFontIndirect(&lf); RestoreDC (hdc, iSavedDC); return hFont; }
static void DrawMdiIcon( HDC hdc, an_MDI_icon *MDI_icon, RECT *r ) { BITMAP bm; HDC memDC; POINT src_org, src_size; POINT dst_org, dst_size; dst_size.y = r->bottom - r->top + 1; dst_size.x = r->right - r->left + 1; DPtoLP( hdc, &dst_size, 1 ); dst_org.x = r->left; dst_org.y = r->top; DPtoLP( hdc, &dst_org, 1 ); GetObject( MDI_icon->AND_bitmap, sizeof( BITMAP ), (LPSTR) &bm ); memDC = CreateCompatibleDC( hdc ); SelectObject( memDC, MDI_icon->AND_bitmap ); src_size.x = bm.bmWidth; src_size.y = bm.bmHeight; DPtoLP( hdc, &src_size, 1 ); src_org.x = 0; src_org.y = 0; DPtoLP( hdc, &src_org, 1 ); StretchBlt( hdc, dst_org.x, dst_org.y, dst_size.x, dst_size.y, memDC, src_org.x, src_org.y, src_size.x, src_size.y, SRCAND ); SelectObject( memDC, MDI_icon->XOR_bitmap ); StretchBlt( hdc, dst_org.x, dst_org.y, dst_size.x, dst_size.y, memDC, src_org.x, src_org.y, src_size.x, src_size.y, SRCCOPY ); DeleteDC( memDC ); } /* DrawMdiIcon */
void Show(HWND hwnd, HDC hdc, int xText, int yText, int iMapMode, TCHAR *szMapMode) { TCHAR szBuffer[60]; RECT rect; SaveDC(hdc); SetMapMode(hdc, iMapMode); GetClientRect(hwnd, &rect); DPtoLP(hdc, (PPOINT)&rect, 2); RestoreDC(hdc, -1); TextOut(hdc, xText, yText, szBuffer, wsprintf(szBuffer, TEXT("%-20s %7d %7d %7d %7d"), szMapMode, rect.left, rect.right, rect.top, rect.bottom)); }
/* * display a bitmap on the given DC, at device coordinates x,y * make the bitmap the same size as the source bitmap */ static void DrawBitmap( HDC hdc, HBITMAP bitmap, short x, short y ) /*****************************************************************/ { BITMAP bitmapbuff; HDC memorydc; POINT origin; POINT size; memorydc = CreateCompatibleDC( hdc ); SelectObject( memorydc, bitmap ); SetMapMode( memorydc, GetMapMode( hdc ) ); GetObject( bitmap, sizeof( BITMAP ), (LPSTR) &bitmapbuff ); origin.x = x; origin.y = y; size.x = bitmapbuff.bmWidth; size.y = bitmapbuff.bmHeight; DPtoLP( hdc, &origin, 1 ); DPtoLP( memorydc, &size, 1 ); BitBlt( hdc, origin.x, origin.y, size.x, size.y, memorydc, 0, 0, SRCCOPY); DeleteDC( memorydc ); } /* DrawBitmap */
static void handleLButtonUp(HWND hDlg, LPARAM lParam) { #if OPENGL double p1x,p1y,p2x,p2y; float red, green, blue; #endif /* These two lines are the only real platform dependent code in here. * Once the mouse position is grabbed, the math is similar. */ ptNew.x = LOWORD(lParam); ptNew.y = HIWORD(lParam); DPtoLP(hdc, &ptNew, 1); /* We insist on actually being inside the drawing area... */ if(ptNew.x <= maxSize && ptNew.x >= 0 && ptNew.y <= maxSize && ptNew.y >= 0 && inside) { SetROP2(hdc, R2_COPYPEN); SelectObject(hdc, hCurrentPen); /* TODO: Turn this into a swicth on tool. */ if(tool==joint) addJoint(hDlg); else if (tool==fixedpoint || tool==loadpoint) addTriangle(hDlg); else if (tool==measpoint || tool==holepoint) addCircle(hDlg); } else /* outside drawing area */ { SetROP2(hdc, R2_NOT); if(!tool && inside) { MoveToEx(hdc, ptBegin.x, ptBegin.y, NULL); LineTo(hdc, ptOld.x, ptOld.y); } } ReleaseCapture(); // ReleaseDC(hDlg, hdc); } /* close handleMouseUp() */
void Map10umToLogical(HDC hDC, RECT & rect) { POINT * pPoint = (POINT *) & rect; // convert from 0.01 mm to pixels for current device for (int i=0; i<2; i++) { int t = GetDeviceCaps(hDC, HORZSIZE) * 100; pPoint[i].x = ( pPoint[i].x * GetDeviceCaps(hDC, HORZRES) + t/2 ) / t; t = GetDeviceCaps(hDC, VERTSIZE) * 100; pPoint[i].y = ( pPoint[i].y * GetDeviceCaps(hDC, VERTRES) + t/2 ) / t; } // convert to logical coordinate space DPtoLP(hDC, pPoint, 2); }
/*********************************************************************** * GetClipBox (GDI32.@) */ INT WINAPI GetClipBox( HDC hdc, LPRECT rect ) { INT ret; HRGN clip; DC *dc = DC_GetDCUpdate( hdc ); if (!dc) return ERROR; if ((clip = get_clip_region(dc))) { HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 ); CombineRgn( hrgn, dc->hVisRgn, clip, RGN_AND ); ret = GetRgnBox( hrgn, rect ); DeleteObject( hrgn ); } else ret = GetRgnBox( dc->hVisRgn, rect ); DPtoLP( hdc, (LPPOINT)rect, 2 ); GDI_ReleaseObj( hdc ); return ret; }
/*********************************************************************** * set_control_clipping * * Set clipping for a builtin control that uses CS_PARENTDC. * Return the previous clip region if any. */ HRGN set_control_clipping( HDC hdc, const RECT *rect ) { RECT rc = *rect; HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 ); if (GetClipRgn( hdc, hrgn ) != 1) { DeleteObject( hrgn ); hrgn = 0; } DPtoLP( hdc, (POINT *)&rc, 2 ); if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */ { rc.left++; rc.right++; } IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom ); return hrgn; }
BOOL WINAPI MoveToEx( _In_ HDC hdc, _In_ INT x, _In_ INT y, _Out_opt_ LPPOINT ppt) { PDC_ATTR pdcattr; HANDLE_METADC(BOOL, MoveTo, FALSE, hdc, x, y, ppt); /* Get the DC attribute */ pdcattr = GdiGetDcAttr(hdc); if (pdcattr == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } if (ppt) { if ( pdcattr->ulDirty_ & DIRTY_PTLCURRENT ) // Double hit! { ppt->x = pdcattr->ptfxCurrent.x; // ret prev before change. ppt->y = pdcattr->ptfxCurrent.y; DPtoLP (hdc, ppt, 1); // reconvert back. } else { ppt->x = pdcattr->ptlCurrent.x; ppt->y = pdcattr->ptlCurrent.y; } } pdcattr->ptlCurrent.x = x; pdcattr->ptlCurrent.y = y; pdcattr->ulDirty_ &= ~DIRTY_PTLCURRENT; pdcattr->ulDirty_ |= ( DIRTY_PTFXCURRENT|DIRTY_STYLESTATE); // Set dirty return TRUE; }