📄 sizablerebar.cpp
字号:
ON_WM_MEASUREITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////
// CSizableReBar message handlers
int CSizableReBar::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if ( CControlBar::OnCreate( lpCreateStruct ) == -1 )
{
return -1;
}
if ( !m_wndReBar.Create( this , RBS_BANDBORDERS | RBS_VARHEIGHT | RBS_DBLCLKTOGGLE,
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
m_dwStyle | CBRS_BORDER_ANY | CBRS_BORDER_3D
) )
{
return -1;
}
m_wndReBar.SetOwner( GetOwner() );
return 0;
}
void CSizableReBar::OnNcLButtonDown( UINT nHitTest, CPoint point )
{
if ( !m_bTracking )
{
if ( ( nHitTest >= HTSIZEFIRST ) && ( nHitTest <= HTSIZELAST ) )
{
StartTracking( nHitTest, point );
}
}
}
void CSizableReBar::OnMouseMove( UINT nFlags, CPoint point )
{
if ( m_bTracking )
{
OnTrackUpdateSize( point );
}
CControlBar::OnMouseMove( nFlags, point );
}
void CSizableReBar::OnLButtonUp( UINT nFlags, CPoint point )
{
if ( m_bTracking )
{
StopTracking();
}
CControlBar::OnLButtonUp( nFlags, point );
}
void CSizableReBar::OnCaptureChanged( CWnd *pWnd )
{
if ( m_bTracking && ( pWnd != this ) )
{
StopTracking();
}
CControlBar::OnCaptureChanged( pWnd );
}
void CSizableReBar::OnNcCalcSize( BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp )
{
CControlBar::OnNcCalcSize( bCalcValidRects, lpncsp );
CRect rcWindow( lpncsp->rgrc[ 0 ] );
CRect rcClient( rcWindow );
CRect rcEdge;
if ( GetSizingEdgeRect( rcWindow, rcEdge, GetSizingEdgeHitCode() ) )
{
if ( rcClient.SubtractRect( rcWindow, rcEdge ) )
{
lpncsp->rgrc[ 0 ] = rcClient;
}
}
}
void CSizableReBar::OnNcPaint()
{
EraseNonClient();
CWindowDC dc( this );
}
UINT CSizableReBar::OnNcHitTest( CPoint point )
{
CRect rcWindow;
GetWindowRect( rcWindow );
CRect rcEdge;
UINT nHitTest = GetSizingEdgeHitCode();
if ( GetSizingEdgeRect( rcWindow, rcEdge, nHitTest ) && rcEdge.PtInRect( point ) )
{
return nHitTest;
}
return HTCLIENT;
}
void CSizableReBar::OnSize( UINT nType, int cx, int cy )
{
CControlBar::OnSize( nType, cx, cy );
CRect rcClient;
GetClientRect( rcClient );
m_wndReBar.MoveWindow( rcClient );
}
void CSizableReBar::OnContextMenu( CWnd* /*pWnd*/, CPoint point )
{
if ( !m_bCommonPart && !m_bCustomPart )
{
return;
}
CMenu menu;
VERIFY( menu.CreatePopupMenu() );
CReBarCtrl& rbCtrl = m_wndReBar.GetReBarCtrl();
int nBand;
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof( rbbi );
// Populate menu by adding titles of the bars that can be shown/hidden
if ( m_bCommonPart )
{
for ( int nIndex = 0; nIndex <= m_aBars.GetUpperBound(); nIndex++ )
{
if ( _tcslen( m_aBars[ nIndex ].szTitle ) > 0 )
{
nBand = rbCtrl.IDToIndex( m_aBars[ nIndex ].nID );
if ( nBand != -1 )
{
rbbi.fMask = RBBIM_STYLE | RBBIM_CHILD;
VERIFY( rbCtrl.GetBandInfo( nBand, &rbbi ) );
UINT nFlags = 0;
if ( m_aBars[ nIndex ].bAlwaysVisible )
{
nFlags |= MF_GRAYED;
}
if ( !( rbbi.fStyle & RBBS_HIDDEN ) )
{
nFlags |= MF_CHECKED;
}
int a=m_aBars[ nIndex ].nID;
CString strTitle=m_aBars[ nIndex ].szTitle ;
CString strTitleNew;
GetText(strTitle,strTitleNew,conmeu_item_text);
VERIFY( menu.AppendMenu( MF_BYCOMMAND | nFlags,
m_aBars[ nIndex ].nID, strTitleNew) );
}
}
}
}
// Populate menu by adding items specific to the bar that was clicked
HWND hwndBar = 0;
if ( m_bCustomPart )
{
RBHITTESTINFO rbhti;
rbhti.pt = point;
rbCtrl.ScreenToClient( &rbhti.pt );
nBand = rbCtrl.HitTest( &rbhti );
if ( nBand != -1 )
{
rbbi.fMask = RBBIM_CHILD;
VERIFY( rbCtrl.GetBandInfo( nBand, &rbbi ) );
hwndBar = rbbi.hwndChild;
UINT nBars = menu.GetMenuItemCount();
::SendMessage( hwndBar, WM_REBAR_CONTEXTMENU, ( WPARAM )&menu, 0 );
if ( 0 < nBars && nBars < menu.GetMenuItemCount() )
{
VERIFY( menu.InsertMenu( nBars, MF_BYPOSITION | MF_SEPARATOR ) );
}
}
}
// Track menu
CWinAppEx::GetInstance()->SetMenuIcons( &menu, true );
UINT nID = menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_NONOTIFY,
point.x, point.y,AfxGetApp()->m_pMainWnd);
nBand = rbCtrl.IDToIndex( nID );
if ( nBand != -1 ) // was it "Show/Hide Bar" command?
{
rbbi.fMask = RBBIM_STYLE;
VERIFY( rbCtrl.GetBandInfo( nBand, &rbbi ) );
VERIFY( rbCtrl.ShowBand( nBand, ( rbbi.fStyle & RBBS_HIDDEN ) != 0 ) );
}
else if ( hwndBar != 0 )
{
// It was bar-specific command, so forward it to the bar
::SendMessage( hwndBar, WM_COMMAND, MAKEWPARAM( nID, 0 ), 0 );
}
VERIFY( menu.DestroyMenu() );
delete menu;
}
/////////////////////////////////////////////////////////////////////////////
// Implementation
UINT CSizableReBar::GetSizingEdgeHitCode() const
{
if ( m_dwStyle & CBRS_ALIGN_LEFT )
{
return HTRIGHT;
}
if ( m_dwStyle & CBRS_ALIGN_TOP )
{
return HTBOTTOM;
}
if ( m_dwStyle & CBRS_ALIGN_RIGHT )
{
return HTLEFT;
}
if ( m_dwStyle & CBRS_ALIGN_BOTTOM )
{
return HTTOP;
}
return HTNOWHERE;
}
bool CSizableReBar::GetSizingEdgeRect( const CRect& rcBar, CRect& rcEdge, UINT nHitTest ) const
{
rcEdge = rcBar;
switch ( nHitTest )
{
case HTLEFT:
rcEdge.left = rcEdge.right - m_cxEdge;
break;
case HTBOTTOM:
rcEdge.top = rcEdge.bottom - m_cyEdge;
break;
case HTRIGHT:
rcEdge.right = rcEdge.left + m_cxEdge;
break;
case HTTOP:
rcEdge.bottom = rcEdge.top + m_cyEdge;
break;
default:
return false;
}
return true;
}
void CSizableReBar::StartTracking( UINT nHitTest, CPoint pt )
{
SetCapture();
// Make sure no updates are pending
VERIFY( RedrawWindow( 0, 0, RDW_ALLCHILDREN | RDW_UPDATENOW ) );
m_htEdge = nHitTest;
m_szOld = m_szCurrent - CSize( m_cxEdge, m_cyEdge );
m_ptOld = pt;
m_bTracking = true;
}
void CSizableReBar::StopTracking()
{
m_bTracking = false;
ReleaseCapture();
GetParentFrame()->DelayRecalcLayout();
}
void CSizableReBar::OnTrackUpdateSize( CPoint pt )
{
ClientToScreen( &pt );
CSize szDelta = pt - m_ptOld;
CSize sizeNew = m_szOld;
switch ( m_htEdge )
{
case HTLEFT:
sizeNew.cx -= szDelta.cx;
break;
case HTTOP:
sizeNew.cy -= szDelta.cy;
break;
case HTRIGHT:
sizeNew.cx += szDelta.cx;
break;
case HTBOTTOM:
sizeNew.cy += szDelta.cy;
break;
}
if ( sizeNew != m_szOld )
{
m_szOld = sizeNew;
m_ptOld = pt;
// Try to re-size the re-bar control
CRect rc( CPoint( 0, 0 ), sizeNew );
if ( m_wndReBar.GetReBarCtrl().SizeToRect( rc ) )
{
GetParentFrame()->DelayRecalcLayout();
}
}
}
void CSizableReBar::DrawGripper(CDC &dc)
{
/* COLORREF clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
COLORREF clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
CRect rcGrip;
GetWindowRect(&rcGrip);
ScreenToClient(&rcGrip);
rcGrip.OffsetRect(-rcGrip.left, -rcGrip.top);
if(m_dwStyle & CBRS_ORIENT_HORZ)
{
// gripper at left
rcGrip.DeflateRect(4, 4);
rcGrip.right = rcGrip.left + 3;
dc.Draw3dRect(rcGrip, clrBtnHilight, clrBtnShadow);
}
*/}
/*void CSizableReBar::DoPaint(CDC* pDC)
{
CRect rect;
GetClientRect(rect);
// clean background
COLORREF clr = ::GetSysColor(COLOR_BTNFACE);
pDC->FillSolidRect(rect, clr);
// draw the gripper
DrawGripper(*pDC);
// It is better to let the underlining control bar take the last shot
CControlBar::DoPaint(pDC);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -