void CPopupEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CWnd *Parent = GetParent(); ASSERT_VALID(Parent); if (m_bIsEmbeddedIntoListCtrl && (VK_ESCAPE == nChar || VK_RETURN == nChar)) { if (VK_ESCAPE == nChar) m_bESC = true; Parent->SetFocus(); return; } CEdit::OnChar(nChar, nRepCnt, nFlags); if (m_bIsEmbeddedIntoListCtrl) { CString str; GetWindowText( str ); CWindowDC dc(this); CFont *pFont = Parent->GetFont(); ASSERT_VALID(pFont); CFont *pFontDC = dc.SelectObject(pFont); ASSERT_VALID(pFontDC); CSize size = dc.GetTextExtent(str); dc.SelectObject(pFontDC); size.cx += 5; CRect rect, parentrect; GetClientRect(&rect); Parent->GetClientRect(&parentrect); Parent->ScreenToClient(&rect); if (size.cx > rect.Width()) { if (size.cx + rect.left < parentrect.right) rect.right = rect.left + size.cx; else rect.right = parentrect.right; MoveWindow(&rect); } } }
void CPaymentHistory::Setfont(UINT nID) { CWnd *pWnd; pWnd = GetDlgItem(nID); LOGFONT lf; CFont *font = pWnd->GetFont(); if (font) { font->GetLogFont(&lf); TRACE("Typeface name of font = %s\n", lf.lfFaceName); } lf.lfWeight = 700; HFONT hfont = ::CreateFontIndirect(&lf); CFont* pfont = CFont::FromHandle(hfont); pWnd->SetFont(pfont); }
int GraphicsMisc::GetTextWidth(const CString& sText, CWnd& wndRef, CFont* pRefFont) { CDC* pDC = wndRef.GetDC(); ASSERT(pDC); if (!pDC) return -1; if (pRefFont == NULL) pRefFont = wndRef.GetFont(); CFont* pOldFont = pDC->SelectObject(pRefFont); int nLength = pDC->GetTextExtent(sText).cx; pDC->SelectObject(pOldFont); wndRef.ReleaseDC(pDC); return nLength; }
BOOL CTDLShowReminderDlg::OnInitDialog() { BOOL bRes = CDialog::OnInitDialog(); // do we need to play a sound? if (!m_sSoundFile.IsEmpty()) PlaySound(m_sSoundFile, NULL, SND_FILENAME); CWnd* pTitle = GetDlgItem(IDC_TASKTITLE); ASSERT(pTitle); CFont* pFont = pTitle->GetFont(); ASSERT(pFont); if (GraphicsMisc::CreateFont(m_fontBold, *pFont, GMFS_BOLD, GMFS_BOLD)) pTitle->SetFont(&m_fontBold); return bRes; }
void CMlsSimpleBitmapButton::Initialize(UINT nID, CWnd* pParent) { CString csText; TRY { CWnd* pControl = pParent->GetDlgItem(nID); if (pControl != NULL) { CRect crControl; pControl->GetWindowRect(crControl); pParent->ScreenToClient(crControl); pControl->GetWindowText(csText); Create(NULL, csText, pControl->GetStyle(), crControl, pParent, nID, NULL); SetWindowPos(pControl, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); SetFont(pControl->GetFont()); pControl->DestroyWindow(); } } END_TRY }
void CnHyperlink::PreSubclassWindow() { ModifyStyle(0, SS_OWNERDRAW | SS_NOTIFY); if (bUseParentFont_) { CWnd* pParent = GetParent(); if (pParent) { LOGFONT lf; pParent->GetFont()->GetLogFont(&lf); lf.lfUnderline = UnderLineMode_ == ULM_ALWAYS ? TRUE : FALSE; Font_.DeleteObject(); Font_.CreateFontIndirect(&lf); } } CStatic::PreSubclassWindow(); }
void CMenuButton::FixFont() { CWnd* pWnd = GetParent(); if (pWnd == nullptr) return; CFont* pFont = pWnd->GetFont(); if (pFont == nullptr) return; LOGFONT logfont; if (pFont->GetLogFont(&logfont) == 0) return; if (m_Font.CreateFontIndirect(&logfont) == FALSE) return; SetFont(&m_Font); Invalidate(); }
BOOL CListViewWalkerPropertySheet::OnInitDialog() { BOOL bResult = CResizableSheet::OnInitDialog(); ////////////////////////////////////////////////////////////////////////// // Add additional controls // if (m_pListCtrl != NULL) { // switching from multi-selection to single selection is currently not supported -> disable Up/Down controls DWORD dwCtrlStyle = (m_aItems.GetSize()>1) ? WS_DISABLED : 0; const struct { CButton *pCtlBtn; UINT uCtlId; LPCTSTR pszLabel; LPCTSTR pszSymbol; DWORD dwStyle; } aCtrls[] = { { &m_ctlPrev, IDC_PREV, _T("&Prev"), _T("5"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP }, { &m_ctlNext, IDC_NEXT, _T("&Next"), _T("6"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP } }; int iLeftMostButtonId = IDOK; int iMax = 32767; static const int _aiPropSheetButtons[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP }; for (int i = 0; i < ARRSIZE(_aiPropSheetButtons); i++) { CWnd* pBtn = GetDlgItem(_aiPropSheetButtons[i]); if (pBtn /*&& pBtn->IsWindowVisible()*/) { CRect rcBtn; pBtn->GetWindowRect(&rcBtn); ScreenToClient(&rcBtn); if (rcBtn.left < iMax) { iMax = rcBtn.left; iLeftMostButtonId = _aiPropSheetButtons[i]; } } } CWnd* pctlOk = GetDlgItem(iLeftMostButtonId); CRect rcOk; pctlOk->GetWindowRect(&rcOk); ScreenToClient(&rcOk); CFont* pDefCtrlFont = pctlOk->GetFont(); for (int i = 0; i < ARRSIZE(aCtrls); i++) { const int iNaviBtnWidth = rcOk.Width()/2; CRect rc; rc.left = rcOk.left - (8 + iNaviBtnWidth) * (ARRSIZE(aCtrls) - i); rc.top = rcOk.top; rc.right = rc.left + iNaviBtnWidth; rc.bottom = rc.top + rcOk.Height(); VERIFY( aCtrls[i].pCtlBtn->Create(aCtrls[i].pszLabel, dwCtrlStyle | aCtrls[i].dwStyle, rc, this, aCtrls[i].uCtlId) ); if (theApp.m_fontSymbol.m_hObject) { aCtrls[i].pCtlBtn->SetFont(&theApp.m_fontSymbol); aCtrls[i].pCtlBtn->SetWindowText(aCtrls[i].pszSymbol); // show down-arrow } else aCtrls[i].pCtlBtn->SetFont(pDefCtrlFont); AddAnchor(*aCtrls[i].pCtlBtn, BOTTOM_RIGHT); } } return bResult; }
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 CXTPPropertyGridInplaceList::Create(CXTPPropertyGridItem* pItem, CRect rect) { ASSERT(pItem && pItem->GetGrid()); if (!pItem) return; CRect rcValue(rect); rcValue.left = pItem->GetGrid()->GetDividerPos() + 1; CWnd* pParent = (CWnd*)pItem->GetGrid(); m_pItem = pItem; DestroyWindow(); if (!m_hWnd) { CListBox::CreateEx(WS_EX_TOOLWINDOW | (pParent->GetExStyle() & WS_EX_LAYOUTRTL), _T("LISTBOX"), _T(""), LBS_NOTIFY | WS_CHILD | WS_VSCROLL | WS_BORDER | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS, CRect(0, 0, 0, 0), pParent, 0); SetOwner(pParent); if (m_bShowShadow && XTPSystemVersion()->IsWinXPOrGreater()) SetClassLongPtr(m_hWnd, GCL_STYLE, GetClassLongPtr(m_hWnd, GCL_STYLE) | 0x00020000); } SetFont(pParent->GetFont()); ResetContent(); CXTPPropertyGridItemConstraints* pList = pItem->GetConstraints(); int dx = rect.right - rcValue.left; CWindowDC dc(pParent); CXTPFontDC font(&dc, pParent->GetFont()); int nHeight = dc.GetTextExtent(_T(" "), 1).cy + 3; for (int i = 0; i < pList->GetCount(); i++) { CXTPPropertyGridItemConstraint* pConstraint = pList->GetConstraintAt(i); CString str = pConstraint->m_strConstraint; int nIndex = AddString(str); SetItemDataPtr(nIndex, pConstraint); CSize sz = pItem->OnMergeItemConstraint(&dc, pConstraint); dx = max(dx, sz.cx); nHeight = max(nHeight, sz.cy); if (pItem->GetValue() == str) SetCurSel(nIndex); } SetItemHeight(0, nHeight); rect.top = rect.bottom; rect.bottom += nHeight * __min(pItem->GetDropDownItemCount(), GetCount()) + 2; rect.left = rect.right - __min(dx, rect.Width() - XTP_PGI_EXPAND_BORDER); pParent->ClientToScreen(&rect); CRect rcWork = XTPMultiMonitor()->GetWorkArea(rect); if (rect.bottom > rcWork.bottom && rect.top > rcWork.CenterPoint().y) { rect.OffsetRect(0, - rect.Height() - rcValue.Height() - 1); } if (rect.left < rcWork.left) rect.OffsetRect(rcWork.left - rect.left, 0); if (rect.right > rcWork.right) rect.OffsetRect(rcWork.right - rect.right, 0); SetFocus(); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, 0); ModifyStyle(WS_CHILD, WS_POPUP); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, (LONG_PTR)pParent->m_hWnd); SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); CXTPMouseMonitor::SetupHook(this); }
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); CFont* pOldDCFont = NULL; if (m_fontNormal.m_hObject != NULL){ pOldDCFont = pdc->SelectObject(&m_fontNormal); } 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) ); } } pdc->SetTextColor(m_crTooltipTextColor); int iTextHeight = 0; int iMaxCol1Width = 0; int iMaxCol2Width = 0; int iMaxSingleLineWidth = 0; CSize sizText(0); int iPos = 0; int iCaptionEnd = m_bShowFileIcon ? max(strText.Find(_T("\n<br_head>\n")), 0) : 0; // special tooltip with file icon int iCaptionHeigth = 0; int iIconMinYBorder = 3; int iIconSize = theApp.GetBigSytemIconSize().cx; int iIconDrawingSpace = iIconSize + 9; 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 + ((m_bShowFileIcon && iPos <= iCaptionEnd + strLine.GetLength()) ? iIconDrawingSpace : 0)); iTextHeight = siz.cy + 1; // update height with 'col1' string, because 'col2' string might be empty and therefore has no height if (iPos <= iCaptionEnd) iCaptionHeigth += siz.cy + 1; else sizText.cy += siz.cy + 1; LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1; while (_istspace((_TUCHAR)*pszCol2)) pszCol2++; if (*pszCol2 != _T('\0')) { siz = pdc->GetTextExtent(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2); iMaxCol2Width = max(iMaxCol2Width, siz.cx); } } else if (m_bShowFileIcon && iPos <= iCaptionEnd && iPos == strLine.GetLength() + 1){ // file name, printed bold on top without any tabbing or desc CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; CSize siz = pdc->GetTextExtent(strLine); if (pOldFont) pdc->SelectObject(pOldFont); iMaxSingleLineWidth = max(iMaxSingleLineWidth, siz.cx + iIconDrawingSpace); iCaptionHeigth += siz.cy + 1; } else if (!strLine.IsEmpty() && strLine.Compare(_T("<br>")) != 0 && strLine.Compare(_T("<br_head>")) != 0) { CSize siz = pdc->GetTextExtent(strLine); iMaxSingleLineWidth = max(iMaxSingleLineWidth, siz.cx + ((iPos <= iCaptionEnd) ? iIconDrawingSpace : 0)); if (m_bShowFileIcon && iPos <= iCaptionEnd + strLine.GetLength()) iCaptionHeigth += siz.cy + 1; else sizText.cy += siz.cy + 1; } else{ CSize siz = pdc->GetTextExtent(_T(" "), 1); sizText.cy += siz.cy; } } if (m_bShowFileIcon && iCaptionEnd > 0) iCaptionHeigth = max(iCaptionHeigth, iIconSize + (2*iIconMinYBorder)); sizText.cy += iCaptionHeigth; iMaxCol1Width = min(m_iScreenWidth4, iMaxCol1Width); iMaxCol2Width = min(m_iScreenWidth4*2, iMaxCol2Width); const int iMiddleMargin = 6; iMaxSingleLineWidth = max(iMaxSingleLineWidth, iMaxCol1Width + iMiddleMargin + iMaxCol2Width); sizText.cx = iMaxSingleLineWidth; CRect rcNewSize(rcWnd.left, rcWnd.top, rcWnd.left + sizText.cx, rcWnd.top + sizText.cy); AdjustRect(&rcNewSize); rcWnd.right = rcWnd.left + rcNewSize.Width(); rcWnd.bottom = rcWnd.top + rcNewSize.Height(); 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)); } CPoint ptText(pNMCD->nmcd.rc.left, pNMCD->nmcd.rc.top); pwnd->MoveWindow(&rcWnd); pwnd->ScreenToClient(&rcWnd); pNMCD->nmcd.rc.right = rcWnd.right; pNMCD->nmcd.rc.bottom = rcWnd.bottom; pdc->FillSolidRect(&rcWnd, m_crTooltipBkColor); iPos = 0; while (iPos != -1) { CString strLine = GetNextString(strText, _T('\n'), iPos); int iColon = strLine.Find(_T(':')); CRect rcDT; if (!m_bShowFileIcon || (unsigned)iPos > (unsigned)iCaptionEnd + strLine.GetLength()) rcDT.SetRect(ptText.x, ptText.y, ptText.x + iMaxCol1Width, ptText.y + iTextHeight); else rcDT.SetRect(ptText.x + iIconDrawingSpace, ptText.y, ptText.x + iMaxCol1Width, ptText.y + iTextHeight); if (iColon != -1) { // 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((_TUCHAR)*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 if (m_bShowFileIcon && iPos <= iCaptionEnd && iPos == strLine.GetLength() + 1){ // first line on special fileicon tab - draw icon and bold filename CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; pdc->DrawText(strLine, CRect(ptText.x + iIconDrawingSpace, ptText.y, ptText.x + iMaxSingleLineWidth, ptText.y + iTextHeight), m_dwCol1DrawTextFlags); if (pOldFont) pdc->SelectObject(pOldFont); ptText.y += iTextHeight; int iImage = theApp.GetFileTypeSystemImageIdx(strLine, -1, true); if (theApp.GetBigSystemImageList() != NULL) ::ImageList_Draw(theApp.GetBigSystemImageList(), iImage, pdc->GetSafeHdc(), ptText.x, rcDT.top + ((iCaptionHeigth - iIconSize) / 2), ILD_NORMAL|ILD_TRANSPARENT); } else { if (strLine.Compare(_T("<br>")) == 0 || strLine.Compare(_T("<br_head>")) == 0){ CPen pen; pen.CreatePen(0, 1, m_crTooltipTextColor); CPen *pOP = pdc->SelectObject(&pen); pdc->MoveTo(ptText.x, ptText.y + ((iTextHeight - 2) / 2)); pdc->LineTo(ptText.x + iMaxSingleLineWidth, ptText.y + ((iTextHeight - 2) / 2)); ptText.y += iTextHeight; pdc->SelectObject(pOP); pen.DeleteObject(); } else{ CSize siz = pdc->TabbedTextOut(ptText.x, ptText.y, strLine, 0, NULL, 0); ptText.y += siz.cy; } } } if (pOldDCFont) pdc->SelectObject(pOldDCFont); *pResult = CDRF_SKIPDEFAULT; return; } *pResult = CDRF_DODEFAULT; }
void CProgressCtrlEx::OnPaint() { CPaintDC paintDC(this); int nMin = 0; int nMax = 0; GetRange(nMin, nMax); ASSERT(nMin <= nMax); int nPos = GetPos(); ASSERT(nPos >= nMin && nPos <= nMax); DWORD dwStyle = GetStyle(); BOOL bVertical = FALSE; if (dwStyle & PBS_VERTICAL) { bVertical = TRUE; } CDC dc; dc.CreateCompatibleDC(&paintDC); ASSERT(dc.GetSafeHdc()); CRect rect; GetClientRect(&rect); CBitmap bmp; bmp.CreateCompatibleBitmap(&paintDC, rect.Width(), rect.Height()); ASSERT(bmp.GetSafeHandle()); CBitmap* pOldBitmap = (CBitmap*)dc.SelectObject(&bmp); CFont* pOldFont = NULL; CWnd* pParent = GetParent(); ASSERT(pParent); CFont* pFont = pParent->GetFont(); ASSERT(pFont); if (bVertical) { if (NULL == m_font.GetSafeHandle()) { LOGFONT lf = { 0 }; pFont->GetLogFont(&lf); lf.lfEscapement = 900; m_font.CreateFontIndirect(&lf); } ASSERT(m_font.GetSafeHandle()); pOldFont = (CFont*)dc.SelectObject(&m_font); } else { pOldFont = (CFont*)dc.SelectObject(pFont); } double dPercent = (double)(nPos - nMin) / ((double)(nMax - nMin)); dc.DrawEdge(rect, EDGE_SUNKEN, BF_RECT | BF_FLAT); CRect rc(rect); rc.DeflateRect(CSize(2, 2)); dc.FillSolidRect(&rc, m_clrBarBkColor); CString strText(_T("")); GetWindowText(strText); if (m_bShowPercent) { strText.AppendFormat(_T("%d%% "), static_cast<int>((dPercent * 100.0) + 0.5)); } dc.SetBkMode(TRANSPARENT); dc.SetTextColor(m_clrTextColor); CPoint pt(0, 0); CSize size = dc.GetOutputTextExtent(strText); if (!bVertical) { switch (m_AlignText) { case ALIGN_LEFT: pt.x = rc.left; break; case ALIGN_RIGHT: pt.x = rc.right - size.cx; break; case ALIGN_CENTER: default: pt.x = rc.left + (rc.Width() - size.cx) / 2; break; } pt.y = rc.top + (rc.Height() - size.cy) / 2; CRect rcPos(rc); rcPos.right = rcPos.left + (int)(dPercent * rcPos.Width()); dc.FillSolidRect(rcPos, m_clrBarColor); dc.SetTextColor(m_clrTextColor); dc.ExtTextOut(pt.x, pt.y, ETO_OPAQUE, rcPos, strText, NULL); dc.SetTextColor(m_clrTextBkColor); dc.ExtTextOut(pt.x, pt.y, ETO_CLIPPED, &rcPos, strText, NULL); } else { switch (m_AlignText) { case ALIGN_LEFT: pt.y = rc.bottom; break; case ALIGN_RIGHT: pt.y = rc.top + size.cx; break; case ALIGN_CENTER: default: pt.y = rc.bottom - (rc.Height() - size.cx) / 2; break; } pt.x = rc.left + (rc.Width() - size.cy) / 2; CRect rcPos(rc); rcPos.top = rcPos.bottom - (int)(dPercent * rcPos.Height()); dc.FillSolidRect(rcPos, m_clrBarColor); dc.SetTextColor(m_clrTextColor); dc.ExtTextOut(pt.x, pt.y, ETO_OPAQUE, rcPos, strText, NULL); dc.SetTextColor(m_clrTextBkColor); dc.ExtTextOut(pt.x, pt.y, ETO_CLIPPED, &rcPos, strText, NULL); } paintDC.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); dc.SelectObject(pOldFont); dc.SelectObject(pOldBitmap); bmp.DeleteObject(); dc.DeleteDC(); }
BOOL CMuleSystrayDlg::OnInitDialog() { CDialog::OnInitDialog(); m_bClosingDown = false; CRect r; CWnd *p; m_hUpArrow = theApp.LoadIcon(_T("UPLOAD")); m_hDownArrow = theApp.LoadIcon(_T("DOWNLOAD")); m_ctrlUpArrow.SetIcon(m_hUpArrow); m_ctrlDownArrow.SetIcon(m_hDownArrow); bool bValidFont = false; LOGFONT lfStaticFont = {0}; p = GetDlgItem(IDC_SPEED); if(p) { p->GetFont()->GetLogFont(&lfStaticFont); bValidFont = true; } p = GetDlgItem(IDC_SPEED); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlSpeed.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_SPEED); m_ctrlSpeed.m_nBtnID = IDC_SPEED; //p->GetWindowText(m_ctrlSpeed.m_strText); m_ctrlSpeed.m_strText = GetResString(IDS_TRAYDLG_SPEED); m_ctrlSpeed.m_strText.Remove(_T('&')); m_ctrlSpeed.m_bUseIcon = true; m_ctrlSpeed.m_sIcon.cx = 16; m_ctrlSpeed.m_sIcon.cy = 16; m_ctrlSpeed.m_hIcon = theApp.LoadIcon(_T("SPEED"), m_ctrlSpeed.m_sIcon.cx, m_ctrlSpeed.m_sIcon.cy); m_ctrlSpeed.m_bParentCapture = true; if(bValidFont) { LOGFONT lfFont = lfStaticFont; lfFont.lfWeight += 200; // make it bold m_ctrlSpeed.m_cfFont.CreateFontIndirect(&lfFont); } m_ctrlSpeed.m_bNoHover = true; } p = GetDlgItem(IDC_TOMAX); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlAllToMax.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_TOMAX); m_ctrlAllToMax.m_nBtnID = IDC_TOMAX; //p->GetWindowText(m_ctrlAllToMax.m_strText); m_ctrlAllToMax.m_strText = GetResString(IDS_PW_UA); m_ctrlAllToMax.m_strText.Remove(_T('&')); m_ctrlAllToMax.m_bUseIcon = true; m_ctrlAllToMax.m_sIcon.cx = 16; m_ctrlAllToMax.m_sIcon.cy = 16; m_ctrlAllToMax.m_hIcon = theApp.LoadIcon(_T("SPEEDMAX"), m_ctrlAllToMax.m_sIcon.cx, m_ctrlAllToMax.m_sIcon.cy); m_ctrlAllToMax.m_bParentCapture = true; if(bValidFont) m_ctrlAllToMax.m_cfFont.CreateFontIndirect(&lfStaticFont); } p = GetDlgItem(IDC_TOMIN); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlAllToMin.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_TOMIN); m_ctrlAllToMin.m_nBtnID = IDC_TOMIN; //p->GetWindowText(m_ctrlAllToMin.m_strText); m_ctrlAllToMin.m_strText = GetResString(IDS_PW_PA); m_ctrlAllToMin.m_strText.Remove(_T('&')); m_ctrlAllToMin.m_bUseIcon = true; m_ctrlAllToMin.m_sIcon.cx = 16; m_ctrlAllToMin.m_sIcon.cy = 16; m_ctrlAllToMin.m_hIcon = theApp.LoadIcon(_T("SPEEDMIN"), m_ctrlAllToMin.m_sIcon.cx, m_ctrlAllToMin.m_sIcon.cy); m_ctrlAllToMin.m_bParentCapture = true; if(bValidFont) m_ctrlAllToMin.m_cfFont.CreateFontIndirect(&lfStaticFont); } p = GetDlgItem(IDC_RESTORE); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlRestore.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_RESTORE); m_ctrlRestore.m_nBtnID = IDC_RESTORE; //p->GetWindowText(m_ctrlRestore.m_strText); m_ctrlRestore.m_strText = GetResString(IDS_MAIN_POPUP_RESTORE); m_ctrlRestore.m_strText.Remove(_T('&')); m_ctrlRestore.m_bUseIcon = true; m_ctrlRestore.m_sIcon.cx = 16; m_ctrlRestore.m_sIcon.cy = 16; m_ctrlRestore.m_hIcon = theApp.LoadIcon(_T("RESTOREWINDOW"), m_ctrlRestore.m_sIcon.cx, m_ctrlRestore.m_sIcon.cy); m_ctrlRestore.m_bParentCapture = true; if(bValidFont) { LOGFONT lfFont = lfStaticFont; lfFont.lfWeight += 200; // make it bold m_ctrlRestore.m_cfFont.CreateFontIndirect(&lfFont); } } p = GetDlgItem(IDC_CONNECT); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlConnect.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_CONNECT); m_ctrlConnect.m_nBtnID = IDC_CONNECT; //p->GetWindowText(m_ctrlConnect.m_strText); m_ctrlConnect.m_strText = GetResString(IDS_MAIN_BTN_CONNECT); m_ctrlConnect.m_strText.Remove(_T('&')); m_ctrlConnect.m_bUseIcon = true; m_ctrlConnect.m_sIcon.cx = 16; m_ctrlConnect.m_sIcon.cy = 16; m_ctrlConnect.m_hIcon = theApp.LoadIcon(_T("CONNECT"), m_ctrlConnect.m_sIcon.cx, m_ctrlConnect.m_sIcon.cy); m_ctrlConnect.m_bParentCapture = true; if(bValidFont) m_ctrlConnect.m_cfFont.CreateFontIndirect(&lfStaticFont); } p = GetDlgItem(IDC_DISCONNECT); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlDisconnect.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_DISCONNECT); m_ctrlDisconnect.m_nBtnID = IDC_DISCONNECT; //p->GetWindowText(m_ctrlDisconnect.m_strText); m_ctrlDisconnect.m_strText = GetResString(IDS_MAIN_BTN_DISCONNECT); m_ctrlDisconnect.m_strText.Remove(_T('&')); m_ctrlDisconnect.m_bUseIcon = true; m_ctrlDisconnect.m_sIcon.cx = 16; m_ctrlDisconnect.m_sIcon.cy = 16; m_ctrlDisconnect.m_hIcon = theApp.LoadIcon(_T("DISCONNECT"), m_ctrlDisconnect.m_sIcon.cx, m_ctrlDisconnect.m_sIcon.cy); m_ctrlDisconnect.m_bParentCapture = true; if(bValidFont) m_ctrlDisconnect.m_cfFont.CreateFontIndirect(&lfStaticFont); } p = GetDlgItem(IDC_PREFERENCES); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlPreferences.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_PREFERENCES); m_ctrlPreferences.m_nBtnID = IDC_PREFERENCES; //p->GetWindowText(m_ctrlPreferences.m_strText); m_ctrlPreferences.m_strText = GetResString(IDS_EM_PREFS); m_ctrlPreferences.m_strText.Remove(_T('&')); m_ctrlPreferences.m_bUseIcon = true; m_ctrlPreferences.m_sIcon.cx = 16; m_ctrlPreferences.m_sIcon.cy = 16; m_ctrlPreferences.m_hIcon = theApp.LoadIcon(_T("Preferences"), m_ctrlPreferences.m_sIcon.cx, m_ctrlPreferences.m_sIcon.cy); m_ctrlPreferences.m_bParentCapture = true; if(bValidFont) m_ctrlPreferences.m_cfFont.CreateFontIndirect(&lfStaticFont); } p = GetDlgItem(IDC_TRAY_EXIT); if(p) { p->GetWindowRect(r); ScreenToClient(r); m_ctrlExit.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, r, this, IDC_EXIT); m_ctrlExit.m_nBtnID = IDC_EXIT; //p->GetWindowText(m_ctrlExit.m_strText); m_ctrlExit.m_strText = GetResString(IDS_EXIT); m_ctrlExit.m_strText.Remove(_T('&')); m_ctrlExit.m_bUseIcon = true; m_ctrlExit.m_sIcon.cx = 16; m_ctrlExit.m_sIcon.cy = 16; m_ctrlExit.m_hIcon = theApp.LoadIcon(_T("EXIT"), m_ctrlExit.m_sIcon.cx, m_ctrlExit.m_sIcon.cy); m_ctrlExit.m_bParentCapture = true; if(bValidFont) m_ctrlExit.m_cfFont.CreateFontIndirect(&lfStaticFont); } if((p = GetDlgItem(IDC_DOWNLBL)) != NULL) p->SetWindowText(GetResString(IDS_PW_CON_DOWNLBL)); if((p = GetDlgItem(IDC_UPLBL)) != NULL) p->SetWindowText(GetResString(IDS_PW_CON_UPLBL)); if((p = GetDlgItem(IDC_DOWNKB)) != NULL) p->SetWindowText(GetResString(IDS_KBYTESPERSEC)); if((p = GetDlgItem(IDC_UPKB)) != NULL) p->SetWindowText(GetResString(IDS_KBYTESPERSEC)); m_ctrlDownSpeedSld.SetRange(0,m_iMaxDown); m_ctrlDownSpeedSld.SetPos(m_nDownSpeedTxt); m_ctrlUpSpeedSld.SetRange(0,m_iMaxUp); m_ctrlUpSpeedSld.SetPos(m_nUpSpeedTxt); m_DownSpeedInput.EnableWindow(m_nDownSpeedTxt >0); m_UpSpeedInput.EnableWindow(m_nUpSpeedTxt >0); CFont Font; Font.CreateFont(-16,0,900,0,700,0,0,0,0,3,2,1,34,_T("Tahoma")); UINT winver = thePrefs.GetWindowsVersion(); if (winver == _WINVER_95_ || winver == _WINVER_NT4_ || g_bLowColorDesktop) { m_ctrlSidebar.SetColors(GetSysColor(COLOR_CAPTIONTEXT), GetSysColor(COLOR_ACTIVECAPTION), GetSysColor(COLOR_ACTIVECAPTION)); } else { m_ctrlSidebar.SetColors(GetSysColor(COLOR_CAPTIONTEXT), GetSysColor(COLOR_ACTIVECAPTION), GetSysColor(COLOR_GRADIENTACTIVECAPTION)); } m_ctrlSidebar.SetHorizontal(false); m_ctrlSidebar.SetFont(&Font); m_ctrlSidebar.SetWindowText(_T("eMule ") + theApp.m_strCurVersionLong); CRect rDesktop; CWnd *pDesktopWnd = GetDesktopWindow(); pDesktopWnd->GetClientRect(rDesktop); CPoint pt = m_ptInitialPosition; pDesktopWnd->ScreenToClient(&pt); int xpos, ypos; GetWindowRect(r); if(m_ptInitialPosition.x + r.Width() < rDesktop.right) xpos = pt.x; else xpos = pt.x - r.Width(); if(m_ptInitialPosition.y - r.Height() < rDesktop.top) ypos = pt.y; else ypos = pt.y - r.Height(); MoveWindow(xpos, ypos, r.Width(), r.Height()); SetCapture(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }