我想实现这个功能:
对于一个可移动的工具栏,将工具栏移动到某个位置,关闭程序,下次打开程序,工具栏自动位于关闭程序时的位置。
我现在在关闭前记录下了工具栏所在的位置,但我用MOVEWINDOW,工具栏仍然停靠在默认的位置(在窗口底部)
这个要怎么做??

解决方案 »

  1.   

    你确定得到在上次关闭时的正确位置了吗?只要得到了正确位置,用MOVEWINDOW应该行的
      

  2.   

    1. Using GetClientRect() to retrieve the coordinates of the docking toolbar's client area, then save them.
    2. Because MoveWindow() uses the coordinates of screen, you should convert coordinate from client to screen area by calling ClientToScreen() before calling MoveWindow().
      

  3.   

    需要同时控制ToolBar的状态和位置CControlBar::SetBarStyle()可以控制ToolBar是否停靠和停靠位置。
    MoveWindow只有在Float的时候才有用。
      

  4.   

    我把代码贴下,大家帮我看看哪儿错了,谢谢//得到位置rect,保存
    m_wndViewBar.GetWindowRect(&rect);//用GetClientRect得到的rect的left和top都是0,应该不对//创建TOOLBAR,默认放在底部
    dwStyle = WS_CHILD | WS_VISIBLE  | CBRS_FLYBY | CBRS_TOOLTIPS| CBRS_SIZE_FIXED
    | CBRS_BOTTOM | CBRS_GRIPPER;
    if (!m_wndViewBar.CreateEx(pParentWnd, TBSTYLE_FLAT, dwStyle, CRect(0,0,0,0), IDW_VIEW_BAR))
        return FALSE;
    f(!LoadToolBar(IDR_VIEW))
        return FALSE;     
    m_wndViewBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
    DockControlBar(&m_wndViewBar);//得到rect,移动TOOLBAR
    m_wndViewBar.MoveWindow(&rect);
      

  5.   

    1。关闭主程序时,用GetWindowRect分别得到主程序和toolbar的rect,然后相减得到toolbar相对于主程序的偏移量,保存之。2。主程序初始化时,用GetWindowRect得到主程序的rect,把保存的偏移量和该rect相加得到toolbar的rect,MoveWindow之。
      

  6.   

    自己找到了方法,用FloatControlBar