📄 customizedialog.cpp
字号:
ON_WM_MEASUREITEM()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
ON_MESSAGE( WM_INITDIALOG, OnInitDialog )
END_MESSAGE_MAP()
LRESULT CCustomizeDialog::OnInitDialog( WPARAM /*wParam*/, LPARAM /*lParam*/ )
{
CRect rcClient;
GetClientRect( rcClient );
CRect rcWindow;
GetWindowRect( rcWindow );
// Create Options dialog as a child window of Customize Toolbar dialog
VERIFY( m_dlgOptions.Create( COptionsDialog::IDD, this ) );
CRect rcDlg;
m_dlgOptions.GetWindowRect( rcDlg );
// Place Options dialog at the bottom
VERIFY( m_dlgOptions.SetWindowPos( 0, 0, rcClient.Height(), rcClient.Width(), rcDlg.Height(),
SWP_NOZORDER | SWP_SHOWWINDOW ) );
// Increase height of Customize Toolbar dialog accordingly
rcWindow.bottom += rcDlg.Height();
VERIFY( SetWindowPos( 0, 0, 0, rcWindow.Width(), rcWindow.Height(),
SWP_NOZORDER | SWP_NOMOVE ) );
return Default();
}
void CCustomizeDialog::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
{
if ( lpDrawItemStruct->CtlType == ODT_LISTBOX )
{
if ( ( nIDCtl == IDC_LB_AVAILABLE ) || ( nIDCtl == IDC_LB_CURRENT ) )
{
CDC* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
int nSavedDC = pDC->SaveDC();
ASSERT( nSavedDC );
// Get all needed info about the item being drawn
CRect rcItem( &lpDrawItemStruct->rcItem );
int nItem = ( SHORT )HIWORD( lpDrawItemStruct->itemData );
int nImage = ( SHORT )LOWORD( lpDrawItemStruct->itemData );
int nIndex = ( int )lpDrawItemStruct->itemID;
bool bSelected = ( lpDrawItemStruct->itemState & ODS_SELECTED ) != 0;
bool bFocused = ( lpDrawItemStruct->itemState & ODS_FOCUS ) != 0;
bool bSeparator = ( ( nItem < 0 ) || ( nItem > m_pToolBar->m_aButtons.GetUpperBound() ) );
// Calculate rectangles for image, text and focus frame
CSize szButton = GetButtonSize();
CRect rcImage( rcItem );
rcImage.right = rcImage.left + szButton.cx;
CRect rcText( rcItem );
rcText.left += szButton.cx + 5;
rcText.right -= 2;
CRect rcLabel( rcItem );
rcLabel.left += szButton.cx + 1;
// Cache system colors
COLORREF clrText = ::GetSysColor( bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT );
COLORREF clrBack = ::GetSysColor( bSelected ? COLOR_HIGHLIGHT : COLOR_BTNFACE );
COLORREF clrGrayText = ::GetSysColor( COLOR_GRAYTEXT );
COLORREF clrBtnFace = ::GetSysColor( COLOR_BTNFACE );
COLORREF clr3dShadow = ::GetSysColor( COLOR_3DSHADOW );
COLORREF clr3dHilite = ::GetSysColor( COLOR_3DHILIGHT );
pDC->FillSolidRect( rcImage, clrBtnFace );
pDC->FillSolidRect( rcLabel, clrBack );
// Draw focus rect, if needed
if ( bFocused )
{
CBrush brush( RGB(
255 - GetRValue( clrBack ),
255 - GetGValue( clrBack ),
255 - GetBValue( clrBack ) ) );
rcLabel.DeflateRect( 2, 2 );
pDC->FrameRect( rcLabel, &brush );
VERIFY( brush.DeleteObject() );
}
// Get item text to be drawn
CString strText;
if ( !bSeparator )
{
UINT nID = m_pToolBar->m_aButtons[ nItem ].tbinfo.idCommand;
m_pToolBar->GetButtonText( nID, strText );
}
else
{
VERIFY( strText.LoadString( IDS_SEPARATOR ) );
}
// Prepare to draw item text
int nFormat = DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS;
pDC->SetBkMode( TRANSPARENT );
pDC->SetTextColor( clrText );
if ( !bSeparator )
{
// Draw item image, if any
if ( nImage >= 0 )
{
if ( bSelected )
{
pDC->Draw3dRect( rcImage, clr3dHilite, clr3dShadow );
}
CToolBarCtrl& tbCtrl = m_pToolBar->GetToolBarCtrl();
CImageList* pImageList = tbCtrl.GetHotImageList();
if ( !bSelected || !pImageList )
{
pImageList = tbCtrl.GetImageList();
}
rcImage.DeflateRect( cxPadding, cyPadding );
VERIFY( pImageList->Draw( pDC, nImage, rcImage.TopLeft(),
ILD_NORMAL | ILD_TRANSPARENT ) );
}
if ( m_pToolBar->m_aButtons[ nItem ].tbinfo.fsStyle & TBSTYLE_DROPDOWN )
{
// This button is drop-down button. To indicate this simple fact
// we draw an arrow on right like one that submenu items have.
CRect rcArrow( rcText );
rcArrow.left = rcArrow.right - ::GetSystemMetrics( SM_CXMENUCHECK );
rcText.right -= rcArrow.Width();
CBrush brush( clrText );
CBrush* pOldBrush = pDC->SelectObject( &brush );
CDC dc;
VERIFY( dc.CreateCompatibleDC( pDC ) );
CBitmap bmpArrow;
VERIFY( bmpArrow.CreateCompatibleBitmap( pDC, rcArrow.Width(), rcArrow.Height() ) );
CBitmap* pOldBitmap = dc.SelectObject( &bmpArrow );
CRect rc( 0, 0, rcArrow.Width(), rcArrow.Height() );
VERIFY( dc.DrawFrameControl( rc, DFC_MENU, DFCS_MENUARROW ) );
VERIFY( pDC->BitBlt( rcArrow.left, rcArrow.top, rcArrow.Width(), rcArrow.Height(),
&dc, 0, 0, ROP_PSDPxax ) );
dc.SelectObject( pOldBitmap );
VERIFY( bmpArrow.DeleteObject() );
pDC->SelectObject( pOldBrush );
VERIFY( brush.DeleteObject() );
}
}
else
{
if ( ( nIDCtl == IDC_LB_CURRENT ) &&
( nIndex == SendDlgItemMessage( nIDCtl, LB_GETCOUNT ) - 1 ) )
{
// The last item in the list of current buttons is a separator
// which cannot be removed (guess what is the purpose of it?).
// To indicate this fact we draw it as disabled item.
if ( bSelected )
{
pDC->SetTextColor( clrGrayText );
}
else
{
CRect rcTemp( rcText );
rcTemp.OffsetRect( 1, 1 );
pDC->SetTextColor( clr3dHilite );
pDC->DrawText( strText, rcTemp, nFormat );
pDC->SetTextColor( clr3dShadow );
}
}
else
{
// Draw the separator bar in the middle
rcImage.DeflateRect( cxPadding, cyPadding );
int y = ( rcImage.top + rcImage.bottom ) / 2;
rcImage.top = y - 1;
rcImage.bottom = y + 1;
pDC->Draw3dRect( rcImage, clr3dShadow, clr3dHilite );
}
}
pDC->DrawText( strText, rcText, nFormat );
VERIFY( pDC->RestoreDC( nSavedDC ) );
return;
}
}
CWnd::OnDrawItem( nIDCtl, lpDrawItemStruct );
}
void CCustomizeDialog::OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
if ( lpMeasureItemStruct->CtlType == ODT_LISTBOX )
{
if ( ( nIDCtl == IDC_LB_AVAILABLE ) ||
( nIDCtl == IDC_LB_CURRENT ) )
{
lpMeasureItemStruct->itemHeight = GetButtonSize().cy;
return;
}
}
CWnd::OnMeasureItem( nIDCtl, lpMeasureItemStruct );
}
HBRUSH CCustomizeDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )
{
HBRUSH hbr = CWnd::OnCtlColor( pDC, pWnd, nCtlColor );
if ( nCtlColor == CTLCOLOR_LISTBOX )
{
UINT nIDCtl = ( UINT )pWnd->GetDlgCtrlID();
if ( ( nIDCtl == IDC_LB_AVAILABLE ) ||
( nIDCtl == IDC_LB_CURRENT ) )
{
hbr = ::GetSysColorBrush( COLOR_BTNFACE );
}
}
return hbr;
}
void COptionsDialog::SetLanguage()
{
CString wintextsrc;
CString wintextnew;
if(this)
{
this->GetWindowText(wintextsrc);
GetText(wintextsrc,wintextnew,global_item_text);
this->SetWindowText(wintextnew);
}
CWnd *wnd=this->GetDlgItem(IDC_STATIC1_CUS);
if(wnd)
{
wnd->GetWindowText(wintextsrc);
GetText(wintextsrc,wintextnew,global_item_text);
wnd->SetWindowText(wintextnew);
}
wnd=GetDlgItem(IDC_STATIC2_CUS);
if(wnd)
{
wnd->GetWindowText(wintextsrc);
GetText(wintextsrc,wintextnew,global_item_text);
wnd->SetWindowText(wintextnew);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -