void CPlotWindow:: DrawAxis(CDC &MemDC) { CString str; // CBrush br,*oldbr; // br.CreateSolidBrush(backcolor); // oldbr = MemDC.SelectObject(&br); // // MemDC.Rectangle(X1,Y2,X2,Y1); // MemDC.SelectObject(oldbr); // br.DeleteObject(); MemDC.FillSolidRect(X1,Y2,X2,Y1,backcolor); // MemDC.Rectangle(X1,Y2,X2,Y1); // MemDC.SetBkColor(backcolor); // MemDC.SelectPalette() COLORREF color_text=RGB(255,255,255); CPen pen(PS_DASH,1,color_text); CPen* pOldPen = MemDC.SelectObject(&pen); MemDC.SetTextColor(color_text); //Draw X Axis MemDC.MoveTo(X1,Y2-2); MemDC.LineTo(X2,Y2-2); CPen pen1(PS_SOLID,1,color_text); MemDC.SelectObject(&pen1); if(y1<0 && y2>0) { int b; b= static_cast<int>(((Y1-10)*y2-(Y2+20)*y1)/(y2-y1)); //Draw Y Axis MemDC.MoveTo(X1+Xoffset,Y1-10); MemDC.LineTo(X1+Xoffset,Y2+2); //Draw Arrow; MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize); MemDC.LineTo(X1+Xoffset,Y2+2); MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); //Draw X Axis MemDC.MoveTo(X1+Xoffset,b); MemDC.LineTo(X2-2,b); //Draw Arrow; MemDC.MoveTo(X2-2-arrowsize,b+arrowsize); MemDC.LineTo(X2-2,b); MemDC.LineTo(X2-2-arrowsize,b-arrowsize); CRect rect_text(X1,b-15,X1+Xoffset-4,b+5); str.Format(_T("%ld"),0); MemDC.DrawText(str,rect_text,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+100,Y2+30); str.Format(_T("%ld"),y2); MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER); CRect rect_text2(X1+Xoffset+10,Y1-10,X1+Xoffset+100,Y1-30); str.Format(_T("%ld"),y1); MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER); str.Format(_T("%d"),x_range-1); CRect rect_text3(X2-100,b+4,X2-10,b+24); MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); MemDC.MoveTo(X1+Xoffset,Y2+20); MemDC.LineTo(X1+Xoffset+6,Y2+20); MemDC.MoveTo(X1+Xoffset,Y1-15); MemDC.LineTo(X1+Xoffset+6,Y1-15); MemDC.MoveTo(X2-20,b); MemDC.LineTo(X2-20,b-6); Axis_X1 = X1+Xoffset; Axis_X2 = X2-20; Axis_Y1 = Y1-15; Axis_Y2 = Y2+20; } else { //XÖáÔÚ×îÏÂÃæ CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+200,Y2+30); str.Format(_T("%ld"),y2); MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER); CRect rect_text2(X1+Xoffset+10,Y1-Yoffset,X1+Xoffset+200,Y1-Yoffset+20); str.Format(_T("%ld"),y1); MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER); //Draw Y Axis MemDC.MoveTo(X1+Xoffset,Y1-Yoffset); MemDC.LineTo(X1+Xoffset,Y2+2); //Draw Arrow; MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize); MemDC.LineTo(X1+Xoffset,Y2+2); MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); //Draw X Axis MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); MemDC.MoveTo(X1+Xoffset,Y1-Yoffset); MemDC.LineTo(X2-2,Y1-Yoffset); //Draw Arrow; MemDC.MoveTo(X2-2-arrowsize,Y1-Yoffset+arrowsize); MemDC.LineTo(X2-2,Y1-Yoffset); MemDC.LineTo(X2-2-arrowsize,Y1-Yoffset-arrowsize); str.Format(_T("%d"),x_range-1); CRect rect_text3(X2-100,Y1-Yoffset+4,X2-10,Y1-Yoffset+24); MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); MemDC.MoveTo(X1+Xoffset,Y2+20); MemDC.LineTo(X1+Xoffset+6,Y2+20); MemDC.MoveTo(X2-20,Y1-Yoffset); MemDC.LineTo(X2-20,Y1-Yoffset-6); Axis_X1 = X1+Xoffset; Axis_X2 = X2-20; Axis_Y1 = Y1-Yoffset; Axis_Y2 = Y2+20; } MemDC.SelectObject(pOldPen); }
void CListBoxST::DrawItem(LPDRAWITEMSTRUCT pDIStruct) { CDC* pDC = CDC::FromHandle(pDIStruct->hDC); BOOL bIsSelected = FALSE; BOOL bIsFocused = FALSE; BOOL bIsDisabled = FALSE; COLORREF crNormal = GetSysColor(COLOR_WINDOW); COLORREF crSelected = GetSysColor(COLOR_HIGHLIGHT); COLORREF crText = GetSysColor(COLOR_WINDOWTEXT); COLORREF crColor = RGB(0, 0, 0); CString sText; // List box item text STRUCT_LBDATA* lpLBData = NULL; lpLBData = (STRUCT_LBDATA*)CListBox::GetItemDataPtr(pDIStruct->itemID); if (lpLBData == NULL || lpLBData == (LPVOID)-1L) return; bIsSelected = (pDIStruct->itemState & ODS_SELECTED); bIsFocused = (pDIStruct->itemState & ODS_FOCUS); bIsDisabled = ((pDIStruct->itemState & ODS_DISABLED) || ((lpLBData->dwFlags & TEST_BIT0) == TEST_BIT0)); CRect rcItem = pDIStruct->rcItem; CRect rcIcon = pDIStruct->rcItem; CRect rcText = pDIStruct->rcItem; CRect rcCenteredText = pDIStruct->rcItem; pDC->SetBkMode(TRANSPARENT); // ONLY FOR DEBUG //CBrush brBtnShadow(RGB(255, 0, 0)); //pDC->FrameRect(&rcItem, &brBtnShadow); // Calculate rcIcon if (m_pImageList) { rcIcon.right = rcIcon.left + m_szImage.cx + LBST_CX_BORDER*2; rcIcon.bottom = rcIcon.top + m_szImage.cy + LBST_CY_BORDER*2; } // if else rcIcon.SetRect(0, 0, 0, 0); // Calculate rcText rcText.left = rcIcon.right; // Calculate rcCenteredText // Get list box item text CListBox::GetText(pDIStruct->itemID, sText); rcCenteredText = rcText; pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS| DT_CALCRECT | lpLBData->nFormat); rcCenteredText.OffsetRect(0, (rcText.Height() - rcCenteredText.Height())/2); // Draw rcIcon background if (m_pImageList) { if (bIsSelected && (m_byRowSelect == ST_FULLROWSELECT) && !bIsDisabled) crColor = crSelected; else crColor = crNormal; OnDrawIconBackground(pDIStruct->itemID, pDC, &rcItem, &rcIcon, bIsDisabled, bIsSelected, crColor); } // if // Draw rcText/rcCenteredText background if (bIsDisabled) { pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); crColor = crNormal; } // if else { if (bIsSelected) { pDC->SetTextColor(0x00FFFFFF & ~crText); crColor = crSelected; } // if else { pDC->SetTextColor(crText); crColor = crNormal; } // else } // else if (m_byRowSelect == ST_TEXTSELECT) //pDC->FillSolidRect(&rcCenteredText, crColor); OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcCenteredText, bIsDisabled, bIsSelected, crColor); else //pDC->FillSolidRect(&rcText, crColor); OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcText, bIsDisabled, bIsSelected, crColor); // Draw the icon (if any) if (m_pImageList) OnDrawIcon(pDIStruct->itemID, pDC, &rcItem, &rcIcon, lpLBData->nImage, bIsDisabled, bIsSelected); // Draw text pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS | lpLBData->nFormat); // Draw focus rectangle if (bIsFocused && !bIsDisabled) { switch (m_byRowSelect) { case ST_FULLROWSELECT: pDC->DrawFocusRect(&rcItem); break; case ST_FULLTEXTSELECT: pDC->DrawFocusRect(&rcText); break; case ST_TEXTSELECT: default: pDC->DrawFocusRect(&rcCenteredText); break; } // switch } // if } // End of DrawItem
void CHotGamePanel::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDis) { if (lpDis->CtlType != ODT_MENU) { CDialog::OnDrawItem(nIDCtl, lpDis); return ; } CDC* pDC = CDC::FromHandle(lpDis->hDC); pDC->SetBkMode(1); CRect rc(lpDis->rcItem); I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_1px.png"), rc); tagMenuItemEx* pItem = (tagMenuItemEx*)lpDis->itemData; if (pItem->dwGid < 0) { CRect rx = rc; rx.DeflateRect(0, 1, 0, 1); I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_分割线.png"), rx); } else if (pItem->dwGid > 0) { int nItem = m_lstGame.GetNextItem(-1, LVIS_SELECTED); if (nItem != -1) { tagGameInfo* pGame = m_GameInfo[nItem]; CRect rx = rc; rx.top = rc.top + (rc.Height() - 32)/2; rx.bottom = rx.top + 32; rx.left = 4; rx.right = rx.left + 32; m_ilLstCtrl.Draw(pDC, nItem, rx.TopLeft(), ILD_TRANSPARENT); LOGFONT lf = {0}; GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf); lf.lfWeight = FW_BOLD; CFont font; font.CreateFontIndirect(&lf); rx = rc; rx.left = 48; pDC->SetTextColor(0xB56226); CFont* pOldFont = pDC->SelectObject(&font); pDC->DrawText(pGame->Name, -1, &rx, DT_SINGLELINE|DT_LEFT|DT_VCENTER); pDC->SelectObject(pOldFont); } } else { if (lpDis->itemState & ODS_SELECTED) pDC->SetTextColor(RGB(255, 255, 255)); else pDC->SetTextColor(RGB(0, 0, 0)); CRect rcImg = rc; rcImg.DeflateRect(4, 1, 4, 1); if (lpDis->itemState & ODS_SELECTED) I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_按钮_鼠标经过.png"), rcImg); else I8SkinCtrl_ns::I8_DrawImage(pDC, TEXT("Skin/Menu/背景_按钮_默认状态.png"), rcImg); CRect rx = rc; rx.left = 40; rx.right = rc.right - 10; pDC->DrawText(pItem->szText, &rx, DT_SINGLELINE|DT_LEFT|DT_VCENTER); } }
static void PrintPiecesThread(void* pv) { CFrameWndEx* pFrame = (CFrameWndEx*)pv; CView* pView = pFrame->GetActiveView(); CPrintDialog PD(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame); if (theApp.DoPrintDialog(&PD) != IDOK) return; if (PD.m_pd.hDC == NULL) return; Project* project = lcGetActiveProject(); ObjArray<lcPiecesUsedEntry> PiecesUsed; project->GetPiecesUsed(PiecesUsed); PiecesUsed.Sort(PiecesUsedSortFunc, NULL); // gather file to print to if print-to-file selected CString strOutput; if (PD.m_pd.Flags & PD_PRINTTOFILE) { CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT)); CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT)); CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER)); CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION)); CFileDialog dlg(FALSE, strDef, strPrintDef,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter); dlg.m_ofn.lpstrTitle = strCaption; if (dlg.DoModal() != IDOK) return; strOutput = dlg.GetPathName(); } CString DocName; char* Ext = strrchr(project->m_strTitle, '.'); DocName.Format("LeoCAD - %.*s BOM", Ext ? Ext - project->m_strTitle : strlen(project->m_strTitle), project->m_strTitle); DOCINFO docInfo; memset(&docInfo, 0, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = DocName; CString strPortName; int nFormatID; if (strOutput.IsEmpty()) { docInfo.lpszOutput = NULL; strPortName = PD.GetPortName(); nFormatID = AFX_IDS_PRINTONPORT; } else { docInfo.lpszOutput = strOutput; AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH); nFormatID = AFX_IDS_PRINTTOFILE; } SetAbortProc(PD.m_pd.hDC, _AfxAbortProc); pFrame->EnableWindow(FALSE); CPrintingDialog dlgPrintStatus(NULL); CString strTemp; dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, DocName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD.GetDeviceName()); AfxFormatString1(strTemp, nFormatID, strPortName); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp); dlgPrintStatus.ShowWindow(SW_SHOW); dlgPrintStatus.UpdateWindow(); if (StartDoc(PD.m_pd.hDC, &docInfo) == SP_ERROR) { pFrame->EnableWindow(TRUE); dlgPrintStatus.DestroyWindow(); AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT); return; } int ResX = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSX); int ResY = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSY); CRect RectDraw(0, 0, GetDeviceCaps(PD.m_pd.hDC, HORZRES), GetDeviceCaps(PD.m_pd.hDC, VERTRES)); DPtoLP(PD.m_pd.hDC, (LPPOINT)(RECT*)&RectDraw, 2); RectDraw.DeflateRect((int)(ResX*(float)theApp.GetProfileInt("Default","Margin Left", 50)/100.0f), (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Top", 50)/100.0f), (int)(ResX*(float)theApp.GetProfileInt("Default","Margin Right", 50)/100.0f), (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Bottom", 50)/100.0f)); CRect HeaderRect = RectDraw; HeaderRect.top -= (int)(ResY*theApp.GetProfileInt("Default", "Margin Top", 50) / 200.0f); HeaderRect.bottom += (int)(ResY*theApp.GetProfileInt("Default", "Margin Bottom", 50) / 200.0f); int RowsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Rows", 10); int ColsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Columns", 3); int PicHeight = RectDraw.Height() / RowsPerPage; int PicWidth = RectDraw.Width() / ColsPerPage; int TotalRows = (PiecesUsed.GetSize() + ColsPerPage - 1) / ColsPerPage; int TotalPages = (TotalRows + RowsPerPage - 1) / RowsPerPage; int RowHeight = RectDraw.Height() / RowsPerPage; int ColWidth = RectDraw.Width() / ColsPerPage; PD.m_pd.nMinPage = 1; PD.m_pd.nMaxPage = TotalPages + 1; UINT EndPage = PD.m_pd.nToPage; UINT StartPage = PD.m_pd.nFromPage; if (PD.PrintAll()) { EndPage = PD.m_pd.nMaxPage; StartPage = PD.m_pd.nMinPage; } lcClamp(EndPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage); lcClamp(StartPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage); int StepPage = (EndPage >= StartPage) ? 1 : -1; VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM)); // begin page printing loop BOOL bError = FALSE; // Creating Compatible Memory Device Context CDC *pMemDC = new CDC; if (!pMemDC->CreateCompatibleDC(pView->GetDC())) return; BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = PicWidth; bi.bmiHeader.biHeight = PicHeight; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = PicWidth * PicHeight * 3; bi.bmiHeader.biXPelsPerMeter = 2925; bi.bmiHeader.biYPelsPerMeter = 2925; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; LPBITMAPINFOHEADER lpbi[1]; HBITMAP hBm, hBmOld; hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0); if (!hBm) return; hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI, PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd); DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd); HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc()); wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc); GL_DisableVertexBufferObject(); float Aspect = (float)PicWidth/(float)PicHeight; glViewport(0, 0, PicWidth, PicHeight); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.5f, 0.1f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(1, 1, 1, 1); LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = -MulDiv(12, ResY, 72); lf.lfWeight = FW_REGULAR; lf.lfCharSet = DEFAULT_CHARSET; lf.lfQuality = PROOF_QUALITY; strcpy (lf.lfFaceName , "Arial"); HFONT HeaderFont = CreateFontIndirect(&lf); HFONT OldFont = (HFONT)SelectObject(PD.m_pd.hDC, HeaderFont); SetBkMode(PD.m_pd.hDC, TRANSPARENT); SetTextColor(PD.m_pd.hDC, 0x000000); SetTextAlign(PD.m_pd.hDC, TA_CENTER|TA_NOUPDATECP); DWORD PrintOptions = AfxGetApp()->GetProfileInt("Settings", "Print", PRINT_NUMBERS | PRINT_BORDER/*|PRINT_NAMES*/); bool DrawNames = 1;//(PrintOptions & PRINT_NAMES) != 0; bool Horizontal = 1;//(PrintOptions & PRINT_HORIZONTAL) != 0; pMemDC->SetTextColor(0x000000); pMemDC->SetBkMode(TRANSPARENT); // lf.lfHeight = -MulDiv(40, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72); // lf.lfWeight = FW_BOLD; HFONT CatalogFont = CreateFontIndirect(&lf); lf.lfHeight = -MulDiv(80, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72); HFONT CountFont = CreateFontIndirect(&lf); HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont); HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC, GetStockObject(BLACK_PEN)); for (UINT CurPage = StartPage; CurPage != EndPage; CurPage += StepPage) { TCHAR szBuf[80]; wsprintf(szBuf, strTemp, CurPage); dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf); if (::StartPage(PD.m_pd.hDC) < 0) { bError = TRUE; break; } // Draw header and footer. SelectObject(PD.m_pd.hDC, HeaderFont); CString Header; UINT Align; FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Header", ""), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages); Align |= DT_TOP|DT_SINGLELINE; DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align); FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Footer", "Page &P"), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages); Align |= DT_BOTTOM|DT_SINGLELINE; DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align); int StartPiece = (CurPage - 1) * RowsPerPage * ColsPerPage; int EndPiece = lcMin(StartPiece + RowsPerPage * ColsPerPage, PiecesUsed.GetSize()); for (int CurPiece = StartPiece; CurPiece < EndPiece; CurPiece++) { FillRect(pMemDC->m_hDC, CRect(0, PicHeight, PicWidth, 0), (HBRUSH)GetStockObject(WHITE_BRUSH)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); PieceInfo* pInfo = PiecesUsed[CurPiece].Info; pInfo->ZoomExtents(30.0f, Aspect); pInfo->RenderPiece(PiecesUsed[CurPiece].ColorIndex); glFinish(); // Draw description text at the bottom. CRect TextRect(0, 0, PicWidth, PicHeight); if (DrawNames) { SelectObject(pMemDC->m_hDC, CatalogFont); pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_CALCRECT | DT_WORDBREAK); TextRect.OffsetRect(0, PicHeight - TextRect.Height() - 5); pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_WORDBREAK); } // Draw count. SelectObject(pMemDC->m_hDC, CountFont); TextRect = CRect(0, 0, PicWidth, TextRect.top); TextRect.DeflateRect(5, 5); char CountStr[16]; sprintf(CountStr, "%dx", PiecesUsed[CurPiece].Count); pMemDC->DrawText(CountStr, strlen(CountStr), TextRect, DT_BOTTOM | DT_LEFT | DT_SINGLELINE); LPBITMAPINFOHEADER lpbi[1]; lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24)); BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER)); SetStretchBltMode(PD.m_pd.hDC, COLORONCOLOR); int CurRow, CurCol; if (Horizontal) { CurRow = (CurPiece - StartPiece) / ColsPerPage; CurCol = (CurPiece - StartPiece) % ColsPerPage; } else { CurRow = (CurPiece - StartPiece) % RowsPerPage; CurCol = (CurPiece - StartPiece) / RowsPerPage; } int Left = RectDraw.left + ColWidth * CurCol + (ColWidth - PicWidth) / 2; int Top = RectDraw.top + RowHeight * CurRow + (RowHeight - PicHeight) / 2; StretchDIBits(PD.m_pd.hDC, Left, Top, PicWidth, PicHeight, 0, 0, PicWidth, PicHeight, (LPBYTE)lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY); if (lpbi[0]) GlobalFreePtr(lpbi[0]); } if (::EndPage(PD.m_pd.hDC) < 0 || !_AfxAbortProc(PD.m_pd.hDC, 0)) { bError = TRUE; break; } } SelectObject(pMemDC->m_hDC, hpOld); SelectObject(PD.m_pd.hDC, OldFont); DeleteObject(HeaderFont); SelectObject(pMemDC->m_hDC, OldMemFont); DeleteObject(CatalogFont); DeleteObject(CountFont); GL_EnableVertexBufferObject(); wglMakeCurrent(NULL, NULL); wglDeleteContext(hmemrc); SelectObject(pMemDC->GetSafeHdc(), hBmOld); DeleteObject(hBm); delete pMemDC; if (!bError) EndDoc(PD.m_pd.hDC); else AbortDoc(PD.m_pd.hDC); pFrame->EnableWindow(); dlgPrintStatus.DestroyWindow(); if (PD.m_pd.hDC != NULL) { ::DeleteDC(PD.m_pd.hDC); PD.m_pd.hDC = NULL; } }
void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR ); *pResult = 0; // Request item-specific notifications if this is the // beginning of the paint cycle. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage ) { *pResult = CDRF_NOTIFYITEMDRAW; } else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage ) { LVITEM rItem; int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec ); CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc ); COLORREF crBkgnd; BOOL bListHasFocus; CRect rcItem; bListHasFocus = ( GetSafeHwnd() == ::GetFocus() ); // Get the image index and selected/focused state of the // item being drawn. ZeroMemory ( &rItem, sizeof(LVITEM) ); rItem.mask = LVIF_STATE; rItem.iItem = nItem; rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; GetItem(&rItem); // Get the rect that bounds the text label. GetItemRect(nItem, rcItem, LVIR_LABEL); rcItem.left -= DUMMY_COL_WIDTH; COLORREF OldColor = -1; int nOldBKMode = -1; // Draw the background of the list item. Colors are selected // according to the item's state. if(rItem.state & LVIS_SELECTED) { if(bListHasFocus) { crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG(); OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText()); } else { crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG(); OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText()); } } else { //Shade alternating Rows if((nItem % 2) == 0) { crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG(); OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText()); } else { crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG(); OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText()); } } pDC->FillSolidRect(rcItem, crBkgnd); nOldBKMode = pDC->SetBkMode(TRANSPARENT); CRect rcText = rcItem; rcText.left += ROW_LEFT_BORDER; rcText.top++; // Draw the text. //CString csText = GetItemText(nItem, 0); CString csText; LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize); GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize); csText.ReleaseBuffer(); // extract symbols CString strSymbols; int nSymEnd = csText.Find('|'); if( nSymEnd >= 0 ) { strSymbols = csText.Left(nSymEnd); csText = csText.Mid(nSymEnd+1); } // set firstTenNum to the first ten number (1-10) corresponding to // the current nItem. // -1 means that nItem is not in the FirstTen block. int firstTenNum = GetFirstTenNum(nItem); if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 ) { rcText.left += 12; } // if we are inside a group, don't display the "in group" flag if( theApp.m_GroupID > 0 ) { int nFlag = strSymbols.Find(_T("!")); if( nFlag >= 0 ) strSymbols.Delete(nFlag); } DrawBitMap(nItem, rcText, pDC, csText); // draw the symbol box if( strSymbols.GetLength() > 0 ) { strSymbols = " " + strSymbols + " "; // leave space for box // add spaces to leave room for the symbols CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1); CRect rectSpace(0,0,0,0); //Get text bounds pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT); pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT); VERIFY( rectSpace.Width() > 0 ); // int numSpaces = rectSym.Width() / rectSpace.Width(); // numSpaces++; // csText = CString(' ',numSpaces) + csText; // draw the symbols pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) ); //pDC->FillSolidRect( rectSym, RGB(0,255,255) ); pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW)); // COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT)); COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255)); pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX); pDC->SetTextColor(crOld); rcText.left += rectSym.Width() + 2; } if(DrawRtfText(nItem, rcText, pDC) == FALSE) { pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX); } // Draw a focus rect around the item if necessary. if(bListHasFocus && (rItem.state & LVIS_FOCUSED)) pDC->DrawFocusRect(rcItem); if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 ) { CString cs; if( firstTenNum == 10 ) cs = "0"; else cs.Format(_T("%d"), firstTenNum); CRect crClient; GetWindowRect(crClient); ScreenToClient(crClient); CRect crHotKey = rcItem; crHotKey.right = crHotKey.left + 11; crHotKey.left += 2; crHotKey.top += 2; HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont); pDC->DrawText(cs, crHotKey, DT_BOTTOM); pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top)); pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom)); pDC->SelectObject(hOldFont); } // restore the previous values if(OldColor > -1) pDC->SetTextColor(OldColor); if(nOldBKMode > -1) pDC->SetBkMode(nOldBKMode); *pResult = CDRF_SKIPDEFAULT; // We've painted everything. } }
void KGListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CClientDC dc(this); CDC* pDC = &dc; pDC->SelectObject(GetFont()); int uRowCount = CListCtrl::GetHeaderCtrl()->GetItemCount(); CString* pszText = new CString[uRowCount]; CRect* pRect = new CRect[uRowCount]; BOOL bIsSelected = FALSE; BOOL bIsFocused = FALSE; BOOL bIsDisabled = FALSE; COLORREF colorFrame = RGB(255, 255, 255); COLORREF colorText = RGB(255, 255, 255); COLORREF colorBack = RGB(255, 255, 255); COLORREF colorExpandFrame = RGB(255, 255, 255); COLORREF colorExpandBack = RGB(255, 255, 255); if(lpDrawItemStruct->itemID == -1 || uRowCount < 1) { return; } bIsSelected = (lpDrawItemStruct->itemState & ODS_SELECTED); bIsFocused = (lpDrawItemStruct->itemState & ODS_FOCUS); bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED); CRect rcItem = lpDrawItemStruct->rcItem; pDC->SetBkMode(TRANSPARENT); LPKGLISTITEM pItem = (LPKGLISTITEM)GetItemData(lpDrawItemStruct->itemID); KG_PROCESS_ERROR(pItem); int uDrawCound = uRowCount; if (uRowCount > (int)pItem->arryItemText.GetCount()) { uDrawCound = (int)pItem->arryItemText.GetCount(); } for (int i = 0; i < uDrawCound; i++) { pszText[i] = pItem->arryItemText.GetAt(i).szItemText; CListCtrl::GetSubItemRect( lpDrawItemStruct->itemID, i, LVIR_BOUNDS, pRect[i] ); } if (CString(pszText[0]) == "FK") { int a = 0; a++; } (*pRect).left += rcItem.Height() * pItem->nTitleLever; for (int i = 0; i < uDrawCound ; i++) { if (!i) { LPKGLISTITEM pParent = pItem; while (pParent->pPerantItem) pParent = pParent->pPerantItem; int nTitleLever = pParent->nTitleLever; while (pParent && pParent->nTitleLever < pItem->nTitleLever) { CRect rect = rcItem; rect.left += rcItem.Height() * pParent->nTitleLever; pDC->FillRect( &rect, &CBrush(pParent->arryItemText.GetAt(i).colorBack) ); CPen pen(PS_SOLID, 1, pParent->arryItemText.GetAt(i).colorFrame); CPen* pPenSave = pDC->SelectObject(&pen); pDC->MoveTo(rect.left, rect.top); pDC->LineTo(rect.left, rect.bottom); pDC->SelectObject(pPenSave); pParent = FindJunior(pParent); if (pItem->pPerantItem && pItem->pPerantItem->nTitleLever == pParent->nTitleLever) pParent = pItem->pPerantItem; //pParent = pParent->pFirstChildItem; //nTitleLever++; } } if (bIsSelected) { colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrameSel; colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBackSel; colorBack = pItem->arryItemText.GetAt(i).colorBackSel; colorFrame = pItem->arryItemText.GetAt(i).colorFrameSel; colorText = pItem->arryItemText.GetAt(i).colorTextSel; } else { colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrame; colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBack; colorText = pItem->arryItemText.GetAt(i).colorText; colorFrame = pItem->arryItemText.GetAt(i).colorFrame; colorBack = pItem->arryItemText.GetAt(i).colorBack; } if (!i && !pItem->pFirstChildItem) pRect[i].left += 1; pDC->FillRect(pRect[i], &CBrush(colorBack)); CPen pen(PS_SOLID, 1, colorFrame); CPen* pPenSave = pDC->SelectObject(&pen); pDC->MoveTo(pRect[i].left, pRect[i].bottom); pDC->LineTo(pRect[i].left, pRect[i].top); pDC->LineTo(pRect[i].right, pRect[i].top); pDC->SelectObject(pPenSave); if (m_listDataTree.IsTitle(pItem))//(uDrawCound == 1) { CRect rect = (*pRect); rect.left += 5; rect.top += 3; rect.bottom -= 4; rect.right = rect.left + (rect.bottom - rect.top); rcItem.left = (*pRect).left; (*pRect).left += rcItem.Height() + 4; DrawRect( pDC, &rect, colorExpandFrame, colorExpandBack, !pItem->nItemState ); } else { pRect[i].left += 12; } pDC->SetTextColor(colorText); pDC->DrawText( pszText[i], -1, pRect[i], DT_LEFT | DT_SINGLELINE | DT_VCENTER ); } Exit0: SAFE_DELETE_ARRAY(pRect); SAFE_DELETE_ARRAY(pszText); }
void CMuleToolbarCtrl::SetAllButtonsWidth() { if (GetButtonCount() == 0) return; if (m_eLabelType == LabelsBelow) { CDC *pDC = GetDC(); CFont *pFnt = GetFont(); CFont *pOldFnt = pDC->SelectObject(pFnt); CRect r(0,0,0,0); // calculate the max. possible button-size int iCalcSize = 0; for (int i = 0; i < m_buttoncount ; i++) { if (!IsButtonHidden(IDC_TOOLBARBUTTON + i)) { pDC->DrawText(TBStrings[i], -1, r, DT_SINGLELINE | DT_CALCRECT); if (r.Width() > iCalcSize) iCalcSize = r.Width(); } } iCalcSize += 10; pDC->SelectObject(pOldFnt); ReleaseDC(pDC); if (!thePrefs.GetUseReBarToolbar()) { GetClientRect(&r); int bc = GetButtonCount(); if (bc == 0) bc = 1; int iMaxPossible = r.Width() / bc; // if the buttons are to big, reduze their size if (iCalcSize > iMaxPossible) iCalcSize = iMaxPossible; } else { if (iCalcSize < 56) iCalcSize = 56; else if (iCalcSize > 72) iCalcSize = 72; } SetButtonWidth(iCalcSize, iCalcSize); } else { int iSmallIconsButtonHeight; if (theApp.m_ullComCtrlVer < MAKEDLLVERULL(6, 0, 0, 0)) { // Win98,WinME,Win2000: Comtrl32 prior to 6.0 cannot make a toolbar smaller than 22 pixels // in height and if it gets larger than 22 pixels the icons do not get centered vertically. iSmallIconsButtonHeight = 22; } else iSmallIconsButtonHeight = GetSystemMetrics(SM_CYSCREEN) <= 600 ? 16 : 28; if (m_eLabelType == NoLabels) { DWORD dwSize = GetButtonSize(); int iFixedButtonWidth; int iFixedButtonHeight = HIWORD(dwSize); if (m_sizBtnBmp.cx == 16) { iFixedButtonWidth = 28; iFixedButtonHeight = iSmallIconsButtonHeight; } else { iFixedButtonWidth = 56; } // it seems that the control updates itself more properly, if 'SetButtonWidth' id called *before* 'SetButtonSize' SetButtonWidth(iFixedButtonWidth, iFixedButtonWidth); SetButtonSize(CSize(iFixedButtonWidth, iFixedButtonHeight)); } else { int iFixedButtonHeight = 0; if (m_sizBtnBmp.cx == 16) iFixedButtonHeight = iSmallIconsButtonHeight; // it seems that the control updates itself more properly, if 'SetButtonWidth' id called *before* 'SetButtonSize' SetButtonWidth(0, 0); SetButtonSize(CSize(0, iFixedButtonHeight)); } } }
void CToolTipCtrlX::OnNMCustomDraw(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTTCUSTOMDRAW pNMCD = reinterpret_cast<LPNMTTCUSTOMDRAW>(pNMHDR); if (pNMCD->nmcd.dwDrawStage == CDDS_PREPAINT) { CWnd* pwnd = CWnd::FromHandle(pNMCD->nmcd.hdr.hwndFrom); CDC* pdc = CDC::FromHandle(pNMCD->nmcd.hdc); CString strText; pwnd->GetWindowText(strText); CRect rcWnd; pwnd->GetWindowRect(&rcWnd); CRect rcBorder; rcBorder.left = pNMCD->nmcd.rc.left - rcWnd.left; rcBorder.top = pNMCD->nmcd.rc.top - rcWnd.top; rcBorder.right = rcWnd.right - pNMCD->nmcd.rc.right; rcBorder.bottom = rcWnd.bottom - pNMCD->nmcd.rc.bottom; if (m_bCol1Bold && m_fontBold.m_hObject == NULL) { CFont* pFont = pwnd->GetFont(); if (pFont) { LOGFONT lf; pFont->GetLogFont(&lf); lf.lfWeight = FW_BOLD; VERIFY( m_fontBold.CreateFontIndirect(&lf) ); } } int iTextHeight = 0; int iMaxCol1Width = 0; int iMaxCol2Width = 0; int iMaxSingleLineWidth = 0; CSize sizText(0); int iPos = 0; while (iPos != -1) { CString strLine = GetNextString(strText, _T('\n'), iPos); int iColon = strLine.Find(_T(':')); if (iColon != -1) { CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; CSize siz = pdc->GetTextExtent(strLine, iColon + 1); if (pOldFont) pdc->SelectObject(pOldFont); iMaxCol1Width = max(iMaxCol1Width, siz.cx); iTextHeight = siz.cy; // update height with 'col1' string, because 'col2' string might be empty and therefore has no height sizText.cy += siz.cy; LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1; while (_istspace(*pszCol2)) pszCol2++; if (*pszCol2 != _T('\0')) { siz = pdc->GetTextExtent(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2); iMaxCol2Width = max(iMaxCol2Width, siz.cx); } } else if (!strLine.IsEmpty()) { CSize siz = pdc->GetTextExtent(strLine); iMaxSingleLineWidth = max(iMaxSingleLineWidth, siz.cx); sizText.cy += siz.cy; } else { CSize siz = pdc->GetTextExtent(_T(" "), 1); sizText.cy += siz.cy; } } iMaxCol1Width = min(m_iScreenWidth4, iMaxCol1Width); iMaxCol2Width = min(m_iScreenWidth4*2, iMaxCol2Width); const int iMiddleMargin = 6; iMaxSingleLineWidth = max(iMaxSingleLineWidth, iMaxCol1Width + iMiddleMargin + iMaxCol2Width); sizText.cx = iMaxSingleLineWidth; rcWnd.right = rcWnd.left + rcBorder.left + sizText.cx + rcBorder.right; rcWnd.bottom = rcWnd.top + rcBorder.top + sizText.cy + rcBorder.bottom; if (rcWnd.left >= m_rcScreen.left) { if (rcWnd.right > m_rcScreen.right && rcWnd.Width() <= m_rcScreen.Width()) rcWnd.OffsetRect(-(rcWnd.right - m_rcScreen.right), 0); } if (rcWnd.top >= m_rcScreen.top) { if (rcWnd.bottom > m_rcScreen.bottom && rcWnd.Height() <= m_rcScreen.Height()) rcWnd.OffsetRect(0, -(rcWnd.bottom - m_rcScreen.bottom)); } pwnd->MoveWindow(&rcWnd); pwnd->ScreenToClient(&rcWnd); pdc->FillSolidRect(&rcWnd, m_crTooltipBkColor); CPoint ptText(pNMCD->nmcd.rc.left, pNMCD->nmcd.rc.top); iPos = 0; while (iPos != -1) { CString strLine = GetNextString(strText, _T('\n'), iPos); int iColon = strLine.Find(_T(':')); if (iColon != -1) { CRect rcDT(ptText.x, ptText.y, ptText.x + iMaxCol1Width, ptText.y + iTextHeight); // don't draw empty <col1> strings (they are still handy to use for skipping the <col1> space) if (iColon > 0) { CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; pdc->DrawText(strLine, iColon + 1, &rcDT, m_dwCol1DrawTextFlags); if (pOldFont) pdc->SelectObject(pOldFont); } LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1; while (_istspace(*pszCol2)) pszCol2++; if (*pszCol2 != _T('\0')) { rcDT.left = ptText.x + iMaxCol1Width + iMiddleMargin; rcDT.right = rcDT.left + iMaxCol2Width; pdc->DrawText(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2, &rcDT, m_dwCol2DrawTextFlags); } ptText.y += iTextHeight; } else { CSize siz = pdc->TabbedTextOut(ptText.x, ptText.y, strLine, 0, NULL, 0); ptText.y += siz.cy; } } *pResult = CDRF_SKIPDEFAULT; return; } *pResult = CDRF_DODEFAULT; }
void CGfxPopupMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); // CRect rcItem(lpDrawItemStruct->rcItem); // pDC->FillSolidRect(rcItem, RGB(255,0,0)); if (lpDrawItemStruct->CtlType == ODT_MENU) { UINT id = lpDrawItemStruct->itemID; UINT state = lpDrawItemStruct->itemState; bool bEnab = !(state & ODS_DISABLED); bool bSelect = (state & ODS_SELECTED) ? true : false; bool bChecked = (state & ODS_CHECKED) ? true : false; // David 08/04/98 - start - bold font handling bool bBold = (state & ODS_DEFAULT) ? true : false; // David 08/04/98 - end - bold font handling SpawnItem * pItem = (SpawnItem *) lpDrawItemStruct->itemData; if (pItem) { CDC * pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CFont * pft; // David 08/04/98 - start - bold font handling if (!bBold) pft = CFont::FromHandle((HFONT) hMenuFont ? hMenuFont : hGuiFont); else pft = CFont::FromHandle((HFONT) hMenuBoldFont ? hMenuBoldFont : hGuiFont); // David 08/04/98 - end - bold font handling CFont * of = pDC->SelectObject(pft); CRect rc(lpDrawItemStruct->rcItem); CRect rcImage(rc), rcText(rc); rcImage.right = rcImage.left + rc.Height(); rcImage.bottom = rc.bottom; if (pItem->iCmd == -3) // is a separator { CPen pnDk(PS_SOLID,1,cr3dShadow); CPen pnLt(PS_SOLID,1,cr3dHilight); CPen * opn = pDC->SelectObject(&pnDk); pDC->MoveTo(rc.left + 2, rc.top + 2); pDC->LineTo(rc.right - 2, rc.top + 2); pDC->SelectObject(&pnLt); pDC->MoveTo(rc.left + 2, rc.top + 3); pDC->LineTo(rc.right - 2, rc.top + 3); pDC->SelectObject(opn); } else if (pItem->iCmd == -4) // is a title item { CString cs(pItem->cText), cs1; CRect rcBdr(rcText); if (bSelect && bEnab) { rcText.top ++; rcText.left += 2; } pDC->FillSolidRect(rcText, crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_CENTER|DT_SINGLELINE); if (bSelect && bEnab) pDC->Draw3dRect(rcBdr,cr3dShadow,cr3dHilight); } else { rcText.left += rcImage.right + 1; int obk = pDC->SetBkMode(TRANSPARENT); COLORREF ocr; if (bSelect) { if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED)) pDC->FillSolidRect(rcText, crHighlight); else pDC->FillSolidRect(rc, crHighlight); ocr = pDC->SetTextColor(crMenuTextSel); } else { if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED)) pDC->FillSolidRect(rcText, crMenu); else pDC->FillSolidRect(rc/*rcText*/, crMenu); ocr = pDC->SetTextColor(crMenuText); } if (pItem->iImageIdx >= 0) { int ay = (rcImage.Height() - szImage.cy) / 2; int ax = (rcImage.Width() - szImage.cx) / 2; if (bSelect && bEnab) pDC->Draw3dRect(rcImage,cr3dHilight,cr3dShadow); else { pDC->Draw3dRect(rcImage,crMenu,crMenu); } if (bEnab) { ilList.Draw(pDC, pItem->iImageIdx, CPoint(rcImage.left + ax, rcImage.top +ay), ILD_NORMAL); } else { HICON hIcon = ilList.ExtractIcon( pItem->iImageIdx ); pDC->DrawState( CPoint(rcImage.left + ax, rcImage.top + ay ), szImage, (HICON)hIcon, DST_ICON | DSS_DISABLED, (CBrush *)NULL ); } } else { if (bChecked) { int ay = (rcImage.Height() - szImage.cy) / 2; int ax = (rcImage.Width() - szImage.cx) / 2; ilOther.Draw(pDC, 0, CPoint(rcImage.left + ax, rcImage.top + ay - 2), ILD_NORMAL); } } CString cs(pItem->cText), cs1; CSize sz; sz = pDC->GetTextExtent(cs); int ay1 = (rcText.Height() - sz.cy) / 2; rcText.top += ay1; rcText.left += 2; rcText.right -= 15; int tf = cs.Find('\t'); if (tf >= 0) { cs1 = cs.Right(cs.GetLength() - tf - 1); cs = cs.Left(tf); if (!bEnab) { if (!bSelect) { CRect rcText1(rcText); rcText1.InflateRect(-1,-1); pDC->SetTextColor(cr3dHilight); pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText1, DT_VCENTER|DT_RIGHT); pDC->SetTextColor(crGrayText); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } else { pDC->SetTextColor(crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } } else { pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } } else { if (!bEnab) { if (!bSelect) { CRect rcText1(rcText); rcText1.InflateRect(-1,-1); pDC->SetTextColor(cr3dHilight); pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); pDC->SetTextColor(crGrayText); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } else { pDC->SetTextColor(crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } } else pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } pDC->SetTextColor(ocr); pDC->SetBkMode(obk); } pDC->SelectObject(of); } } }
void CMultiPicWnd::OnPaint() { CPaintDC dc(this); // device context for painting CRect rc; GetClientRect(&rc); m_ff.SetTargetDC(dc); if (m_bMemDCInvalidated) { m_picDrawer.Draw(m_ff.GetMemDC(), rc); if (m_curPic>=0 && m_frames[m_curPic].title.size() > 0) { CDC* pDC = &m_ff.GetMemDC(); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,255,255)); CFont* pOldFont = NULL; if (m_pTitleFont != NULL) pOldFont = pDC->SelectObject(m_pTitleFont); CRect titleRC(rc); titleRC.DeflateRect(10,10); pDC->DrawText(m_frames[m_curPic].title.c_str(), -1, &titleRC, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_EXPANDTABS | DT_CALCRECT); int titHeight = titleRC.Height(); titleRC.top = rc.bottom - titHeight - 10; titleRC.bottom = titleRC.top + titHeight; CRect borderRC(titleRC); borderRC.InflateRect(5,2); m_AlphaDrawer.SetColor(RGB(0,0,0)); m_AlphaDrawer.Draw(*pDC, borderRC, 100); pDC->DrawText(m_frames[m_curPic].title.c_str(), -1, &titleRC, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_EXPANDTABS); if (pOldFont != NULL) pDC->SelectObject(pOldFont); } m_bMemDCInvalidated = FALSE; m_bTransitioning = TRUE; m_curFadeStep = 0; } if (m_bTemporaryDisableTransitioning)//Do not transition the first time { m_bTransitioning = FALSE; m_bTemporaryDisableTransitioning = FALSE; } if (m_bTransitioning) { if (m_curFadeStep < m_totalFadeSteps) { //TRACE(_T("CFadePicWnd: Fading: %d/%d\r\n"), m_curFadeStep, m_totalFadeSteps); BLENDFUNCTION bf; bf.BlendOp=AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = (255 * m_curFadeStep) / ( 2 * m_totalFadeSteps + 1);//v1 Increasing bf.AlphaFormat = 0;//AC_SRC_ALPHA ; dc.AlphaBlend(rc.left, rc.top, rc.Width(), rc.Height(), &m_ff.GetMemDC(), 0, 0, rc.Width(), rc.Height(), bf); SetTimer(TIMER_FADE_REFRESH, TIMER_FADE_DELAY, NULL); m_curFadeStep++; } else { //TRACE(_T("CFadePicWnd: Fading Finished: Blitting\r\n")); m_ff.Draw(); } m_bTransitioning = FALSE; } else { m_ff.Draw(); } }
//============================================================================= CXProgressWnd& CXProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/) //============================================================================= { int nWidth = nWindowWidth; int nMargin = 10; CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE)); CSize CancelSize; CRect CancelRect, ProgressRect, AviRect; AviRect.SetRectEmpty(); if (IsWindow(m_avi.m_hWnd)) { // we'll adjust the width later AviRect.SetRect(nMargin, nMargin, nMargin + m_nAviHeight, nMargin + m_nAviHeight); } // set up a default size for the text area in case things go wrong m_TextRect.SetRect(nMargin, AviRect.bottom+nMargin, nWindowWidth-2*nMargin, AviRect.bottom+100+2*nMargin); m_TimeLeftRect.SetRectEmpty(); // get DrawText to tell us how tall the text area will be (while we're at // it, we'll see how big the word "Cancel" is) CDC* pDC = GetDC(); if (pDC) { CFont *pOldFont = pDC->SelectObject(&m_font); CString str = _T("M"); for (int i = 0; i < nNumTextLines-1; i++) str += _T("\nM"); pDC->DrawText(str, m_TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX); if (m_bTimeLeft) pDC->DrawText(_T("M"), 1, m_TimeLeftRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX); nWidth = max(nWindowWidth, m_TextRect.Width()+2*nMargin); m_TextRect.right = nWidth - nMargin; CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T(" ")); CancelSize += CSize(EdgeSize.cx*11, EdgeSize.cy*5); pDC->SelectObject(pOldFont); ReleaseDC(pDC); } AviRect.right = m_TextRect.right; // Work out how big (and where) the progress control should be ProgressRect.SetRect(m_TextRect.left, m_TextRect.bottom + nMargin, m_TextRect.right, m_TextRect.bottom + nMargin + CancelSize.cy); if (m_bTimeLeft) { // Work out how big (and where) the time left text should be int h = m_TimeLeftRect.Height(); m_TimeLeftRect.SetRect(m_TextRect.left, ProgressRect.bottom + nMargin, m_TextRect.right, ProgressRect.bottom + nMargin + h); } else { m_TimeLeftRect = ProgressRect; } // work out how big (and where) the cancel button should be CancelRect.SetRect(ProgressRect.right - CancelSize.cx, m_TimeLeftRect.bottom + nMargin, ProgressRect.right, m_TimeLeftRect.bottom + nMargin + CancelSize.cy); // resize the main window to fit the controls CSize ClientSize(nWidth, nMargin + CancelRect.bottom); CRect WndRect, ClientRect; GetWindowRect(WndRect); GetClientRect(ClientRect); WndRect.right = WndRect.left + WndRect.Width() - ClientRect.Width() + ClientSize.cx; WndRect.bottom = WndRect.top + WndRect.Height() - ClientRect.Height() + ClientSize.cy; MoveWindow(WndRect); // now reposition the controls... if (IsWindow(m_avi.m_hWnd)) m_avi.MoveWindow(AviRect); // start modified code: added to allow dialog with only a message if (m_bEnableProgressBar) // end modified code m_wndProgress.MoveWindow(ProgressRect); // start modified code: added to allow dialog with only a message if (m_bEnableCancel) // end modified code m_CancelButton.MoveWindow(CancelRect); return *this; }
void CIconStatic::SetIcon(LPCTSTR pszIconID) { m_strIconID = pszIconID; // If this function is called for the first time and we did not yet call 'SetWindowText', we take // the window label which is already specified for the window (the label which comes from the resource) CString strText; CStatic::GetWindowText(strText); CStatic::SetWindowText(_T("")); if (!strText.IsEmpty() && m_strText.IsEmpty()) m_strText = strText; CRect rRect; GetClientRect(rRect); CDC *pDC = GetDC(); CDC MemDC; CBitmap *pOldBMP; VERIFY( MemDC.CreateCompatibleDC(pDC) ); CFont *pOldFont = MemDC.SelectObject(GetFont()); CRect rCaption(0,0,0,0); MemDC.DrawText(m_strText, rCaption, DT_CALCRECT); ASSERT( rCaption.Width() >= 0 ); ASSERT( rCaption.Height() >= 0 ); if (rCaption.Height() < 16) rCaption.bottom = rCaption.top + 16; rCaption.right += 25; if (rRect.Width() >= 16 && rCaption.Width() > rRect.Width() - 16) rCaption.right = rCaption.left + rRect.Width() - 16; if (m_MemBMP.m_hObject) VERIFY( m_MemBMP.DeleteObject() ); VERIFY( m_MemBMP.CreateCompatibleBitmap(pDC, rCaption.Width(), rCaption.Height()) ); pOldBMP = MemDC.SelectObject(&m_MemBMP); // Get the background color from the parent window. This way the controls which are // embedded in a dialog window can get painted with the same background color as // the dialog window. HBRUSH hbr = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)MemDC.m_hDC, (LPARAM)m_hWnd); FillRect(MemDC, &rCaption, hbr); if (!m_strIconID.IsEmpty()) VERIFY( DrawState( MemDC.m_hDC, NULL, NULL, (LPARAM)(HICON)CTempIconLoader(m_strIconID, 16, 16), NULL, 3, 0, 16, 16, DST_ICON | DSS_NORMAL) ); // clear all alpha channel data BITMAP bmMem; if (m_MemBMP.GetObject(sizeof bmMem, &bmMem) >= sizeof bmMem && bmMem.bmBitsPixel == 32) { DWORD dwSize = m_MemBMP.GetBitmapBits(0, NULL); if (dwSize) { LPBYTE pPixels = (LPBYTE)malloc(dwSize); if (pPixels) { if (m_MemBMP.GetBitmapBits(dwSize, pPixels) == dwSize) { LPBYTE pLine = pPixels; int iLines = bmMem.bmHeight; while (iLines-- > 0) { LPDWORD pdwPixel = (LPDWORD)pLine; for (int x = 0; x < bmMem.bmWidth; x++) *pdwPixel++ &= 0x00FFFFFF; pLine += bmMem.bmWidthBytes; } m_MemBMP.SetBitmapBits(dwSize, pPixels); } free(pPixels); } } } rCaption.left += 22; if(IsThemeActive() && IsAppThemed()) { HTHEME hTheme = OpenThemeData(NULL, L"BUTTON"); DrawThemeText(hTheme, MemDC.m_hDC, BP_GROUPBOX, GBS_NORMAL, m_strText, m_strText.GetLength(), DT_WORDBREAK | DT_CENTER | DT_WORD_ELLIPSIS, NULL, &rCaption); CloseThemeData(hTheme); } else { MemDC.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); MemDC.DrawText(m_strText, rCaption, DT_SINGLELINE | DT_LEFT | DT_END_ELLIPSIS); } ReleaseDC(pDC); MemDC.SelectObject(pOldBMP); MemDC.SelectObject(pOldFont); if (m_wndPicture.m_hWnd == NULL) m_wndPicture.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0,0,0,0), this); m_wndPicture.SetWindowPos(NULL, rRect.left+8, rRect.top, rCaption.Width()+22, rCaption.Height(), SWP_SHOWWINDOW); m_wndPicture.SetBitmap(m_MemBMP); CRect r; GetWindowRect(r); r.bottom = r.top + 20; GetParent()->ScreenToClient(&r); GetParent()->RedrawWindow(r); }
void CSkinListBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) { //没有节点就不用继续执行了 if( GetCount()==0 ) return; //变量定义 CRect rcItem=lpDrawItemStruct->rcItem; CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC); //创建缓冲 CDC BufferDC; CBitmap ImageBuffer; BufferDC.CreateCompatibleDC(pDCControl); ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height()); //设置环境 BufferDC.SelectObject(&ImageBuffer); BufferDC.SelectObject(GetCtrlFont()); //获取字符 CString strString; GetText(lpDrawItemStruct->itemID,strString); //计算位置 CRect rcString; rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height()); //颜色定义 COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText; //绘画背景 BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),m_colBack); //节点选中 if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 ) { if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() ) { m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height())); } } //节点高亮 else if ( m_nHovenItem == lpDrawItemStruct->itemID ) { if ( m_pBackImgH!= NULL && !m_pBackImgH->IsNull() ) { m_pBackImgH->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height())); } } //绘画字符 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(crTextColor); BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE); //绘画界面 pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY); //清理资源 BufferDC.DeleteDC(); ImageBuffer.DeleteObject(); }
void COFSNcDlg::DrawCaption(CDC &dc,const CRect &m_Rect) { if(m_Rect.Width()==0||m_Rect.Height()==0) return; switch(m_CaptionMode) { case CAP_NONE: case CAP_COLOR: { CFont m_font; CBrush m_br; CRect m_TextRect = m_Rect; if(m_bActive) m_br.CreateSolidBrush(m_ActiveColor); else m_br.CreateSolidBrush(m_InactiveColor); dc.FillRect(m_Rect,&m_br); CString str; GetWindowText(str); m_font.Attach(GetStockObject(DEFAULT_GUI_FONT)); dc.SelectObject(&m_font); dc.SetTextColor(RGB(255,255,255)); dc.SetBkMode(TRANSPARENT); m_TextRect.right -= 80; dc.DrawText(str,(LPRECT)&m_TextRect ,DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS|DT_SINGLELINE); } break; case CAP_BITMAP_1: { CDC dcT; dcT.CreateCompatibleDC(&dc); dcT.SelectObject(pActiveBMP); dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_1_ZOOM: { CDC dcT; dcT.CreateCompatibleDC(&dc); dcT.SelectObject(pActiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY); // dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_2: { CDC dcT; dcT.CreateCompatibleDC(&dc); if(m_bActive) dcT.SelectObject(pActiveBMP); else dcT.SelectObject(pInactiveBMP); dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_2_ZOOM: { CDC dcT; dcT.CreateCompatibleDC(&dc); if(m_bActive) { dcT.SelectObject(pActiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY); } else { dcT.SelectObject(pInactiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_InactiveBMPSize.cx,m_InactiveBMPSize.cy,SRCCOPY); } } break; } DWORD dwStyle = GetStyle(); CRect m_ButtonRect; m_ButtonRect.SetRect(m_Rect.right - CaptionH +2 ,m_Rect.top + 4, m_Rect.right - 2,m_Rect.bottom - 2); if(dwStyle&WS_SYSMENU) dc.DrawFrameControl(&m_ButtonRect,DFC_CAPTION,DFCS_CAPTIONCLOSE); if (dwStyle & WS_MAXIMIZEBOX) { m_ButtonRect-=CPoint(CaptionH-2,0); dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION, IsZoomed()?DFCS_CAPTIONRESTORE:DFCS_CAPTIONMAX); } if (dwStyle & WS_MINIMIZEBOX) { m_ButtonRect-=CPoint(CaptionH-2,0); dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION ,DFCS_CAPTIONMIN); } }
void CSAPrefsStatic::MakeCaptionBitmap() { if (m_bm.m_hObject) return; // already have bitmap; return CRect cr; GetClientRect(cr); int w = cr.Width(); int h = cr.Height(); // Create bitmap same size as caption area and select into memory DC // CWindowDC dcWin(this); CDC dc; dc.CreateCompatibleDC(&dcWin); m_bm.DeleteObject(); m_bm.CreateCompatibleBitmap(&dcWin, w, h); CBitmap* pOldBitmap = dc.SelectObject(&m_bm); COLORREF clrBG = ::GetSysColor(COLOR_3DFACE); // background color int r = GetRValue(clrBG); // red.. int g = GetGValue(clrBG); // ..green int b = GetBValue(clrBG); // ..blue color vals int x = 8*cr.right/8; // start 5/6 of the way right int w1 = x - cr.left; // width of area to shade int NCOLORSHADES = 128; // this many shades in gradient int xDelta= max( w / NCOLORSHADES , 1); // width of one shade band PaintRect(dc, x, 0, cr.right-x, h, clrBG); while (x > xDelta) { // paint bands right to left x -= xDelta; // next band int wmx2 = (w1-x)*(w1-x); // w minus x squared int w2 = w1*w1; // w squared PaintRect(dc, x, 0, xDelta, h, RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2)); } PaintRect(dc,0,0,x,h,RGB(0,0,0)); // whatever's left ==> black // draw the 'constant' text // create a font, if we need to if (m_nameFont.GetSafeHandle()==NULL) { m_nameFont.CreateFont( 18, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, m_csFontName); } CFont * OldFont = dc.SelectObject(&m_nameFont); // back up a little cr.right-=5; // draw text in DC dc.SetBkMode(TRANSPARENT); dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT)); dc.DrawText( m_csConstantText, cr + CPoint(1,1), DT_SINGLELINE | DT_RIGHT | DT_VCENTER); dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW)); dc.DrawText( m_csConstantText, cr, DT_SINGLELINE | DT_RIGHT | DT_VCENTER); // restore old font dc.SelectObject(OldFont); // Restore DC dc.SelectObject(pOldBitmap); }
void CEnListCtrl::OnPaint() { // if no items or in report mode draw to back buffer then blt if (GetItemCount() && GetView() != LVS_REPORT) { Default(); } else { CPaintDC cleanup(this); CHeaderCtrl* pHeader = GetHeader(); CDC& paintdc = *GetDC(); CDC dc; dc.CreateCompatibleDC(&paintdc); CRect rClient; GetClientRect(&rClient); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&paintdc, rClient.right, rClient.bottom); CBitmap* pOldBitmap = dc.SelectObject(&bitmap); if (pHeader && m_nCurView == LVS_REPORT && !(GetStyle() & LVS_NOCOLUMNHEADER)) { CRect rHeader; pHeader->GetWindowRect(&rHeader); ScreenToClient(rHeader); dc.ExcludeClipRect(rHeader); rClient.top = rHeader.bottom; } // fill with back color COLORREF crBack = GetItemBackColor(0, FALSE, FALSE, FALSE); dc.FillSolidRect(rClient, crBack); // default drawing CListCtrl::DefWindowProc(WM_PAINT, (WPARAM)dc.m_hDC, 0); // do empty text if nec if (GetItemCount() == 0) { CString sText = GetNoItemsText(); // virtual call if (!sText.IsEmpty()) { sText.TrimRight(); sText.TrimLeft(); if (sText[0] != _T('(')) { sText = _T("(") + sText; } if (sText[sText.GetLength() - 1] != _T(')')) { sText += _T(")"); } dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); dc.SetBkColor(crBack); dc.SelectStockObject(ANSI_VAR_FONT); rClient.top += 10; dc.DrawText(sText, rClient, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX/* | DT_NOCLIP */); rClient.top -= 10; // reset } } paintdc.BitBlt(0, rClient.top, rClient.right, rClient.bottom, &dc, 0, rClient.top, SRCCOPY); dc.SelectObject(pOldBitmap); ReleaseDC(&paintdc); } // Do not call CListView::OnPaint() for painting messages }
// CViewMax definitions void CViewMax::OnDraw(CDC& dc) { //Centre some text in our view window CRect rc = GetClientRect(); dc.DrawText(_T("Maxed Window"), -1, rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE); }
void BHeader::Paint() { CRect cr; GetClientRect(&cr); CPaintDC dc(this); CDC* pDC = &dc; CDC* pParsedDC = pDC; CDC MemDC; CBitmap MemBM; MemBM.CreateCompatibleBitmap(pParsedDC,cr.Width(),cr.Height()); MemDC.CreateCompatibleDC(pParsedDC); MemDC.SelectObject(&MemBM); pDC = &MemDC; //umple backgroundul CRect fillRect; fillRect.SetRect(0,0,cr.Width(),cr.Height()); pDC->FillSolidRect(&fillRect, RGB(220,220,220)); // cr.left = 0; // cr.right = LabelWidth; // pDC->FillSolidRect(&cr,RGB(255,0,0)); pDC->DrawEdge(&cr,BDR_RAISEDINNER,BF_RECT); //pDC->SetBkMode(TRANSPARENT); // pDC->SetBkColor(RGB(240,240,240)); pDC->SelectObject(&simpleFont); CRect textRext; textRext.SetRect(cr.left+5,cr.Height()/2 - 7,cr.right-20,cr.Height()); pDC->SetTextColor(RGB(0,0,0)); pDC->DrawText(label,-1,textRext,DT_LEFT); // fillRect.left =cr.right+SPACE_BETWEEN_ELEMENT; // fillRect.right = 500; // pDC->FillSolidRect(&fillRect,RGB(255,0,0)); //deseneaza buotnul de plus //CRect plusButton; if(collapsed) { CRect collapseButton; collapseButton.SetRect(cr.right-15,5,cr.right-4,16); pDC->DrawEdge(&collapseButton,BDR_RAISEDINNER,BF_RECT); collapseButton.SetRect(cr.right-13,4,cr.right-7,15); pDC->SelectObject(&smallFont); pDC->MoveTo(cr.right-12,10); pDC->LineTo(cr.right-7,10); if(collapsed == ITEM_COLLAPSED) { pDC->MoveTo(cr.right-10,8); pDC->LineTo(cr.right-10,13); } } //-------------------------- // flicker //-------------------------- //pDC->SetViewportOrg(0,0); //MemDC.SetViewportOrg(0,0); pParsedDC->BitBlt( 0 , 0 , cr.Width() , cr.Height() , &MemDC , 0 , 0 , SRCCOPY ); }
void CColorCombox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) { //验证是否为组合框控件 ASSERT( lpDrawItemStruct->CtlType == ODT_COMBOBOX ); CDC dc ; dc.Attach( lpDrawItemStruct->hDC ); //获取项目区域 CRect itemRC ( lpDrawItemStruct->rcItem ); //定义显示颜色的区域 CRect clrRC = itemRC; //定义文本区域 CRect textRC = itemRC; //获取系统文本颜色 COLORREF clrText = GetSysColor( COLOR_WINDOWTEXT ); //选中时的文本颜色 COLORREF clrSelected = GetSysColor( COLOR_HIGHLIGHT ); //获取窗口背景颜色 COLORREF clrNormal = GetSysColor( COLOR_WINDOW ); //获取当前项目索引 int nIndex = lpDrawItemStruct->itemID; //判断项目状态 int nState = lpDrawItemStruct->itemState; if( nState & ODS_SELECTED ) //处于选中状态 { dc.SetTextColor( ( 0x00FFFFFF & ~( clrText ) ) ); //文本颜色取反 dc.SetBkColor( clrSelected ); //设置文本背景颜色 dc.FillSolidRect( &clrRC, clrSelected ); //填充项目区域为高亮效果 } else { dc.SetTextColor( clrText ); //设置正常的文本颜色 dc.SetBkColor( clrNormal ); //设置正常的文本背景颜色 dc.FillSolidRect( &clrRC, clrNormal ); } if( nState & ODS_FOCUS ) //如果项目获取焦点,绘制焦点区域 { dc.DrawFocusRect( &itemRC ); } //计算文本区域 int nclrWidth = itemRC.Width() / 4; textRC.left = nclrWidth + 55; //计算颜色显示区域 clrRC.DeflateRect( 2, 2 ); clrRC.right = nclrWidth + 50; //绘制颜色文本并且填充颜色区域 if ( nIndex != -1 ) //项目不为空 { //获取项目颜色 COLORREF clrItem = GetItemData( nIndex ); dc.SetBkMode( TRANSPARENT ); //获取文本 CString szText; GetLBText( nIndex, szText ); //输出文本 dc.DrawText( szText, textRC, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); dc.FillSolidRect( &clrRC, clrItem ); //输出颜色 dc.FrameRect( &clrRC, &CBrush( RGB( 0, 0, 0 ) ) ); } dc.Detach(); }
void CClosableTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CRect rect(lpDIS->rcItem); int nTabIndex = lpDIS->itemID; if (nTabIndex < 0) return; TCHAR szLabel[256]; TC_ITEM tci; tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE; tci.pszText = szLabel; tci.cchTextMax = _countof(szLabel); tci.dwStateMask = TCIS_HIGHLIGHTED; if (!GetItem(nTabIndex, &tci)) return; szLabel[_countof(szLabel) - 1] = _T('\0'); //TRACE("CClosableTabCtrl::DrawItem: item=%u, state=%08x, color=%08x, rc=%3d,%3d,%3dx%3d\n", nTabIndex, tci.dwState, GetTextColor(lpDIS->hDC), lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right - lpDIS->rcItem.left, lpDIS->rcItem.bottom - lpDIS->rcItem.top); CDC* pDC = CDC::FromHandle(lpDIS->hDC); if (!pDC) return; CRect rcFullItem(lpDIS->rcItem); bool bSelected = (lpDIS->itemState & ODS_SELECTED) != 0; /////////////////////////////////////////////////////////////////////////////////////// // Adding support for XP Styles (Vista Themes) for owner drawn tab controls simply // does *not* work under Vista. Maybe it works under XP (did not try), but that is // meaningless because under XP a owner drawn tab control is already rendered *with* // the proper XP Styles. So, for XP there is no need to care about the theme API at all. // // However, under Vista, a tab control which has the TCS_OWNERDRAWFIXED // style gets additional 3D-borders which are applied by Vista *after* WM_DRAWITEM // was processed. Thus, there is no known workaround available to prevent Vista from // adding those old fashioned 3D-borders. We can render the tab control items within // the WM_DRAWITEM handler in whatever style we want, but Vista will in each case // overwrite the borders of each tab control item with old fashioned 3D-borders... // // To complete this experience, tab controls also do not support NMCUSTOMDRAW. So, the // only known way to customize a tab control is by using TCS_OWNERDRAWFIXED which does // however not work properly under Vista. // // The "solution" which is currently implemented to prevent Vista from drawing those // 3D-borders is by using "ExcludeClipRect" to reduce the drawing area which is used // by Windows after WM_DRAWITEM was processed. This "solution" is very sensitive to // the used rectangles and offsets in general. Incrementing/Decrementing one of the // "rcItem", "rcFullItem", etc. rectangles makes the entire "solution" flawed again // because some borders would become visible again. // HTHEME hTheme = NULL; int iPartId = TABP_TABITEM; int iStateId = TIS_NORMAL; bool bVistaHotTracked = false; bool bVistaThemeActive = theApp.IsVistaThemeActive(); if (bVistaThemeActive) { // To determine if the current item is in 'hot tracking' mode, we need to evaluate // the current foreground color - there is no flag which would indicate this state // more safely. This applies only for Vista and for tab controls which have the // TCS_OWNERDRAWFIXED style. bVistaHotTracked = pDC->GetTextColor() == GetSysColor(COLOR_HOTLIGHT); hTheme = g_xpStyle.OpenThemeData(m_hWnd, L"TAB"); if (hTheme) { if (bSelected) { // get the real tab item rect rcFullItem.left += 1; rcFullItem.right -= 1; rcFullItem.bottom -= 1; } else rcFullItem.InflateRect(2, 2); // get the real tab item rect CRect rcBk(rcFullItem); if (bSelected) { iStateId = TTIS_SELECTED; if (nTabIndex == 0) { // First item if (nTabIndex == GetItemCount() - 1) iPartId = TABP_TOPTABITEMBOTHEDGE; // First & Last item else iPartId = TABP_TOPTABITEMLEFTEDGE; } else if (nTabIndex == GetItemCount() - 1) { // Last item iPartId = TABP_TOPTABITEMRIGHTEDGE; } else { iPartId = TABP_TOPTABITEM; } } else { rcBk.top += 2; iStateId = bVistaHotTracked ? TIS_HOT : TIS_NORMAL; if (nTabIndex == 0) { // First item if (nTabIndex == GetItemCount() - 1) iPartId = TABP_TABITEMBOTHEDGE; // First & Last item else iPartId = TABP_TABITEMLEFTEDGE; } else if (nTabIndex == GetItemCount() - 1) { // Last item iPartId = TABP_TABITEMRIGHTEDGE; } else { iPartId = TABP_TABITEM; } } if (g_xpStyle.IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) g_xpStyle.DrawThemeParentBackground(m_hWnd, *pDC, &rcFullItem); g_xpStyle.DrawThemeBackground(hTheme, *pDC, iPartId, iStateId, &rcBk, NULL); } } // Following background clearing is needed for: // WinXP/Vista (when used without an application theme) // Vista (when used with an application theme but without a theme for the tab control) if ( (!g_xpStyle.IsThemeActive() || !g_xpStyle.IsAppThemed()) || (hTheme == NULL && bVistaThemeActive) ) pDC->FillSolidRect(&lpDIS->rcItem, GetSysColor(COLOR_BTNFACE)); int iOldBkMode = pDC->SetBkMode(TRANSPARENT); // Draw image on left side CImageList *piml = GetImageList(); if (tci.iImage >= 0 && piml && piml->m_hImageList) { IMAGEINFO ii; piml->GetImageInfo(0, &ii); rect.left += bSelected ? 8 : 4; piml->Draw(pDC, tci.iImage, CPoint(rect.left, rect.top + 2), ILD_TRANSPARENT); rect.left += (ii.rcImage.right - ii.rcImage.left); if (!bSelected) rect.left += 4; } bool bCloseable = m_bCloseable; if (bCloseable && GetParent()->SendMessage(UM_QUERYTAB, nTabIndex)) bCloseable = false; // Draw 'Close button' at right side if (bCloseable && m_ImgLstCloseButton.m_hImageList) { CRect rcCloseButton; GetCloseButtonRect(nTabIndex, rect, rcCloseButton, bSelected, bVistaThemeActive); HTHEME hThemeNC = bVistaThemeActive ? g_xpStyle.OpenThemeData(m_hWnd, _T("WINDOW")) : NULL; if (hThemeNC) { // Possible "Close" parts: WP_CLOSEBUTTON, WP_SMALLCLOSEBUTTON, WP_MDICLOSEBUTTON int iPartId = WP_SMALLCLOSEBUTTON; int iStateId = (bSelected || bVistaHotTracked) ? CBS_NORMAL : CBS_DISABLED; if (g_xpStyle.IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) g_xpStyle.DrawThemeParentBackground(m_hWnd, *pDC, &rcCloseButton); g_xpStyle.DrawThemeBackground(hThemeNC, *pDC, iPartId, iStateId, rcCloseButton, NULL); g_xpStyle.CloseThemeData(hThemeNC); } else { m_ImgLstCloseButton.Draw(pDC, (bSelected || bVistaHotTracked) ? 0 : 1, rcCloseButton.TopLeft(), ILD_TRANSPARENT); } rect.right = rcCloseButton.left - 2; if (bSelected) rect.left += hTheme ? 4 : 2; } COLORREF crOldColor = CLR_NONE; if (tci.dwState & TCIS_HIGHLIGHTED) crOldColor = pDC->SetTextColor(RGB(192, 0, 0)); else if (bVistaHotTracked) crOldColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); rect.top += bSelected ? 4 : 3; // Vista: Tab control has troubles with determining the width of a tab if the // label contains one '&' character. To get around this, we use the old code which // replaces one '&' character with two '&' characters and we do not specify DT_NOPREFIX // here when drawing the text. // // Vista: "DrawThemeText" can not be used in case we need a certain foreground color. Thus we always us // "DrawText" to always get the same font and metrics (just for safety). pDC->DrawText(szLabel, rect, DT_SINGLELINE | DT_TOP | DT_CENTER /*| DT_NOPREFIX*/); if (crOldColor != CLR_NONE) pDC->SetTextColor(crOldColor); pDC->SetBkMode(iOldBkMode); if (hTheme) { CRect rcClip(rcFullItem); if (bSelected) { rcClip.left -= 2 + 1; rcClip.right += 2 + 1; } else { rcClip.top += 2; } pDC->ExcludeClipRect(&rcClip); g_xpStyle.CloseThemeData(hTheme); } }
//重画消息 void CButtonBar::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcRect; GetClientRect(&rcRect); //加载资源 CImageHandle ImageHotHandle(&m_ImageHot); CImageHandle ImageActiveHandle(&m_ImageActive); CImageHandle ImageNormalHandle(&m_ImageNormal); CImageHandle m_ImageBackGroundHandle(&m_ImageBackGround); //建立缓冲 CDC BufferDC; CBitmap BufferBmp; BufferDC.CreateCompatibleDC(&dc); BufferBmp.CreateCompatibleBitmap(&dc,rcRect.Width(),rcRect.Height()); BufferDC.SelectObject(&BufferBmp); //绘画背景 CBrush BackBrush(TITLE_GROUND_COLOR); CPen BorderPen(PS_SOLID,1,CSkinWndObject::m_SkinAttribute.m_crInsideBorder); CPen * pOldPen=BufferDC.SelectObject(&BorderPen); CBrush * pOldBrush=BufferDC.SelectObject(&BackBrush); BufferDC.FillSolidRect(&rcRect,CSkinWndObject::m_SkinAttribute.m_crBackGround); BufferDC.RoundRect(&rcRect,CPoint(10,10)); m_ImageBackGround.BitBlt(BufferDC,1,rcRect.Height()-m_ImageBackGround.GetHeight()-3); BufferDC.SelectObject(pOldPen); BufferDC.SelectObject(pOldBrush); BackBrush.DeleteObject(); BorderPen.DeleteObject(); //绘画按钮 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SelectObject(&CSkinAttribute::m_DefaultFont); //绘画按钮 CRect rcButton; CSkinImage * pSkinImage=NULL; for (INT_PTR i=0; i<m_OptionsItemPtr.GetCount(); i++) { LPCTSTR pszButtonText=m_OptionsItemPtr[i]->GetButtonText(); rcButton.SetRect(1,(int)(ITEM_HEIGHT*i+10+2*i),rcRect.Width(),(int)(ITEM_HEIGHT*(i+1)+10+2*i)); if (i==m_nActiveItem) { pSkinImage=&m_ImageActive; BufferDC.SetTextColor(RGB(0,0,0)); } else if (i==m_nHotItem) { pSkinImage=&m_ImageHot; BufferDC.SetTextColor(RGB(0,0,0)); } else { pSkinImage=&m_ImageNormal; BufferDC.SetTextColor(RGB(0,0,0)); } pSkinImage->BitBlt(BufferDC,rcButton.left,rcButton.top,ITEM_WIDTH,ITEM_HEIGHT,0,0,SRCCOPY); BufferDC.DrawText(pszButtonText,lstrlen(pszButtonText),rcButton,DT_END_ELLIPSIS|DT_VCENTER|DT_CENTER|DT_SINGLELINE); } //绘画界面 dc.BitBlt(0,0,rcRect.Width(),rcRect.Height(),&BufferDC,0,0,SRCCOPY); //清理资源 BufferDC.DeleteDC(); BufferBmp.DeleteObject(); return; }
void CLabel::OnPaint() { CPaintDC dc(this); // device context for painting DWORD dwFlags = 0; CRect rc; GetClientRect(rc); CString strText; GetWindowText(strText); CBitmap bmp; /////////////////////////////////////////////////////// // // Set up for double buffering... // CDC* pDCMem; if (!m_bTransparent) { pDCMem = new CDC; pDCMem->CreateCompatibleDC(&dc); bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height()); CBitmap * pMyBmp = pDCMem->SelectObject(&bmp); pDCMem->SelectObject(pMyBmp); } else { pDCMem = &dc; } UINT nMode = pDCMem->SetBkMode(TRANSPARENT); COLORREF crText = pDCMem->SetTextColor(m_crText); CFont *pOldFont = pDCMem->SelectObject(&m_font); // Fill in backgound if not transparent if (!m_bTransparent) { if (m_fillmode == Normal) { CBrush br; if (m_hBackBrush != NULL) br.Attach(m_hBackBrush); else br.Attach(m_hwndBrush); pDCMem->FillRect(rc,&br); br.Detach(); } else // Gradient Fill { DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100); } } // If the text is flashing turn the text color on // then to the color of the window background. LOGBRUSH lb; ZeroMemory(&lb,sizeof(lb)); // Stop Checking complaining if (m_hBackBrush) ::GetObject(m_hBackBrush,sizeof(lb),&lb); // Something to do with flashing if (!m_bState && m_Type == Text) pDCMem->SetTextColor(lb.lbColor); DWORD style = GetStyle(); switch (style & SS_TYPEMASK) { case SS_RIGHT: dwFlags = DT_RIGHT | DT_WORDBREAK; break; case SS_CENTER: dwFlags = SS_CENTER | DT_WORDBREAK; break; case SS_LEFTNOWORDWRAP: dwFlags = DT_LEFT; break; default: // treat other types as left case SS_LEFT: dwFlags = DT_LEFT | DT_WORDBREAK; break; } // If the text centered make an assumtion that // the will want to center verticly as well if (style & SS_CENTERIMAGE) { dwFlags = DT_CENTER; // Apply if (strText.Find(_T("\r\n")) == -1) { dwFlags |= DT_VCENTER; // And because DT_VCENTER only works with single lines dwFlags |= DT_SINGLELINE; } } // // 3333 DDDDD // 3 D D // 33 D D E F X // 3 D D // 3333 DDDDD // // if (m_bRotation) { int nAlign = pDCMem->SetTextAlign (TA_BASELINE); CPoint pt; GetViewportOrgEx (pDCMem->m_hDC,&pt) ; SetViewportOrgEx (pDCMem->m_hDC,rc.Width() / 2, rc.Height() / 2, NULL) ; pDCMem->TextOut (0, 0, strText) ; SetViewportOrgEx (pDCMem->m_hDC,pt.x / 2, pt.y / 2, NULL) ; pDCMem->SetTextAlign (nAlign); } else { pDCMem->DrawText(strText,rc,dwFlags); if (m_bFont3d) { pDCMem->SetTextColor(m_cr3DHiliteColor); if (m_3dType == Raised) rc.OffsetRect(-1,-1); else rc.OffsetRect(1,1); pDCMem->DrawText(strText,rc,dwFlags); m_3dType; } } // Restore DC's State pDCMem->SetBkMode(nMode); CFont *pMyFont = pDCMem->SelectObject(pOldFont); pDCMem->SelectObject(pMyFont); pDCMem->SetTextColor(crText); if (!m_bTransparent) { dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY); delete pDCMem; } }
////////////////// // Call MFC/Windows to draw text. // void CDragDropText::OnDrawData(CDC& dc, CRect& rc, COLORREF& crMask) { crMask = 1; dc.DrawText(m_text, &rc, DT_LEFT|DT_END_ELLIPSIS); }
void CHSShadeButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { ASSERT (lpDrawItemStruct); //TRACE("* Captured: %08X\n", ::GetCapture()); //Check if the button state in not in inconsistent mode... POINT mouse_position; if ((m_button_down) && (::GetCapture() == m_hWnd) && (::GetCursorPos(&mouse_position))) { if (::WindowFromPoint(mouse_position) == m_hWnd) { if ((GetState() & BST_PUSHED) != BST_PUSHED) { //TRACE("* Inconsistency up detected! Fixing.\n"); SetState(TRUE); return; } } else { if ((GetState() & BST_PUSHED) == BST_PUSHED) { //TRACE("* Inconsistency up detected! Fixing.\n"); SetState(FALSE); return; } } } //TRACE("* Drawing: %08x\n", lpDrawItemStruct->itemState); CString sCaption; TEXTMETRIC tm; CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); // get device context RECT r = lpDrawItemStruct->rcItem; // context rectangle int cx = r.right - r.left ; // get width int cy = r.bottom - r.top ; // get height GetWindowText(sCaption); // get button text pDC->SetBkMode(TRANSPARENT); pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); //get text font pDC->GetTextMetrics(&tm); // get font metrics // get top-left corner to draw the text centered on the button int tx = (cx-tm.tmAveCharWidth*sCaption.GetLength())/2; int ty = (cy-tm.tmHeight)/2; // Select the correct skin if (lpDrawItemStruct->itemState & ODS_DISABLED) { Draw(pDC->GetSafeHdc(),r); // if needed, draw the standard 3D rectangular border if (m_Border) pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT); // paint the etched button text pDC->SetTextColor(GetSysColor(COLOR_3DHILIGHT)); pDC->DrawText(sCaption,&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER); //pDC->ExtTextOut(tx+1,ty+1,ETO_CLIPPED,&r,sCaption,NULL); pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); pDC->DrawText(sCaption,&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER); //pDC->ExtTextOut(tx,ty,ETO_CLIPPED,&r,sCaption,NULL); } else { if (lpDrawItemStruct->itemState & ODS_SELECTED) { Draw(pDC->GetSafeHdc(),r); // if needed, draw the standard 3D rectangular border if (m_Border) pDC->DrawEdge(&r,EDGE_SUNKEN,BF_RECT); } else { Draw(pDC->GetSafeHdc(),r,m_tracking); // if needed, draw the standard 3D rectangular border if (m_Border) { if (lpDrawItemStruct->itemState & ODS_DEFAULT) { pDC->DrawEdge(&r,EDGE_SUNKEN,BF_RECT); r.left += 1; r.top += 1; r.right -= 1; r.bottom -= 1; pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT); } else { pDC->DrawEdge(&r,EDGE_RAISED,BF_RECT); } } } if ((lpDrawItemStruct->itemState & ODS_FOCUS) /*&& (m_FocusRectMargin > 0)*/) { Draw(pDC->GetSafeHdc(),r,2); } // paint the enabled button tex { pDC->SetTextColor(m_TextColor); pDC->DrawText(sCaption,&r,DT_CENTER|DT_SINGLELINE|DT_VCENTER); //pDC->ExtTextOut(tx,ty,ETO_CLIPPED,&r,sCaption,NULL); } } }
void CNewHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) { CDC dc; dc.Attach( lpDrawItemStruct->hDC ); // Save DC int nSavedDC = dc.SaveDC(); /* if(m_RTL) { dc.SetViewportOrg(0, 0); dc.SetMapMode(MM_TEXT); } */ // Get the column rect CRect rcLabel( lpDrawItemStruct->rcItem ); /* CTLFrame *pFrame = (CTLFrame *)GetParent(); CRect m_clientRect; pFrame->m_tree.GetClientRect(&m_clientRect); if(m_RTL) { int left = rcLabel.left; int right = rcLabel.right; rcLabel.left = m_clientRect.Width() - right; rcLabel.right = m_clientRect.Width() - left; } */ // Set clipping region to limit drawing within column CRgn rgn; rgn.CreateRectRgnIndirect( &rcLabel ); dc.SelectObject( &rgn ); rgn.DeleteObject(); // Labels are offset by a certain amount // This offset is related to the width of a space character int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2; // Draw image from image list // Get the column text and format TCHAR buf[256]; HD_ITEM hditem; hditem.mask = HDI_TEXT | HDI_FORMAT; hditem.pszText = buf; hditem.cchTextMax = 255; GetItem( lpDrawItemStruct->itemID, &hditem ); // Determine format for drawing column label UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ; if( hditem.fmt & HDF_CENTER) uFormat |= DT_CENTER; else if( hditem.fmt & HDF_RIGHT) uFormat |= DT_RIGHT; else uFormat |= DT_LEFT; if(!(uFormat & DT_RIGHT)) { // Adjust the rect if the mouse button is pressed on it if( lpDrawItemStruct->itemState == ODS_SELECTED ) { rcLabel.left++; rcLabel.top += 2; rcLabel.right++; } rcLabel.left += offset; rcLabel.right -= offset; // Draw column label if( rcLabel.left < rcLabel.right ) dc.DrawText(buf,-1,rcLabel, uFormat); } int imageIndex; if (m_pImageList && m_mapImageIndex.Lookup( lpDrawItemStruct->itemID, imageIndex ) ) { if( imageIndex != -1 ) { if(uFormat & DT_RIGHT) // draw to the left of the label m_pImageList->Draw(&dc, imageIndex, CPoint( rcLabel.left + offset,offset/3 ), ILD_TRANSPARENT ); else // draw to the right m_pImageList->Draw(&dc, imageIndex, CPoint( rcLabel.right - dc.GetTextExtent(_T(buf), 1 ).cx*2,offset/3 ), ILD_TRANSPARENT ); // Now adjust the label rectangle IMAGEINFO imageinfo; if( m_pImageList->GetImageInfo( imageIndex, &imageinfo ) ) { rcLabel.left += offset/2 + imageinfo.rcImage.right - imageinfo.rcImage.left; } } } if(uFormat & DT_RIGHT) { // Adjust the rect if the mouse button is pressed on it if( lpDrawItemStruct->itemState == ODS_SELECTED ) { rcLabel.left++; rcLabel.top += 2; rcLabel.right++; } rcLabel.left += offset; rcLabel.right -= offset; // Draw column label if( rcLabel.left < rcLabel.right ) dc.DrawText(buf,-1,rcLabel, uFormat); } /* if(m_RTL) { dc.SetViewportOrg(m_clientRect.Width(), 0); CSize ext = dc.GetViewportExt(); ext.cx = ext.cx > 0 ? -ext.cx : ext.cx; dc.SetMapMode(MM_ANISOTROPIC); dc.SetViewportExt(ext); } */ // Restore dc dc.RestoreDC( nSavedDC ); // Detach the dc before returning dc.Detach(); }
BOOL AboutDlg::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default CRect rect; GetWindowRect(&rect); GetClientRect(&m_rect); CDC memdc; //定义一个显示设备对象 CBitmap bmp; //定义一个位图对象 memdc.CreateCompatibleDC(pDC); //建立与屏幕显示兼容的内存显示设备 bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());//建立一个与屏幕显示兼容的位图 memdc.SetBkMode(TRANSPARENT); CBitmap* pOldBmp = memdc.SelectObject(&bmp); //将位图选入到内存显示设备中 DWORD style = DT_CENTER|DT_SINGLELINE|DT_VCENTER; m_DlgPic.Load(IDR_ABOUT); if(m_DlgPic != NULL) m_DlgPic.Render(&memdc,m_rect); m_DlgPic.Load(IDR_JPG_BTN1); if(m_DlgPic != NULL) m_DlgPic.Render(&memdc,m_rtbutton); m_DlgPic.Load(IDR_CLOSEX); if(m_DlgPic != NULL) m_DlgPic.Render(&memdc,m_rtclose); switch(m_numbtn) { case 0: break; case 1: m_DlgPic.Load(IDR_JPG_BTN1_1); if(m_DlgPic != NULL) m_DlgPic.Render(&memdc,m_rtbutton); break; case 2: m_DlgPic.Load(IDR_CLOSEX1); if(m_DlgPic != NULL) m_DlgPic.Render(&memdc,m_rtclose); break; default: break; } CFont *pOldfont = (CFont *)memdc.SelectObject(&m_font); memdc.SetTextColor(RGB(0, 0, 0)); //memdc.SetBkColor(TRANSPARENT); CString str,str1; if (g_Language) { str = GetStringLanguage("About","Caption","About RiPlayer"); str1 = GetStringLanguage("About","Button1","Ok"); } else { str = GetStringLanguage("About","Caption","关于RiPlayer"); str1 = GetStringLanguage("About","Button1","确定"); } memdc.DrawText(str,CRect(10,2,180,28),DT_LEFT| DT_VCENTER | DT_SINGLELINE); memdc.DrawText(str1,m_rtbutton,DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->BitBlt(0,0,m_rect.Width(),m_rect.Height(),&memdc,0,0,SRCCOPY); bmp.DeleteObject(); memdc.DeleteDC(); ReleaseDC(pDC); return true;//true }
void CKSInputDialog::OnPaint() { CPaintDC dc(this); // device context for painting CDC memDC; CBitmap bkBit,*oldBkBit; CRect client; RECT clientRect,edtRect; dc.GetClipBox(client); if(memDC.CreateCompatibleDC(&dc)) { memDC.SetBkMode(TRANSPARENT); if(bkBit.CreateCompatibleBitmap(&dc,client.Width(),client.Height())) { oldBkBit = memDC.SelectObject(&bkBit); /* CBrush brh; brh.CreateSolidBrush( RGB(0,0,255) ); brh.UnrealizeObject(); memDC.FillRect( client , &brh ); */ if(m_config) { CRect parentRect; CWnd * parentWnd = GetParent(); ASSERT(parentWnd != NULL); parentWnd->GetWindowRect(parentRect); GetWindowRect(&clientRect); m_config->m_bkImg.m_Dest.x = -(clientRect.left); m_config->m_bkImg.m_Dest.y = -(clientRect.top); m_config->m_bkImg.m_DestSize.cx = parentRect.Width(); m_config->m_bkImg.m_DestSize.cy = parentRect.Height(); m_config->m_bkImg.m_Src.x = 0; m_config->m_bkImg.m_Src.y = 0; m_config->m_bkImg.m_SrcSize.cx = m_config->m_bkImg.GetWidth(); m_config->m_bkImg.m_SrcSize.cy = m_config->m_bkImg.GetHeight(); m_config->m_bkImg.Display(&memDC); /* dc.StretchBlt(0,0,client.Width(),client.Height(),&memDC ,0,0,m_config->m_bkImg.GetWidth(),m_config->m_bkImg.GetHeight(),SRCCOPY); */ } ////////////////////////////////////////////////////////////////////////// // 设置字体 LOGFONT lf; memset(&lf,0,sizeof lf); lf.lfCharSet = GB2312_CHARSET; strcpy(lf.lfFaceName,m_fontName.GetBuffer(1)); lf.lfHeight = m_fontSize; lf.lfWeight = FW_BOLD; CFont font; CFont *pOldFont; // 新添加的老字体资源 font.CreateFontIndirect(&lf); // memDC.SelectObject(font); // 隐掉 pOldFont = memDC.SelectObject(&font); // 新添加获得老字体资源 ////////////////////////////////////////////////////////////////////////// // 取得字体属性 TEXTMETRIC tm; memset(&tm,0,sizeof tm); memDC.GetTextMetrics(&tm); CSize fs = memDC.GetTextExtent(m_prompt); int textWidth = fs.cx;//tm.tmAveCharWidth * (m_prompt.GetLength() + 1); ////////////////////////////////////////////////////////////////////////// // 设置字体颜色 memDC.SetTextColor(m_fontColor); ////////////////////////////////////////////////////////////////////////// GetWindowRect(&clientRect); ScreenToClient(&clientRect); m_edtInput.GetWindowRect(&edtRect); ScreenToClient(&edtRect); int x,y; RECT textRect; if(clientRect.right > textWidth) { x = (clientRect.right - textWidth) / 2; textRect.left = x; textRect.right = textRect.left + textWidth; } else { x = 20; textRect.left = x; textRect.right = clientRect.right - 20; } //y = (edtRect.top - tm.tmHeight - 2); y = 5; memDC.MoveTo(x,y); textRect.top = y; textRect.bottom = y + GetTextLineHeight(fs.cy,textRect.right-textRect.left ,fs.cx); memDC.DrawText(m_prompt,&textRect,DT_WORDBREAK|DT_CENTER); ////////////////////////////////////////////////////////////////////////// dc.BitBlt(0,0,client.Width(),client.Height(),&memDC,0,0,SRCCOPY); memDC.SelectObject(pOldFont); // 新添加的把老字体资源选回去 font.DeleteObject(); //brh.DeleteObject(); memDC.SelectObject(oldBkBit); memDC.DeleteDC(); } } }
void CColumnTreeWnd::OnTreeCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { NMCUSTOMDRAW* pNMCustomDraw = (NMCUSTOMDRAW*)pNMHDR; NMTVCUSTOMDRAW* pNMTVCustomDraw = (NMTVCUSTOMDRAW*)pNMHDR; switch (pNMCustomDraw->dwDrawStage) { case CDDS_PREPAINT: *pResult = CDRF_NOTIFYITEMDRAW; break; case CDDS_ITEMPREPAINT: *pResult = CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT; break; case CDDS_ITEMPOSTPAINT: { HTREEITEM hItem = (HTREEITEM)pNMCustomDraw->dwItemSpec; CRect rcItem = pNMCustomDraw->rc; if (rcItem.IsRectEmpty()) { // nothing to paint *pResult = CDRF_DODEFAULT; break; } CDC dc; dc.Attach(pNMCustomDraw->hdc); CRect rcLabel; m_Tree.GetItemRect(hItem, &rcLabel, TRUE); COLORREF crTextBk = pNMTVCustomDraw->clrTextBk; COLORREF crText = pNMTVCustomDraw->clrText; COLORREF crWnd = GetSysColor(COLOR_WINDOW); // clear the original label rectangle CRect rcClear = rcLabel; if (rcClear.left > m_arrColWidths[0] - 1) { rcClear.left = m_arrColWidths[0] - 1; } dc.FillSolidRect(&rcClear, crWnd); int nColsCnt = m_Header.GetItemCount(); // draw horizontal lines... int xOffset = 0; for (int i=0; i<nColsCnt; i++) { xOffset += m_arrColWidths[i]; rcItem.right = xOffset-1; dc.DrawEdge(&rcItem, BDR_SUNKENINNER, BF_RIGHT); } // ...and the vertical ones dc.DrawEdge(&rcItem, BDR_SUNKENINNER, BF_BOTTOM); CString strText = m_Tree.GetItemText(hItem); CString strSub; AfxExtractSubString(strSub, strText, 0, '\t'); // calculate main label's size CRect rcText(0,0,0,0); dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_CALCRECT); rcLabel.right = min(rcLabel.left + rcText.right + 4, m_arrColWidths[0] - 4); CRect rcBack = rcLabel; if (GetWindowLong(m_Tree.m_hWnd, GWL_STYLE) & TVS_FULLROWSELECT) { int nWidth = 0; for (int i=0; i<nColsCnt; i++) { nWidth += m_arrColWidths[i]; } rcBack.right = nWidth - 1; if (rcBack.left > m_arrColWidths[0] - 1) { rcBack.left = m_arrColWidths[0] - 1; } } if (rcBack.Width() < 0) { crTextBk = crWnd; } if (crTextBk != crWnd) // draw label's background { dc.FillSolidRect(&rcBack, crTextBk); } // draw focus rectangle if necessary if (pNMCustomDraw->uItemState & CDIS_FOCUS) { dc.DrawFocusRect(&rcBack); } // draw main label rcText = rcLabel; rcText.DeflateRect(2, 1); dc.SetTextColor(crText); dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_END_ELLIPSIS); xOffset = m_arrColWidths[0]; dc.SetBkMode(TRANSPARENT); if (!(GetWindowLong(m_Tree.m_hWnd, GWL_STYLE) & TVS_FULLROWSELECT)) { dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); } // draw other columns text for (int i=1; i<nColsCnt; i++) { if (AfxExtractSubString(strSub, strText, i, '\t')) { rcText = rcLabel; rcText.left = xOffset; rcText.right = xOffset + m_arrColWidths[i]; rcText.DeflateRect(m_xOffset, 1, 2, 1); dc.DrawText(strSub, &rcText, DT_NOPREFIX | DT_END_ELLIPSIS); } xOffset += m_arrColWidths[i]; } dc.Detach(); } *pResult = CDRF_DODEFAULT; break; default: *pResult = CDRF_DODEFAULT; } }
void CChildView::OnLButtonUp(UINT nFlags, CPoint point) { if (m_bMouseLeft == TRUE) return; if (m_CurrentShapeType == SHAPETYPE_SELECTOR) { for(auto i = m_Shapes.rbegin(); i != m_Shapes.rend(); ++i) { if ((*i)->IsOn(point)) { m_CurrentShape = *i; break; } } } else if (m_CurrentShapeType == SHAPETYPE_LINETO) { for (auto i = m_Shapes.rbegin(); i != m_Shapes.rend(); ++i) { if ((*i)->IsOn(point)) { CDC* pDC = GetDC(); pDC->MoveTo(m_CurrentShape->GetRect().CenterPoint()); pDC->LineTo((*i)->GetRect().CenterPoint()); break; } } } /*else if(m_CurrentShapeType == SHAPETYPE_POLYGON) { m_CurrentShape->SetEndPoint(point); }*/ else if(m_CurrentShape) { CDC* pDC = GetDC(); if (m_LastPoint.x != -1 || m_CurrentShapeType == SHAPETYPE_POLYGON) { m_CurrentShape->SetEndPoint(m_LastPoint); CPen pen; pen.CreatePen(PS_SOLID, m_CurrentShape->GetPenWidth(), RGB(0, 0, 0)); CPen* oldPen = pDC->SelectObject(&pen); m_CurrentShape->Draw(pDC); CRect rect = m_CurrentShape->GetRect(); rect.top += (rect.Height() / 2) - 10; string text = m_CurrentShape->GetText(); CString cs(text.c_str()); pDC->DrawText(cs, rect, DT_CENTER); pDC->SelectObject(oldPen); } ReleaseDC(pDC); m_Shapes.push_back(m_CurrentShape); //if (m_CurrentShape) // delete m_CurrentShape; } m_StartPoint.x = -1; m_LastPoint.x = -1; CWnd::OnLButtonUp(nFlags, point); }