///////////////////////////////////////////////////////////////////// // TMapDC // ------ // void TMapDC::SetupOrg() { #ifdef WINDOWS_SCALING // Set window and viewport scale and extension SetMapMode (MM_ANISOTROPIC); SetViewportOrg (TPoint(ScrCenterX, ScrCenterY)); SetWindowOrg (TPoint(OrigX, OrigY)) ; if ( Scale > 1.0 ) { // dc.SetWindowExt (TSize(ScrMaxX, ScrMaxY)); // dc.SetViewportExt (TSize(ScrMaxX * MUL_SCALE, -ScrMaxY * MUL_SCALE)); SetWindowExt (TSize(1, 1)); SetViewportExt (TSize(MUL_SCALE, -MUL_SCALE)); } else if (Scale <= 1.0 ) { SetWindowExt (TSize(ScrMaxX * DIV_SCALE, ScrMaxY * DIV_SCALE)); SetViewportExt (TSize(ScrMaxX, -ScrMaxY)); } /* for (int x = MIN_MAP_X ; x <= MAX_MAP_X ; x+=1000) for (SHORT y = MIN_MAP_Y ; y <= MAX_MAP_Y ; y+=1000) { char msg[80]; wsprintf (msg,"(%d:%d)", x/1000, y/1000); dc.TextOut (x, y, msg); } */ #endif }
//KMemDC KMemDC::KMemDC(HDC hDC, const RECT* pRect):KDC(){ assert(hDC!=NULL); // Some initialization m_hDCPaint=hDC; // Get the rectangle to draw if(!pRect) ::GetClipBox(hDC,&m_rect); else m_rect=*pRect; // Create a Memory DC CreateCompatibleDC(hDC); ::LPtoDP(hDC,(POINT*)(&m_rect),2); m_bitmap=::CreateCompatibleBitmap(hDC, m_rect.right-m_rect.left,m_rect.bottom-m_rect.top); m_oldBitmap=(HBITMAP)SelectObject(m_bitmap); SetMapMode(::GetMapMode(hDC)); SIZE size; ::GetWindowExtEx(hDC,&size); SetWindowExt(size); ::GetViewportExtEx(hDC,&size); SetViewportExt(size); ::DPtoLP(hDC,(POINT*)(&m_rect),2); SetWindowOrg(m_rect.left, m_rect.top); // Fill background FillSolidRect(&m_rect, ::GetBkColor(hDC)); }
/* * PaintMonitor - redraw the monitor window */ static void PaintMonitor( HWND hwnd, HDC dc, LocalMonInfo *info ) { RECT area; WORD i; char buf[80]; WORD xpos, ypos; HBRUSH white; SaveDC( dc ); GetClientRect( hwnd, &area ); white = GetStockObject( WHITE_BRUSH ); FillRect( dc, &area, white ); SetMapMode( dc, MM_ANISOTROPIC ); SetWindowOrg( dc, 0, 0 ); SetWindowExt( dc, MONITOR_WIDTH, MONITOR_HITE ); SetViewportOrg( dc, 0, 0 ); SetViewportExt( dc, area.right, area.bottom ); area.top = BAR_HITE; area.bottom = 2 * BAR_HITE; area.left = BAR_XPOS; for( i=0; i < SIZE_CNT; i++ ) { if( info->sizes[i] == 0 ) continue; area.right = area.left + SECTION_WIDTH( info->sizes[i], info->total_size ); FillRect( dc, &area, Brushes.brush[i] ); xpos = ( area.left + area.right ) / 2; MoveTo( dc, xpos, area.bottom ); ypos = area.bottom + TEXT_SPACE + ( SIZE_CNT - i ) * TEXT_HITE; LineTo( dc, xpos, ypos ); xpos += TICK_LENGTH; LineTo( dc, xpos, ypos ); if( i == STACK_SIZE ) { sprintf( buf, MonitorLabels[i], info->sizes[i], info->stack_used ); } else { sprintf( buf, MonitorLabels[i], info->sizes[i] ); } TextOut( dc, xpos, ypos, buf, strlen( buf ) ); area.left = area.right; } area.left = BAR_XPOS; area.right = area.left + BAR_LENGTH; MoveTo( dc, area.left, area.top ); LineTo( dc, area.right, area.top ); LineTo( dc, area.right, area.bottom ); LineTo( dc, area.left, area.bottom ); LineTo( dc, area.left, area.top ); TextOut( dc, 0, BAR_HITE, "0", 1 ); sprintf( buf, "%u", info->total_size ); TextOut( dc, area.right + area.left, BAR_HITE, buf, strlen( buf ) ); RestoreDC( dc, -1 ); }
void ColorNode(HDC hDC, COLORREF rgb, COLORREF bgc, int left, int top, int right, int bottom) { WORD wWidth = right - left; WORD wHeight = bottom - top; if (GetDeviceCaps(hDC, NUMCOLORS) <= 2) PatBlt(hDC, left, top, wWidth, wHeight, DSTINVERT); else { HBRUSH hBrush = CreateSolidBrush(rgb); HDC hMemDC = CreateCompatibleDC(hDC); HBITMAP hBitmap; DWORD dwExt; POINT pt; SetMapMode(hMemDC, GetMapMode(hDC)); dwExt = GetWindowExt(hDC); SetWindowExt(hMemDC, LOWORD(dwExt), HIWORD(dwExt)); dwExt = GetViewportExt(hDC); SetViewportExt(hMemDC, LOWORD(dwExt), HIWORD(dwExt)); pt.x = wWidth; pt.y = wHeight; LPtoDP(hMemDC, &pt, 1); hBitmap = CreateBitmap(pt.x, pt.y, 1, 1, NULL); SelectObject(hMemDC, hBitmap); SetBkColor(hDC, bgc); BitBlt(hMemDC, 0, 0, wWidth, wHeight, hDC, left, top, SRCCOPY); SetBkColor(hDC, rgb); BitBlt(hDC, left, top, wWidth, wHeight, hMemDC, 0, 0, SRCCOPY); DeleteDC(hMemDC); DeleteObject(hBitmap); SelectObject(hDC, GetStockObject(WHITE_BRUSH)); DeleteObject(hBrush); SetBkColor(hDC, GetSysColor(COLOR_WINDOW)); } }
/********************************************************************** SetELightMapping **********************************************************************/ static int SetupRLightMapping(HWND hWnd, HDC hDC, WORD wMaxWidth, WORD wTextHeight, WORD wNumPossValues) { short sXWinExt, sYWinExt, sXWinOrg, sYWinOrg; short sXViewExt, sYViewExt, sXViewOrg, sYViewOrg; RECT rect; SetMapMode(hDC, MM_ISOTROPIC); sYWinExt = wNumPossValues * ((2 * VERT_PAD) + wTextHeight) + (2 * VERT_PAD) + wTextHeight; sXWinExt = wMaxWidth + (2 * VERT_PAD); /* Get clients rectangle */ GetClientRect(hWnd, (LPRECT) & rect); sXViewExt = rect.right - rect.left; sYViewExt = rect.bottom - rect.top; if (sXViewExt > sXWinExt) sXViewOrg = rect.left + (short) ((double) sXViewExt / 2.0); else sXViewOrg = rect.left + (short) ((double) sXWinExt / 2.0); if (sYViewExt > sYWinExt) sYViewOrg = rect.bottom - (short) ((double) (sYViewExt - sYWinExt) / 2.0); else sYViewOrg = rect.bottom; sXWinOrg = 0; sYWinOrg = 0; /* Set the mappings */ SetWindowExt(hDC, sXWinExt, sYWinExt); SetWindowOrg(hDC, sXWinOrg, sYWinOrg); SetViewportExt(hDC, sXWinExt, -sYWinExt); SetViewportOrg(hDC, sXViewOrg, sYViewOrg); return TRUE; }
CMemDC::CMemDC(CDC* pDC, const CRect* pRect) : CDC() { ASSERT(pDC != NULL); // Some initialization m_pDC = pDC; m_oldBitmap = NULL; m_bMemDC = !pDC->IsPrinting(); // Get the rectangle to draw if (pRect == NULL) { pDC->GetClipBox(&m_rect); } else { m_rect = *pRect; } if (m_bMemDC) { // Create a Memory DC CreateCompatibleDC(pDC); pDC->LPtoDP(&m_rect); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); m_oldBitmap = SelectObject(&m_bitmap); SetMapMode(pDC->GetMapMode()); SetWindowExt(pDC->GetWindowExt()); SetViewportExt(pDC->GetViewportExt()); pDC->DPtoLP(&m_rect); SetWindowOrg(m_rect.left, m_rect.top); } else { // Make a copy of the relevent parts of the current DC for printing m_bPrinting = pDC->m_bPrinting; m_hDC = pDC->m_hDC; m_hAttribDC = pDC->m_hAttribDC; } // Fill background FillSolidRect(m_rect, pDC->GetBkColor()); }
/* * -- 更改坐标系 -- * ViewOrg_X, ViewOrg_Y: 视图原点; ViewExt_X, ViewExt_Y: 视图范围; * WindOrg_X, WindOrg_Y: 视图原点; WindExt_X, WindExt_Y: 窗口范围 */ void ChangeZBX(HDC hdc, int ViewOrg_X, int ViewOrg_Y, int ViewExt_X, int ViewExt_Y, int WindOrg_X, int WindOrg_Y, int WindExt_X, int WindExt_Y) { POINT Pt_ViewOrg; POINT Pt_ViewExt; POINT Pt_WindExt; POINT Pt_WindOrg; Pt_ViewOrg.x = ViewOrg_X; Pt_ViewOrg.y = ViewOrg_Y; Pt_ViewExt.x = ViewExt_X; Pt_ViewExt.y = ViewExt_Y; Pt_WindOrg.x = WindOrg_X; Pt_WindOrg.y = WindOrg_Y; Pt_WindExt.x = WindExt_X; Pt_WindExt.y = WindExt_Y; SetMapMode(hdc, MM_ANISOTROPIC); SetViewportOrg(hdc, &Pt_ViewOrg); SetViewportExt(hdc, &Pt_ViewExt); SetWindowExt(hdc, &Pt_WindExt); SetWindowOrg(hdc, &Pt_WindOrg ); }