void CPropertiesWnd::InitPropList() { SetPropListFont(); m_wndPropList.EnableHeaderCtrl(FALSE); m_wndPropList.EnableDescriptionArea(); m_wndPropList.SetVSDotNetLook(); m_wndPropList.MarkModifiedProperties(); CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("外观")); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("三维外观"), (_variant_t) false, _T("指定窗口的字体不使用粗体,并且控件将使用三维边框"))); CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("边框"), _T("对话框外框"), _T("其中之一:“无”、“细”、“可调整大小”或“对话框外框”")); pProp->AddOption(_T("无")); pProp->AddOption(_T("细")); pProp->AddOption(_T("可调整大小")); pProp->AddOption(_T("对话框外框")); pProp->AllowEdit(FALSE); pGroup1->AddSubItem(pProp); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("标题"), (_variant_t) _T("关于"), _T("指定窗口标题栏中显示的文本"))); m_wndPropList.AddProperty(pGroup1); CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("窗口大小"), 0, TRUE); pProp = new CMFCPropertyGridProperty(_T("高度"), (_variant_t) 250l, _T("指定窗口的高度")); pProp->EnableSpinControl(TRUE, 50, 300); pSize->AddSubItem(pProp); pProp = new CMFCPropertyGridProperty( _T("宽度"), (_variant_t) 150l, _T("指定窗口的宽度")); pProp->EnableSpinControl(TRUE, 50, 200); pSize->AddSubItem(pProp); m_wndPropList.AddProperty(pSize); CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("字体")); LOGFONT lf; CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); font->GetLogFont(&lf); lstrcpy(lf.lfFaceName, _T("宋体, Arial")); pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("字体"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("指定窗口的默认字体"))); pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("使用系统字体"), (_variant_t) true, _T("指定窗口使用“MS Shell Dlg”字体"))); m_wndPropList.AddProperty(pGroup2); CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("杂项")); pProp = new CMFCPropertyGridProperty(_T("(名称)"), _T("应用程序")); pProp->Enable(FALSE); pGroup3->AddSubItem(pProp); CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("窗口颜色"), RGB(210, 192, 254), NULL, _T("指定默认的窗口颜色")); pColorProp->EnableOtherButton(_T("其他...")); pColorProp->EnableAutomaticButton(_T("默认"), ::GetSysColor(COLOR_3DFACE)); pGroup3->AddSubItem(pColorProp); static const TCHAR szFilter[] = _T("图标文件(*.ico)|*.ico|所有文件(*.*)|*.*||"); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("图标"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("指定窗口图标"))); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("文件夹"), _T("c:\\"))); m_wndPropList.AddProperty(pGroup3); CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("层次结构")); CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("第一个子级")); pGroup4->AddSubItem(pGroup41); CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("第二个子级")); pGroup41->AddSubItem(pGroup411); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 1"), (_variant_t) _T("值 1"), _T("此为说明"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 2"), (_variant_t) _T("值 2"), _T("此为说明"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 3"), (_variant_t) _T("值 3"), _T("此为说明"))); pGroup4->Expand(FALSE); m_wndPropList.AddProperty(pGroup4); }
void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient) { if (!HasGripper()) return; // compute the caption rectangle BOOL bHorz = IsHorzDocked(); CRect rcGrip = rcClient; CRect rcBtn = m_biHide.GetRect(); if (bHorz) { // right side gripper rcGrip.left -= m_cyGripper + 1; rcGrip.right = rcGrip.left + 11; rcGrip.top = rcBtn.bottom + 3; } else { // gripper at top rcGrip.top -= m_cyGripper + 1; rcGrip.bottom = rcGrip.top + 11; rcGrip.right = rcBtn.left - 3; } rcGrip.InflateRect(bHorz ? 1 : 0, bHorz ? 0 : 1); // draw the caption background //CBrush br; /* COLORREF clrCptn = m_bActive ? ::GetSysColor(COLOR_ACTIVECAPTION) : ::GetSysColor(COLOR_INACTIVECAPTION); // query gradient info (usually TRUE for Win98/Win2k) BOOL bGradient = FALSE; ::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0); if (!bGradient) pDC->FillSolidRect(&rcGrip, clrCptn); // solid color else { // gradient from left to right or from bottom to top // get second gradient color (the right end) COLORREF clrCptnRight = m_bActive ? ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) : ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION); // this will make 2^6 = 64 fountain steps int nShift = 6; int nSteps = 1 << nShift; for (int i = 0; i < nSteps; i++) { // do a little alpha blending int nR = (GetRValue(clrCptn) * (nSteps - i) + GetRValue(clrCptnRight) * i) >> nShift; int nG = (GetGValue(clrCptn) * (nSteps - i) + GetGValue(clrCptnRight) * i) >> nShift; int nB = (GetBValue(clrCptn) * (nSteps - i) + GetBValue(clrCptnRight) * i) >> nShift; COLORREF cr = RGB(nR, nG, nB); // then paint with the resulting color CRect r2 = rcGrip; if (bHorz) { r2.bottom = rcGrip.bottom - ((i * rcGrip.Height()) >> nShift); r2.top = rcGrip.bottom - (((i + 1) * rcGrip.Height()) >> nShift); if (r2.Height() > 0) pDC->FillSolidRect(r2, cr); } else { r2.left = rcGrip.left + ((i * rcGrip.Width()) >> nShift); r2.right = rcGrip.left + (((i + 1) * rcGrip.Width()) >> nShift); if (r2.Width() > 0) pDC->FillSolidRect(r2, cr); } } }*/ // draw the caption text - first select a font CFont font; int ppi = pDC->GetDeviceCaps(LOGPIXELSX); #ifdef CHINESE_VER int pointsize = MulDiv(90, 96, ppi); // 9.0 points at 96 ppi #else int pointsize = MulDiv(85, 96, ppi); // 8.5 points at 96 ppi for english #endif LOGFONT lf; BOOL bFont = font.CreatePointFont(pointsize, m_sFontFace); if (bFont) { // get the text color /* COLORREF clrCptnText = m_bActive ? ::GetSysColor(COLOR_CAPTIONTEXT) : ::GetSysColor(COLOR_INACTIVECAPTIONTEXT);*/ COLORREF clrCptnText = ::GetSysColor(COLOR_BTNTEXT); int nOldBkMode = pDC->SetBkMode(TRANSPARENT); COLORREF clrOldText = pDC->SetTextColor(clrCptnText); if (bHorz) { // rotate text 90 degrees CCW if horizontally docked font.GetLogFont(&lf); font.DeleteObject(); lf.lfEscapement = 900; font.CreateFontIndirect(&lf); } CFont* pOldFont = pDC->SelectObject(&font); CString sTitle; GetWindowText(sTitle); CPoint ptOrg = bHorz ? CPoint(rcGrip.left - 1, rcGrip.bottom - 3) : CPoint(rcGrip.left + 3, rcGrip.top ); pDC->ExtTextOut(ptOrg.x, ptOrg.y, ETO_CLIPPED, rcGrip, sTitle, NULL); pDC->SelectObject(pOldFont); pDC->SetBkMode(nOldBkMode); pDC->SetTextColor(clrOldText); } // draw the button m_biHide.Paint(pDC); }
void CProgressCtrlX::DrawText(const CDrawInfo& info, const CRect &rcMax, const CRect &rcBar) { if(!(info.dwStyle&PBS_TEXTMASK)) return; BOOL fVert = info.dwStyle&PBS_VERTICAL; CDC *pDC = info.pDC; int nValue = 0; CString sFormat; GetWindowText(sFormat); switch(info.dwStyle&PBS_TEXTMASK) { case PBS_SHOW_PERCENT: if(sFormat.IsEmpty()) sFormat = "%d%%"; // retrieve current position and range nValue = (int)((float)(info.nCurPos-info.nLower) * 100 / ((info.nUpper-info.nLower == 0) ? 1 : info.nUpper-info.nLower)); break; case PBS_SHOW_POSITION: if(sFormat.IsEmpty()) sFormat = "%d"; // retrieve current position nValue = info.nCurPos; break; } if (sFormat.IsEmpty()) return; CFont* pFont = GetFont(); CSelFont sf(pDC, pFont); CSelTextColor tc(pDC, m_clrTextOnBar); CSelBkMode bm(pDC, TRANSPARENT); CSelTextAlign ta(pDC, TA_BOTTOM|TA_CENTER); CPoint ptOrg = pDC->GetWindowOrg(); CString sText; sText.Format(sFormat, nValue); LONG grad = 0; if(pFont) { LOGFONT lf; pFont->GetLogFont(&lf); grad = lf.lfEscapement/10; } int x = 0, y = 0, dx = 0, dy = 0; CSize sizText = pDC->GetTextExtent(sText); if(grad == 0) { x = sizText.cx; y = sizText.cy; dx = 0; dy = sizText.cy;} else if(grad == 90) { x = sizText.cy; y = sizText.cx; dx = sizText.cy; dy = 0;} else if(grad == 180) { x = sizText.cx; y = sizText.cy; dx = 0; dy = -sizText.cy;} else if(grad == 270) { x = sizText.cy; y = sizText.cx; dx = -sizText.cy; dy = 0;} else ASSERT(0); // angle not supported CPoint pt = pDC->GetViewportOrg(); if(info.dwStyle&PBS_TIED_TEXT) { CRect rcFill(ConvertToReal(info, rcBar)); if((fVert ? y : x) <= rcBar.Width()) { pDC->SetViewportOrg(rcFill.left + (rcFill.Width() + dx)/2, rcFill.top + (rcFill.Height() + dy)/2); DrawClippedText(info, rcBar, sText, ptOrg); } } else { pDC->SetViewportOrg(info.rcClient.left + (info.rcClient.Width() + dx)/2, info.rcClient.top + (info.rcClient.Height() + dy)/2); if(m_clrTextOnBar == m_clrTextOnBk) // if the same color for bar and background draw text once DrawClippedText(info, rcMax, sText, ptOrg); else { // else, draw clipped parts of text // draw text on gradient if(rcBar.left != rcBar.right) DrawClippedText(info, rcBar, sText, ptOrg); // draw text out of gradient if(rcMax.right > rcBar.right) { tc.Select(m_clrTextOnBk); CRect rc(rcMax); rc.left = rcBar.right; DrawClippedText(info, rc, sText, ptOrg); } if(rcMax.left < rcBar.left) { tc.Select(m_clrTextOnBk); CRect rc(rcMax); rc.right = rcBar.left; DrawClippedText(info, rc, sText, ptOrg); } } } pDC->SetViewportOrg(pt); }
void MyGraph::DrawAxes(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); _ASSERTE(MyGraph::PieChart != m_eGraphType); dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); // Draw y axis. dc.MoveTo(m_ptOrigin); VERIFY(dc.LineTo(m_ptOrigin.x, m_ptOrigin.y - m_nYAxisHeight)); // Draw x axis. dc.MoveTo(m_ptOrigin); if (m_saLegendLabels.GetSize()) { VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), m_ptOrigin.y)); } else { VERIFY(dc.LineTo(m_ptOrigin.x + m_nXAxisWidth, m_ptOrigin.y)); } // Note: m_nAxisLabelHeight and m_nAxisTickLabelHeight have been calculated in SetupAxis() // Create the x-axis label font. CFont fontXAxis; VERIFY(fontXAxis.CreatePointFont(m_nAxisLabelHeight, _T("Arial"), &dc)); // Obtain the height of the font in device coordinates. LOGFONT pLF; VERIFY(fontXAxis.GetLogFont(&pLF)); int fontHeightDC = pLF.lfHeight; // Create the y-axis label font. CFont fontYAxis; VERIFY(fontYAxis.CreateFont( /* nHeight */ fontHeightDC, /* nWidth */ 0, /* nEscapement */ 90 * 10, /* nOrientation */ 0, /* nWeight */ FW_DONTCARE, /* bItalic */ false, /* bUnderline */ false, /* cStrikeOut */ 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_DONTCARE, _T("Arial")) ); // Set the y-axis label font and draw the label. CFont* pFontOld = dc.SelectObject(&fontYAxis); ASSERT_VALID(pFontOld); CSize sizYLabel(dc.GetTextExtent(m_sYAxisLabel)); VERIFY(dc.TextOut(GAP_PIXELS, (m_rcGraph.Height() + sizYLabel.cx) / 2, m_sYAxisLabel)); // Set the x-axis label font and draw the label. VERIFY(dc.SelectObject(&fontXAxis)); CSize sizXLabel(dc.GetTextExtent(m_sXAxisLabel)); VERIFY(dc.TextOut(m_ptOrigin.x + (m_nXAxisWidth - sizXLabel.cx) / 2, m_rcGraph.bottom - GAP_PIXELS - sizXLabel.cy, m_sXAxisLabel)); // chose suitable tick step (1, 2, 5, 10, 20, 50, etc.) int nMaxDataValue(GetMaxDataValue()); nMaxDataValue = max(nMaxDataValue, 1); int nTickStep = 1; while (10 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 10; if (5 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 5; if (2 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 2; // We hardwire TITLE_DIVISOR y-axis ticks here for simplicity. int nTickCount(nMaxDataValue / nTickStep); double tickSpace = (double)m_nYAxisHeight * nTickStep / (double)nMaxDataValue; // create tick label font and set it in the device context CFont fontTickLabels; VERIFY(fontTickLabels.CreatePointFont(m_nAxisTickLabelHeight, _T("Arial"), &dc)); VERIFY(dc.SelectObject(&fontTickLabels)); for (int nTick = 0; nTick < nTickCount; ++nTick) { int nTickYLocation = static_cast<int>(m_ptOrigin.y - tickSpace * (nTick + 1) + 0.5); dc.MoveTo(m_ptOrigin.x - TICK_PIXELS, nTickYLocation); VERIFY(dc.LineTo(m_ptOrigin.x + TICK_PIXELS, nTickYLocation)); // Draw tick label. CString sTickLabel; sTickLabel.Format(_T("%d"), nTickStep * (nTick+1)); CSize sizTickLabel(dc.GetTextExtent(sTickLabel)); VERIFY(dc.TextOut(m_ptOrigin.x - GAP_PIXELS - sizTickLabel.cx - TICK_PIXELS, nTickYLocation - sizTickLabel.cy/2, sTickLabel)); } // Draw X axis tick marks. POSITION pos(m_olMyGraphSeries.GetHeadPosition()); int nSeries(0); while (pos) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); // Ignore unpopulated series if bar chart. if (m_eGraphType != MyGraph::Bar || 0 < pSeries->GetNonZeroElementCount()) { // Get the spacing of the series. int nSeriesSpace(0); if (m_saLegendLabels.GetSize()) { nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) / (m_eGraphType == MyGraph::Bar ? GetNonZeroSeriesCount() : (int)m_olMyGraphSeries.GetCount()); } else { nSeriesSpace = m_nXAxisWidth / (m_eGraphType == MyGraph::Bar ? GetNonZeroSeriesCount() : (int)m_olMyGraphSeries.GetCount()); } int nTickXLocation(m_ptOrigin.x + ((nSeries + 1) * nSeriesSpace) - (nSeriesSpace / 2)); dc.MoveTo(nTickXLocation, m_ptOrigin.y - TICK_PIXELS); VERIFY(dc.LineTo(nTickXLocation, m_ptOrigin.y + TICK_PIXELS)); // Draw x-axis tick label. CString sTickLabel(pSeries->GetLabel()); CSize sizTickLabel(dc.GetTextExtent(sTickLabel)); VERIFY(dc.TextOut(nTickXLocation - (sizTickLabel.cx / 2), m_ptOrigin.y + TICK_PIXELS + GAP_PIXELS, sTickLabel)); ++nSeries; } } VERIFY(dc.SelectObject(pFontOld)); fontXAxis.DeleteObject(); fontYAxis.DeleteObject(); fontTickLabels.DeleteObject(); }
void CPropertiesWnd::InitPropList() { SetPropListFont(); m_wndPropList.EnableHeaderCtrl(FALSE); m_wndPropList.EnableDescriptionArea(); m_wndPropList.SetVSDotNetLook(); m_wndPropList.MarkModifiedProperties(); CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Вид")); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Трехмерный вид"), (_variant_t) false, _T("В окне используется обычный (не жирный) шрифт, а у элементов управления есть визуально трехмерная граница."))); CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("Граница"), _T("Диалоговое окно"), _T("Одно из значений: \"Нет\", \"Тонкая\", \"Изменяемая\" или \"Диалоговое окно\"")); pProp->AddOption(_T("Нет")); pProp->AddOption(_T("Тонкая")); pProp->AddOption(_T("Изменяемая")); pProp->AddOption(_T("Диалоговое окно")); pProp->AllowEdit(FALSE); pGroup1->AddSubItem(pProp); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Заголовок"), (_variant_t) _T("О программе"), _T("Указывает текст, который будет отображаться в строке заголовка окна"))); m_wndPropList.AddProperty(pGroup1); CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Размер окна"), 0, TRUE); pProp = new CMFCPropertyGridProperty(_T("Высота"), (_variant_t) 250l, _T("Указывает высоту окна")); pProp->EnableSpinControl(TRUE, 50, 300); pSize->AddSubItem(pProp); pProp = new CMFCPropertyGridProperty( _T("Ширина"), (_variant_t) 150l, _T("Указывает ширину окна")); pProp->EnableSpinControl(TRUE, 50, 200); pSize->AddSubItem(pProp); m_wndPropList.AddProperty(pSize); CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Шрифт")); LOGFONT lf; CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); font->GetLogFont(&lf); lstrcpy(lf.lfFaceName, _T("Arial")); pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Шрифт"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Указывает шрифт окна по умолчанию"))); pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Использование системного шрифта"), (_variant_t) true, _T("Указывает, что в окне используется шрифт MS Shell Dlg"))); m_wndPropList.AddProperty(pGroup2); CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Разное")); pProp = new CMFCPropertyGridProperty(_T("(Имя)"), _T("Приложение")); pProp->Enable(FALSE); pGroup3->AddSubItem(pProp); CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Цвет окна"), RGB(210, 192, 254), NULL, _T("Указывает цвет окна по умолчанию")); pColorProp->EnableOtherButton(_T("Другое...")); pColorProp->EnableAutomaticButton(_T("По умолчанию"), ::GetSysColor(COLOR_3DFACE)); pGroup3->AddSubItem(pColorProp); static const TCHAR szFilter[] = _T("Файлы значков(*.ico)|*.ico|Все файлы(*.*)|*.*||"); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Значок"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Указывает значок окна"))); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Папка"), _T("c:\\"))); m_wndPropList.AddProperty(pGroup3); CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Иерархия")); CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("Первый подуровень")); pGroup4->AddSubItem(pGroup41); CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Второй подуровень")); pGroup41->AddSubItem(pGroup411); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Элемент 1"), (_variant_t) _T("Значение 1"), _T("Это описание"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Элемент 2"), (_variant_t) _T("Значение 2"), _T("Это описание"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Элемент 3"), (_variant_t) _T("Значение 3"), _T("Это описание"))); pGroup4->Expand(FALSE); m_wndPropList.AddProperty(pGroup4); }
void CPropertiesWnd::InitPropList() { SetPropListFont(); m_wndPropList.EnableHeaderCtrl(FALSE); m_wndPropList.EnableDescriptionArea(); m_wndPropList.SetVSDotNetLook(); m_wndPropList.MarkModifiedProperties(); CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Appearance")); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("3D Look"), (_variant_t) false, _T("Specifies the window's font will be non-bold and controls will have a 3D border"))); CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("Border"), _T("Dialog Frame"), _T("One of: None, Thin, Resizable, or Dialog Frame")); pProp->AddOption(_T("None")); pProp->AddOption(_T("Thin")); pProp->AddOption(_T("Resizable")); pProp->AddOption(_T("Dialog Frame")); pProp->AllowEdit(FALSE); pGroup1->AddSubItem(pProp); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Caption"), (_variant_t) _T("About"), _T("Specifies the text that will be displayed in the window's title bar"))); m_wndPropList.AddProperty(pGroup1); CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Window Size"), 0, TRUE); pProp = new CMFCPropertyGridProperty(_T("Height"), (_variant_t) 250l, _T("Specifies the window's height")); pProp->EnableSpinControl(TRUE, 50, 300); pSize->AddSubItem(pProp); pProp = new CMFCPropertyGridProperty( _T("Width"), (_variant_t) 150l, _T("Specifies the window's width")); pProp->EnableSpinControl(TRUE, 50, 200); pSize->AddSubItem(pProp); m_wndPropList.AddProperty(pSize); CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Font")); LOGFONT lf; CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); font->GetLogFont(&lf); lstrcpy(lf.lfFaceName, _T("Arial")); pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Font"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the window"))); pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Use System Font"), (_variant_t) true, _T("Specifies that the window uses MS Shell Dlg font"))); m_wndPropList.AddProperty(pGroup2); CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc")); pProp = new CMFCPropertyGridProperty(_T("(Name)"), _T("Application")); pProp->Enable(FALSE); pGroup3->AddSubItem(pProp); CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Window Color"), RGB(210, 192, 254), NULL, _T("Specifies the default window color")); pColorProp->EnableOtherButton(_T("Other...")); pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE)); pGroup3->AddSubItem(pColorProp); static const TCHAR szFilter[] = _T("Icon Files(*.ico)|*.ico|All Files(*.*)|*.*||"); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Icon"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Specifies the window icon"))); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Folder"), _T("c:\\"))); m_wndPropList.AddProperty(pGroup3); CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Hierarchy")); CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("First sub-level")); pGroup4->AddSubItem(pGroup41); CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Second sub-level")); pGroup41->AddSubItem(pGroup411); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 1"), (_variant_t) _T("Value 1"), _T("This is a description"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 2"), (_variant_t) _T("Value 2"), _T("This is a description"))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 3"), (_variant_t) _T("Value 3"), _T("This is a description"))); pGroup4->Expand(FALSE); m_wndPropList.AddProperty(pGroup4); }
void MyGraph::DrawLegend(CDC& dc) { VALIDATE; ASSERT_VALID(&dc); // Create the legend font. CFont fontLegend; int pointFontHeight = max(m_rcGraph.Height() / LEGEND_DIVISOR, MIN_FONT_SIZE); VERIFY(fontLegend.CreatePointFont(pointFontHeight, _T("Arial"), &dc)); // Get the height of each label. LOGFONT lf; ::SecureZeroMemory(&lf, sizeof(lf)); VERIFY(fontLegend.GetLogFont(&lf)); int nLabelHeight(abs(lf.lfHeight)); // Get number of legend entries int nLegendEntries = max(1, GetMaxSeriesSize()); // Calculate optimal label height = AvailableLegendHeight/AllAuthors // Use a buffer of (GAP_PIXELS / 2) on each side inside the legend, and in addition the same // gab above and below the legend frame, so in total 2*GAP_PIXELS double optimalLabelHeight = double(m_rcGraph.Height() - 2*GAP_PIXELS)/nLegendEntries; // Now relate the LabelHeight to the PointFontHeight int optimalPointFontHeight = int(pointFontHeight*optimalLabelHeight/nLabelHeight); // Limit the optimal PointFontHeight to the available range optimalPointFontHeight = min( max(optimalPointFontHeight, MIN_FONT_SIZE), pointFontHeight); // If the optimalPointFontHeight is different from the initial one, create a new legend font if (optimalPointFontHeight != pointFontHeight) { fontLegend.DeleteObject(); VERIFY(fontLegend.CreatePointFont(optimalPointFontHeight, _T("Arial"), &dc)); VERIFY(fontLegend.GetLogFont(&lf)); nLabelHeight = abs(lf.lfHeight); } // Calculate maximum number of authors that can be shown with the current label height int nShownAuthors = (m_rcGraph.Height() - 2*GAP_PIXELS)/nLabelHeight - 1; // Fix rounding errors. if (nShownAuthors+1 == GetMaxSeriesSize()) ++nShownAuthors; // Get number of authors to be shown. nShownAuthors = min(nShownAuthors, GetMaxSeriesSize()); // nShownAuthors contains now the number of authors CFont* pFontOld = dc.SelectObject(&fontLegend); ASSERT_VALID(pFontOld); // Determine actual size of legend. A buffer of (GAP_PIXELS / 2) on each side, // plus the height of each label based on the pint size of the font. int nLegendHeight = (GAP_PIXELS / 2) + (nShownAuthors * nLabelHeight) + (GAP_PIXELS / 2); // Draw the legend border. Allow LEGEND_COLOR_BAR_PIXELS pixels for // display of label bars. m_rcLegend.top = (m_rcGraph.Height() - nLegendHeight) / 2; m_rcLegend.bottom = m_rcLegend.top + nLegendHeight; m_rcLegend.right = m_rcGraph.Width() - GAP_PIXELS; m_rcLegend.left = m_rcLegend.right - GetMaxLegendLabelLength(dc) - LEGEND_COLOR_BAR_WIDTH_PIXELS; VERIFY(dc.Rectangle(m_rcLegend)); int skipped_row = -1; // if != -1, this is the row that we show the ... in if (nShownAuthors < GetMaxSeriesSize()) skipped_row = nShownAuthors-2; // Draw each group's label and bar. for (int nGroup = 0; nGroup < nShownAuthors; ++nGroup) { int nLabelTop(m_rcLegend.top + (nGroup * nLabelHeight) + (GAP_PIXELS / 2)); int nShownGroup = nGroup; // introduce helper variable to avoid code duplication // Do we have a skipped row? if (skipped_row != -1) { if (nGroup == skipped_row) { // draw the dots VERIFY(dc.TextOut(m_rcLegend.left + GAP_PIXELS, nLabelTop, _T("...") )); continue; } if (nGroup == nShownAuthors-1) { // we show the last group instead of the scheduled group nShownGroup = GetMaxSeriesSize()-1; } } // Draw the label. VERIFY(dc.TextOut(m_rcLegend.left + GAP_PIXELS, nLabelTop, m_saLegendLabels.GetAt(nShownGroup))); // Determine the bar. CRect rcBar; rcBar.left = m_rcLegend.left + GAP_PIXELS + GetMaxLegendLabelLength(dc) + GAP_PIXELS; rcBar.top = nLabelTop + LEGEND_COLOR_BAR_GAP_PIXELS; rcBar.right = m_rcLegend.right - GAP_PIXELS; rcBar.bottom = rcBar.top + nLabelHeight - LEGEND_COLOR_BAR_GAP_PIXELS; VERIFY(dc.Rectangle(rcBar)); // Draw bar for group. COLORREF crBar(m_dwaColors.GetAt(nShownGroup)); CBrush br(crBar); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); rcBar.DeflateRect(LEGEND_COLOR_BAR_GAP_PIXELS, LEGEND_COLOR_BAR_GAP_PIXELS); dc.FillRect(rcBar, &br); dc.SelectObject(pBrushOld); br.DeleteObject(); } VERIFY(dc.SelectObject(pFontOld)); fontLegend.DeleteObject(); }
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; }
//////////////////////////////////////////////////////////////////// // Public functions // void CDrawGrid::Draw( int page, CDC* dc ) /* ============================================================ Function : CDrawGrid::Draw Description : Draws this object. Access : Public Return : void Parameters : int page - Current page CDC* dc - CDC to draw to Usage : Called by the generator to draw the object. ============================================================*/ { ///////////////////////////////// // Get and convert grid position // int drawpage = page - GetPageOffset(); CDoubleRect rect = GetPosition(); CUnitConversion::InchesToPixels( rect ); CRect r( static_cast< int >( rect.left ), static_cast< int >( rect.top ), static_cast< int >( rect.right ), static_cast< int >( rect.bottom ) ); CUnitConversion::AdjustPixelsToPaper( dc, r ); ///////////////////////////////// // Create column widths and // fonts // int restWidth = 0; int sumWidth = 0; TContainer< CFont* > fonts; double lpi = static_cast< double >( GetLPI() ); double inch = static_cast< double >( dc->GetDeviceCaps( LOGPIXELSY ) ); int lineHeight = static_cast< int >( inch / lpi + .5 ); int max = m_columns.GetSize(); for( int t = 0 ; t < max ; t++ ) { CColumn* column = m_columns.GetAt( t ); if( column ) { sumWidth += CUnitConversion::InchesToPixels( column->GetWidth() ); fonts.Add( column->GetColumnFont() ); } } // restWidth will be used for // any 0-length field restWidth = r.Width() - sumWidth; ///////////////////////////////// // Find start and end of data // int start = m_pages.GetAt( drawpage )->m_startLine; int end = m_pages.GetAt( drawpage )->m_endLine; int mode = dc->SetBkMode( TRANSPARENT ); COLORREF color = dc->GetTextColor(); ///////////////////////////////// // Border // const CBorderLine* borderline = GetBorder(); CPen pen; CPen boldPen; if( borderline->GetVisible() ) { // Draw a border around the grid int thickness = CUnitConversion::InchesToPixels( borderline->GetThickness() ); pen.CreatePen( borderline->GetStyle(), thickness, borderline->GetColor() ); dc->SelectObject( &pen ); dc->SelectStockObject( NULL_BRUSH ); dc->Rectangle( r ); dc->SelectStockObject( NULL_PEN ); } ///////////////////////////////// // Line pens // const CBorderLine* columnline = GetColumnLine(); const CBorderLine* rowline = GetRowLine(); CPen* columnpen = NULL; CPen* rowpen = NULL; if( columnline->GetVisible() ) { columnpen = new CPen; int thickness = CUnitConversion::InchesToPixels( columnline->GetThickness() ); columnpen->CreatePen( columnline->GetStyle(), thickness, columnline->GetColor() ); } if( rowline->GetVisible() ) { rowpen = new CPen; int thickness = CUnitConversion::InchesToPixels( rowline->GetThickness() ); rowpen->CreatePen( rowline->GetStyle(), thickness, rowline->GetColor() ); } ///////////////////////////////// // Column lines // if( columnpen ) { dc->SelectObject( columnpen ); int left = r.left; // Loop columns for( int i = 0 ; i < max - 1; i++ ) { CColumn* column = m_columns.GetAt( i ); if( column ) { int pixelWidth = CUnitConversion::InchesToPixels( column->GetWidth() ); if( pixelWidth == 0 ) pixelWidth = restWidth; left += pixelWidth; dc->MoveTo( left, r.top ); dc->LineTo( left, r.bottom ); } } dc->SelectStockObject( NULL_PEN ); } ///////////////////////////////// // Loop and print column strings // int top = r.top; for(int t = start ; t < end ; t++ ) { // Tokenize a line of data CString line( m_data[ t ] ); int quarterHeight = lineHeight / 4; // Check if this is a separator if( IsSeparator( line ) ) { // Draw a line across the grid dc->SelectStockObject( BLACK_PEN ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); } else if( IsDoubleSeparator( line ) ) { // Draw a double line across the grid dc->SelectStockObject( BLACK_PEN ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); dc->MoveTo( r.left, top + quarterHeight * 2 ); dc->LineTo( r.right, top + quarterHeight * 2 ); } else if( IsBoldSeparator( line ) ) { // Draw a bold line across the grid boldPen.CreatePen( PS_SOLID, quarterHeight / 2, RGB( 0, 0, 0 ) ); dc->SelectObject( boldPen ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); dc->SelectStockObject( BLACK_PEN ); } else { CTokenizer tok( line, _T( "|" ) ); int left = r.left; // Loop columns for( int i = 0 ; i < max ; i++ ) { CColumn* column = m_columns.GetAt( i ); CRect drawRect( left, top, r.right, top + lineHeight ); if( column ) { // Get the data for this column CString data; tok.GetAt( i, data ); // Get the width of the column int pixelWidth = CUnitConversion::InchesToPixels( column->GetWidth() ); if( pixelWidth == 0 ) pixelWidth = restWidth; // Set font CFont* font = fonts.GetAt( i ); CFont* specialFont = NULL; if( font ) { if( IsBold( data ) ) { // Select a bold font // here instead specialFont = new CFont; LOGFONT lf; font->GetLogFont( &lf ); lf.lfWeight = FW_BOLD; specialFont->CreateFontIndirect( &lf ); } if( IsItalic( data )) { // Select an italic font // here instead specialFont = new CFont; LOGFONT lf; font->GetLogFont( &lf ); lf.lfItalic = TRUE; specialFont->CreateFontIndirect( &lf ); } } if( specialFont ) dc->SelectObject( specialFont ); else if( font ) dc->SelectObject( font ); // Create draw rect drawRect.SetRect( left, top, left + pixelWidth, top + lineHeight ); // Add offsets for columns int offset = CUnitConversion::PointsToPixels( column->GetFontSize() / 40.0 ); if( borderline->GetVisible() && i == 0 ) offset += max( 1, CUnitConversion::InchesToPixels( borderline->GetThickness() ) ); if( columnline->GetVisible() && i > 0 ) offset += max( 1, CUnitConversion::InchesToPixels( columnline->GetThickness() ) ); drawRect.left += offset; drawRect.right -= offset; // Draw data int justification = column->GetJustification(); dc->DrawText( data, drawRect, DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK | justification ); if( specialFont ) delete specialFont; // Increase x-coord left += pixelWidth; } ///////////////////////////////// // Row dividers // if( rowpen && t < end ) { dc->SelectObject( rowpen ); dc->MoveTo( r.left, drawRect.bottom ); dc->LineTo( r.right, drawRect.bottom ); } } } // Increase y-coord top += lineHeight; } ///////////////////////////////// // Restore everything // dc->SetBkMode( mode ); dc->SetTextColor( color ); dc->SelectStockObject( ANSI_VAR_FONT ); dc->SelectStockObject( NULL_PEN ); if( columnpen ) delete columnpen; if( rowpen ) delete rowpen; }
void AFX_GLOBAL_DATA::UpdateFonts() { CWindowDC dc(NULL); m_dblRibbonImageScale = dc.GetDeviceCaps(LOGPIXELSX) / 96.0f; if (m_dblRibbonImageScale > 1. && m_dblRibbonImageScale < 1.1) { m_dblRibbonImageScale = 1.; } if (fontRegular.GetSafeHandle() != NULL) { ::DeleteObject(fontRegular.Detach()); } if (fontTooltip.GetSafeHandle() != NULL) { ::DeleteObject(fontTooltip.Detach()); } if (fontBold.GetSafeHandle() != NULL) { ::DeleteObject(fontBold.Detach()); } if (fontDefaultGUIBold.GetSafeHandle() != NULL) { ::DeleteObject(fontDefaultGUIBold.Detach()); } if (fontUnderline.GetSafeHandle() != NULL) { ::DeleteObject(fontUnderline.Detach()); } if (fontDefaultGUIUnderline.GetSafeHandle() != NULL) { ::DeleteObject(fontDefaultGUIUnderline.Detach()); } if (fontVert.GetSafeHandle() != NULL) { ::DeleteObject(fontVert.Detach()); } if (fontVertCaption.GetSafeHandle() != NULL) { ::DeleteObject(fontVertCaption.Detach()); } if (fontMarlett.GetSafeHandle() != NULL) { ::DeleteObject(fontMarlett.Detach()); } if (fontSmall.GetSafeHandle() != NULL) { ::DeleteObject(fontSmall.Detach()); } // Initialize fonts: NONCLIENTMETRICS info; info.cbSize = sizeof(info); GetNonClientMetrics (info); LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfCharSet = (BYTE) GetTextCharsetInfo(dc.GetSafeHdc(), NULL, 0); lf.lfHeight = info.lfMenuFont.lfHeight; lf.lfWeight = info.lfMenuFont.lfWeight; lf.lfItalic = info.lfMenuFont.lfItalic; //------------------ // Adjust font size: //------------------ int nFontHeight = lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight; if (nFontHeight <= 12) { nFontHeight = 11; } else if (!m_bDontReduceFontHeight) { nFontHeight--; } lf.lfHeight = (lf.lfHeight < 0) ? -nFontHeight : nFontHeight; // Check if we should use system font lstrcpy(lf.lfFaceName, info.lfMenuFont.lfFaceName); BOOL fUseSystemFont = m_bUseSystemFont || (info.lfMenuFont.lfCharSet > SYMBOL_CHARSET); if (!fUseSystemFont) { // Check for "Segoe UI" or "Tahoma" font existance: if (::EnumFontFamilies(dc.GetSafeHdc(), NULL, FontFamilyProcFonts, (LPARAM)(LPCTSTR) AFX_FONT_NAME_OFFICE_2007) == 0) { // Found! Use MS Office 2007 font! lstrcpy(lf.lfFaceName, AFX_FONT_NAME_OFFICE_2007); lf.lfQuality = 5 /*CLEARTYPE_QUALITY*/; } else if (::EnumFontFamilies(dc.GetSafeHdc(), NULL, FontFamilyProcFonts, (LPARAM)(LPCTSTR) AFX_FONT_NAME_OFFICE) == 0) { // Found! Use MS Office font! lstrcpy(lf.lfFaceName, AFX_FONT_NAME_OFFICE); } else { // Not found. Use default font: lstrcpy(lf.lfFaceName, AFX_FONT_NAME_DEFAULT); } } fontRegular.CreateFontIndirect(&lf); // Create small font: LONG lfHeightSaved = lf.lfHeight; lf.lfHeight = (long)((1. + abs(lf.lfHeight)) * 2 / 3); if (lfHeightSaved < 0) { lf.lfHeight = -lf.lfHeight; } fontSmall.CreateFontIndirect(&lf); lf.lfHeight = lfHeightSaved; // Create tooltip font: NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(ncm); GetNonClientMetrics (ncm); lf.lfItalic = ncm.lfStatusFont.lfItalic; lf.lfWeight = ncm.lfStatusFont.lfWeight; fontTooltip.CreateFontIndirect(&lf); lf.lfItalic = info.lfMenuFont.lfItalic; lf.lfWeight = info.lfMenuFont.lfWeight; // Create "underline" font: lf.lfUnderline = TRUE; fontUnderline.CreateFontIndirect(&lf); lf.lfUnderline = FALSE; // Create bold font: lf.lfWeight = FW_BOLD; fontBold.CreateFontIndirect(&lf); // Create Marlett font: BYTE bCharSet = lf.lfCharSet; lf.lfWeight = info.lfMenuFont.lfWeight; lf.lfCharSet = SYMBOL_CHARSET; lf.lfWeight = 0; lf.lfHeight = ::GetSystemMetrics(SM_CYMENUCHECK) - 1; lstrcpy(lf.lfFaceName, AFX_FONT_NAME_MARLETT); fontMarlett.CreateFontIndirect(&lf); lf.lfCharSet = bCharSet; // Restore charset // Create vertical font: CFont font; if (font.CreateStockObject(DEFAULT_GUI_FONT)) { if (font.GetLogFont(&lf) != 0) { lf.lfOrientation = 900; lf.lfEscapement = 2700; lf.lfHeight = info.lfMenuFont.lfHeight; lf.lfWeight = info.lfMenuFont.lfWeight; lf.lfItalic = info.lfMenuFont.lfItalic; { lstrcpy(lf.lfFaceName, AFX_FONT_NAME_VERT); } fontVert.CreateFontIndirect(&lf); lf.lfEscapement = 900; fontVertCaption.CreateFontIndirect(&lf); } } // Create dialog underline and bold fonts: CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); ASSERT_VALID(pDefaultGUIFont); pDefaultGUIFont->GetLogFont(&lf); lf.lfUnderline = TRUE; fontDefaultGUIUnderline.CreateFontIndirect(&lf); lf.lfUnderline = FALSE; lf.lfWeight = FW_BOLD; fontDefaultGUIBold.CreateFontIndirect(&lf); UpdateTextMetrics(); #if 0 // Notify toolbars about font changing: for (POSITION posTlb = afxAllToolBars.GetHeadPosition(); posTlb != NULL;) { CMFCToolBar* pToolBar = (CMFCToolBar*) afxAllToolBars.GetNext(posTlb); ENSURE(pToolBar != NULL); if (CWnd::FromHandlePermanent(pToolBar->m_hWnd) != NULL) { ASSERT_VALID(pToolBar); pToolBar->OnGlobalFontsChanged(); } } #endif }
BOOL CDlgExtractSignature::OnInitDialog() { #ifndef _UNSTABLE CDialog::OnInitDialog(); // TODO: Zusätzliche Initialisierung hier einfügen LOGFONT LogFont; char DefaultFontName[32]; LONG defaultFontWeight; CFont *defaultFont = m_DefEditCtrl.GetFont(); defaultFont->GetLogFont( &LogFont ); // Default Systemschrift ermitteln strncpy(DefaultFontName, LogFont.lfFaceName, 32); // Default Wert sichern defaultFontWeight = LogFont.lfWeight; // Default Wert sichern LogFont.lfWeight = FW_BOLD; // Auf Fettdruck umstellen Font.CreateFontIndirect( &LogFont ); // Font initialisieren m_TextMsgCtrl.SetFont(&Font); m_TextSigCtrl.SetFont(&Font); m_TextSignerCtrl.SetFont(&Font); m_TextKeyCtrl.SetFont(&Font); m_TextAlgCtrl.SetFont(&Font); LogFont.lfWeight = defaultFontWeight; // Auf default Wert zurückstellen strncpy(LogFont.lfFaceName, "Courier", 32); // Auf Courier umstellen Font2.CreateFontIndirect( &LogFont ); // Font2 initialisieren m_MessageCtrl.SetFont(&Font2); m_SignatureCtrl.SetFont(&Font2); //strncpy(LogFont.lfFaceName, DefaultFontStyle, 32); LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE,pc_str,STR_LAENGE_STRING_TABLE); m_TextSig = (CString) pc_str; LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNED_MESSAGE,pc_str,STR_LAENGE_STRING_TABLE); m_TextMsg = (CString) pc_str; LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_ORIGINATOR,pc_str,STR_LAENGE_STRING_TABLE); m_TextSigner = (CString) pc_str; LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_USED_KEY,pc_str,STR_LAENGE_STRING_TABLE); m_TextKey = (CString) pc_str; LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_METHOD,pc_str,STR_LAENGE_STRING_TABLE); m_TextAlg = (CString) pc_str; UpdateData(FALSE); int err; bool messagefromfile=false; // zeigt an, ob die signierte Nachricht aus einer Datei // gelesen werden musste CString filename; CString SigAlg=""; CString HashAlg=""; CString UserKeyId=""; int SignLength; // (Aus dem Ausgabefenster eingelesene) Länge der Signatur in Bits CKeyFile FileHandling; SignatureType = GetSignData(inFileName,messagefromfile,filename,&message,SigAlg,HashAlg,UserKeyId,&SignLength,&Signatur,c,d); // Folgende Speicherbereiche sind von GetSignData() alloziert worden und // müssen später wieder freigegeben werden: // message.octets (falls != NULL) // Signatur.signature.bits (falls != NULL) if ( (SignatureType > 0) && (SignatureType != EC_SIGN) &&\ (SignatureType != RSA_OR_DSA_SIGN) && (SignatureType != UNKNOWN_SIGN) ) { // Fehler beim auslesen der Daten (Nicht genügend Speicher vorhanden) Message(IDS_STRING_ERR_MEMORY_SIGNATURE_VERIFICATION, MB_ICONSTOP); if (Signatur.signature.bits) free(Signatur.signature.bits); if (message.octets) free(message.octets); EndDialog(-1); return TRUE; } else if ((SignatureType != EC_SIGN) && (SignatureType != RSA_OR_DSA_SIGN) &&\ (SignatureType != UNKNOWN_SIGN)) { Message(IDS_STRING_ASYMKEY_COULD_NOT_EXTRACT_SIGNATURE,MB_ICONSTOP); if (Signatur.signature.bits) free(Signatur.signature.bits); if (message.octets) free(message.octets); EndDialog(-2); return TRUE; } if (messagefromfile == true) { // Die signierte Nachricht ist zu gross und passt nicht komplett // in ein CEdit Feld. Es wird lediglich ein erster Teil der Nachricht dargestellt LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNED_MESSAGE_FIRST_PART,pc_str,STR_LAENGE_STRING_TABLE); m_TextMsg = (CString) pc_str; } // Überprüfe, ob angegebener Schlüsselbezeichner tatsächlich existiert bool keyExists = FileHandling.FilenameExisting(UserKeyId); char *name=NULL; char *firstname=NULL; char *keyType=NULL; char *keyInfo=NULL; char *creattime=NULL; char *ctstr=NULL; CString kInfo; if (keyExists == true) { err = FileHandling.ExtractData(UserKeyId,&ctstr,&creattime,&name,&firstname,&keyType,&keyInfo); if (ctstr) free(ctstr); // wird hier nicht benötigt if (keyInfo==NULL) kInfo=""; else kInfo = ((CString)" (")+((CString)keyInfo)+((CString)") "); // Infos über den Signaturersteller m_InfoAboutSigner = (CString) ((CString)firstname)+((CString)" ")+((CString)name); // Signatur erzeugt von: // Infos über Schlüssel LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_DATE,pc_str1,STR_LAENGE_STRING_TABLE); sprintf(pc_str, pc_str1,((CString)keyType)+kInfo,((CString)creattime)); m_KeyInfo = (CString) pc_str; // Benutzter Schlüssel: } else { // Schlüsselbezeichner "UserKeyId" existiert nicht LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_UNKNOWN_KEY_IDENTIFIER,pc_str1,STR_LAENGE_STRING_TABLE); // pc_str1 = "Übermittelter Schlüsselbezeichner existiert nicht!" m_InfoAboutSigner = ((CString)pc_str1); // Signaturerzeuger unbekannt } // Überprüfe ob angegebener Signatur-/Hashalgorithmus bekannt ist if ( (SigAlg!="RSA") && (SigAlg!="DSA") && (SigAlg!="ECSP-NR") && (SigAlg!="ECSP-DSA") ) { // unbekannter Signaturalgorithmus angegeben LoadString(AfxGetInstanceHandle(),IDS_STRING_UNKNOWN,pc_str,STR_LAENGE_STRING_TABLE); // pc_str = "unbekannt !" SigAlg = SigAlg+((CString)" (")+((CString)pc_str)+((CString)")"); } if ( (HashAlg!="MD2") && (HashAlg!="MD5") && (HashAlg!="SHA") && (HashAlg!="SHA-1") &&\ (HashAlg!="RIPEMD-160") ) { // unbekannter Hashalgorithmus angegeben LoadString(AfxGetInstanceHandle(),IDS_STRING_UNKNOWN,pc_str,STR_LAENGE_STRING_TABLE); // pc_str = "unbekannt !" HashAlg = HashAlg+((CString)" (")+((CString)pc_str)+((CString)")"); } // Benutzter Signaturalgorithmus LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_HASH_FUNCTION,pc_str1,STR_LAENGE_STRING_TABLE); sprintf(pc_str, pc_str1, SigAlg, HashAlg); m_SigHashAlg = (CString) pc_str; UpdateData(FALSE); int srcSize; int destSize; // Signierte Nachricht ausgeben if (message.noctets != 0) { // Nachricht ist kein leerer String srcSize = message.noctets; destSize = ((srcSize+hexdumpCols-1)/hexdumpCols)*(11+hexdumpCols*4)-hexdumpCols+(srcSize%hexdumpCols)+1; char *msgdata = (char *) malloc(destSize+1); err = HexDumpMem(msgdata, destSize, (unsigned char *) message.octets, srcSize, hexdumpCols); if (err == 0) { // Fehler if (Signatur.signature.bits) free(Signatur.signature.bits); if (message.octets) free(message.octets); return TRUE; } CString mData(msgdata); m_Message = mData; free(msgdata); } // Länge der signierten Nachricht char buffer[30]; _itoa( message.noctets, buffer, 10 ); LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_MESSAGE_LENGTH,pc_str1,STR_LAENGE_STRING_TABLE); sprintf(pc_str, pc_str1,((CString)buffer)); m_MessageLength = (CString) pc_str; UpdateData(FALSE); if (SignatureType == EC_SIGN) { // CheckRadioButton (IDC_RADIO1, IDC_RADIO4, IDC_RADIO3); UpdateData(TRUE); base = 10; // Signatur als Dezimalzahlen darstellen int signlength = theApp.SecudeLib.lngtouse(c)+theApp.SecudeLib.lngtouse(d)+2;// Bit-Länge der Signatur char buffer[30]; _itoa( signlength, buffer, 10 ); LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_LENGTH,pc_str1,STR_LAENGE_STRING_TABLE); sprintf(pc_str, pc_str1,((CString)buffer)); m_SignatureLength = (CString) pc_str; UpdateData(FALSE); UpdateSigEditBox(); } else if (SignatureType == RSA_OR_DSA_SIGN) { // CheckRadioButton (IDC_RADIO1, IDC_RADIO4, IDC_RADIO1); UpdateData(TRUE); base = -1; // Signatur als Octets darstellen srcSize = (Signatur.signature.nbits+7)/8; destSize = ((srcSize+hexdumpCols-1)/hexdumpCols)*(11+hexdumpCols*4)-hexdumpCols+(srcSize%hexdumpCols)+1; char *sigdata = (char *) malloc(destSize+1); err = HexDumpMem(sigdata, destSize, (unsigned char *) Signatur.signature.bits, srcSize, hexdumpCols); if (err == 0) { // Fehler if (Signatur.signature.bits) free(Signatur.signature.bits); if (message.octets) free(message.octets); return TRUE; } m_Signature = (CString) sigdata; UpdateData(FALSE); free(sigdata); char buffer[30]; _itoa( Signatur.signature.nbits, buffer, 10 ); LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGNATURE_LENGTH,pc_str1,STR_LAENGE_STRING_TABLE); sprintf(pc_str, pc_str1,((CString)buffer)); m_SignatureLength = (CString) pc_str; UpdateData(FALSE); } else // (SignatureType == UNKNOWN_SIGN) { // unbekanntes Signaturverfahren angegeben m_RadioOctets.EnableWindow(FALSE); m_RadioOktal.EnableWindow(FALSE); m_RadioDezimal.EnableWindow(FALSE); m_RadioHexadezimal.EnableWindow(FALSE); } #endif return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben }
void CPropertiesWnd::InitPropList() { SetPropListFont(); m_wndPropList.EnableHeaderCtrl(FALSE); m_wndPropList.EnableDescriptionArea(); m_wndPropList.SetVSDotNetLook(); m_wndPropList.MarkModifiedProperties(); CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("모양")); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("3D 모양"), (_variant_t) false, _T("창에 굵은 글꼴이 아닌 글꼴을 지정하고, 컨트롤에 3D 테두리를 지정합니다."))); CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("테두리"), _T("Dialog Frame"), _T("None, Thin, Resizable 또는 Dialog Frame 중 하나를 지정합니다.")); pProp->AddOption(_T("None")); pProp->AddOption(_T("Thin")); pProp->AddOption(_T("Resizable")); pProp->AddOption(_T("Dialog Frame")); pProp->AllowEdit(FALSE); pGroup1->AddSubItem(pProp); pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("캡션"), (_variant_t) _T("정보"), _T("창의 제목 표시줄에 표시되는 텍스트를 지정합니다."))); m_wndPropList.AddProperty(pGroup1); CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("창 크기"), 0, TRUE); pProp = new CMFCPropertyGridProperty(_T("높이"), (_variant_t) 250l, _T("창의 높이를 지정합니다.")); pProp->EnableSpinControl(TRUE, 50, 300); pSize->AddSubItem(pProp); pProp = new CMFCPropertyGridProperty( _T("너비"), (_variant_t) 150l, _T("창의 너비를 지정합니다.")); pProp->EnableSpinControl(TRUE, 50, 200); pSize->AddSubItem(pProp); m_wndPropList.AddProperty(pSize); CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("글꼴")); LOGFONT lf; CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); font->GetLogFont(&lf); lstrcpy(lf.lfFaceName, _T("맑은 고딕")); pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("글꼴"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("창의 기본 글꼴을 지정합니다."))); pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("시스템 글꼴을 사용합니다."), (_variant_t) true, _T("창에서 MS Shell Dlg 글꼴을 사용하도록 지정합니다."))); m_wndPropList.AddProperty(pGroup2); CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("기타")); pProp = new CMFCPropertyGridProperty(_T("(이름)"), _T("응용 프로그램")); pProp->Enable(FALSE); pGroup3->AddSubItem(pProp); CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("창 색상"), RGB(210, 192, 254), NULL, _T("창의 기본 색상을 지정합니다.")); pColorProp->EnableOtherButton(_T("기타...")); pColorProp->EnableAutomaticButton(_T("기본값"), ::GetSysColor(COLOR_3DFACE)); pGroup3->AddSubItem(pColorProp); static TCHAR BASED_CODE szFilter[] = _T("아이콘 파일(*.ico)|*.ico|모든 파일(*.*)|*.*||"); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("아이콘"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("창 아이콘을 지정합니다."))); pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("폴더"), _T("c:\\"))); m_wndPropList.AddProperty(pGroup3); CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("계층")); CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("첫번째 하위 수준")); pGroup4->AddSubItem(pGroup41); CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("두 번째 하위 수준")); pGroup41->AddSubItem(pGroup411); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("항목 1"), (_variant_t) _T("값 1"), _T("설명입니다."))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("항목 2"), (_variant_t) _T("값 2"), _T("설명입니다."))); pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("항목 3"), (_variant_t) _T("값 3"), _T("설명입니다."))); pGroup4->Expand(FALSE); m_wndPropList.AddProperty(pGroup4); }