我是MFC的新手。我需要创建一个没有停靠选项的浮动工具栏(CToolBar),并保存和恢复它的最后一个位置。
工具栏也应该一直处于活动状态,但它不是。当我从大型机打开一个新的子窗口(例如对话框)时,浮动工具栏变得不活动(我不能单击它的按钮,也不能拖动它等)。
在过去,我使用重叠样式的CDiaolog,它是浮动的,并且总是在我需要的时候激活。我的浮动工具栏可以做同样的事情吗?谢谢
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
toolbarIconSize.cx = toolbarIconSize.cy = TOOLBAR_MAIN_ICON_SIZE;
if ( !m_wndMyFloatingToolbar.Create(this,m_wndMyFloatingToolbar.GetBarStyle() |WS_EX_PALETTEWINDOW | WS_EX_TOPMOST |CBRS_FLOATING | WS_VISIBLE) ||
!m_wndMyFloatingToolbar.LoadToolBar(IDR_GENERAL_TOOLBAR, toolbarIconSize))
{
TRACE0("Failed to create My Floating Toolbar\n");
return -1; // fail to create
}
m_wndMyFloatingToolbar.EnableDocking(0);
EnableDocking(0);
if (!CreateCtrlBar())
{
TRACE0("Failed to create ctrl toolbar\n");
return -1; // fail to create
}
// ...
//...
return 0;
}
void CMainFrame::OnViewToolBar()
{
// ...
//...
CPoint Pos = MyFloatingToolbarGetLastPosition(); \\Get last pos
FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
MyFloatingToolbarSetIsVisible();
FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
}
void CMainFrame::MyFloatingToolbarSetIsVisible()
{
WINDOWPLACEMENT wp;
m_wndMyFloatingToolbar.GetParent()->GetParent()->GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.GetParent()->GetParent()->SetWindowPlacement(&wp);
m_wndMyFloatingToolbar.GetParent()->GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.GetParent()->SetWindowPlacement(&wp);
m_wndMyFloatingToolbar.GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.SetWindowPlacement(&wp);
}
void CWJToolBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CToolBar::OnWindowPosChanging(lpwndpos);
if ( GetBarStyle() & CBRS_FLOATING )
{
if((lpwndpos->flags & SWP_HIDEWINDOW) && ((this->GetParentFrame())->m_hWnd !=(this->GetTopLevelFrame())->m_hWnd))
{
CMainFrame* mf = (CMainFrame*)(AfxGetApp()->GetMainWnd());
mf->MyFloatingToolbarSavePosition();
}
}
}发布于 2015-01-21 20:22:56
- hiding your toolbar
- saving its position data
- changing your parent windows position and
- reloading your saved coordinates.
这样,保存的数据就会变成不正确的值。
我建议你捕捉你想要添加你的工具栏实时的位置。这将使您的工具栏应用程序更加通用。所以,
获取父窗口的工具条距离
当然,还有其他方法可以做到这一点,但我认为,要实现您可能正在寻找的目标,这种方法更为简单。
发布于 2018-02-09 18:53:49
使用CMFCToolBar (而不是CToolBar),然后你只需要两个命令就可以做到这一点。
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
:
m_wndToolBar.SetPermament(TRUE); // it removes CloseButton (=always active)
CRect rect;
GetClientRect(&rect);
ClientToScreen(rect);
rect.OffsetRect(100, 20);
m_wndToolBar.FloatPane(rect); // Float and move it to your wished coordinates
:
}https://stackoverflow.com/questions/28066396
复制相似问题