void RWinColorPaletteWell::OnPaint( ) { CPaintDC dc( this ); CRect rect; GetClientRect( rect ); if (m_crColor.GetFillMethod() != RColor::kTransparent) { // The bounding rect is in logical units, so we // need to create a transform to scale from logical // units to device units. We also divide by 2 to // account for the scaling in the bounding rect to // make the texture more visible in such a small area. RRealSize dpi( ::GetScreenDPI() ); R2dTransform transform; transform.PostScale( dpi.m_dx / kSystemDPI * 0.5, dpi.m_dy / kSystemDPI * 0.5 ); RColor crFillColor = m_crColor; crFillColor *= transform; RIntRect rRect( rect ); RDcDrawingSurface ds; ds.Initialize( (HDC) dc ); RColor oldColor = ds.GetFillColor(); ds.SetFillColor( crFillColor ); ds.FillRectangle( rRect ); ds.SetFillColor( oldColor ); ds.DetachDCs(); } else { dc.FillSolidRect( rect, RGB( 255, 255, 255 ) ); CString strText ; GetWindowText( strText ); CRect rcTextRect( rect ); rcTextRect.DeflateRect( 1, 1 ); CFont* pFont = dc.SelectObject( GetParent()->GetFont() ); dc.DrawText( strText, rcTextRect, DT_CENTER | DT_VCENTER ); dc.SelectObject( pFont ); } dc.MoveTo( rect.left, rect.bottom - 1 ); dc.LineTo( rect.left, rect.top ); dc.LineTo( rect.right, rect.top ); }
// Updates the window position. A DC is needed to calculate the size of the text void CPopupNoteDlg::UpdateWindowPos(CDC *pDC) { if (!pDC) { ASSERT(FALSE); return; } // Select the new font CFont *pOldFont=pDC->SelectObject(&m_font); // Calculate how big the window needs to be based on its width CRect rcTextRect(0,0, m_nDialogWidth, 0); pDC->DrawText(m_sNoteText, &rcTextRect, DT_CALCRECT | DT_LEFT | DT_WORDBREAK); // Make the window slightly larger than just the text int nBorderSize=m_nBorderSize; // Move the window up to the left a little bit CRect rcWindow(m_initialCursorPos.x, m_initialCursorPos.y, m_initialCursorPos.x+rcTextRect.Width()+(nBorderSize*2), m_initialCursorPos.y+rcTextRect.Height()+(nBorderSize*2)); if (rcWindow.left > 25) { rcWindow.OffsetRect(-20, 0); } if (rcWindow.top > 25) { rcWindow.OffsetRect(0,-20); } // Make sure that the window isn't going off of the bottom of the main window CRect rcMainWindow; AfxGetMainWnd()->GetWindowRect(rcMainWindow); // Check to see if it extends past the bottom if (rcWindow.bottom > rcMainWindow.bottom) { // Move the window up rcWindow.OffsetRect(0, rcMainWindow.bottom-rcWindow.bottom-5); // Make sure we didn't go off of the top of the screen if (rcWindow.bottom < 0) { rcWindow.OffsetRect(0, (-1)*rcWindow.bottom); } } // Check to see if it extends past the right side of the screen if (rcWindow.right > rcMainWindow.right) { // Move the window to the left rcWindow.OffsetRect(rcMainWindow.right-rcWindow.right-5, 0); // Make sure we didn't go off of the left of the screen if (rcWindow.left < 0) { rcWindow.OffsetRect((-1)*rcWindow.left, 0); } } MoveWindow(rcWindow); // Select the old font pDC->SelectObject(pOldFont); }