CRect x,y;
GetWindowRect(y);   
TBBUTTON button;
button.idCommand=nID;
button.fsState=TBSTATE_ENABLED;
button.fsStyle=TBSTYLE_CHECK;
    GetToolBarCtrl().InsertButton(index,&button);
    GetToolBarCtrl().GetItemRect(CommandToIndex(nID),&x);
CString cs,cs2;
GetToolBarCtrl().ClientToScreen(&x);
    
 cs.Format("%d",x.left);
     cs2.Format("%d",y.right);
 AfxMessageBox(cs+" "+cs2);
if(x.left>(1284*2))SetButtonStyle(CommandToIndex(nID),GetButtonStyle(CommandToIndex(nID))|TBBS_WRAPPED);
GetWindowRect(y)是想获得屏幕右坐标或者是工具栏右坐标。
1284是我给定的坐标值,而我通过对话框看到(按钮)GetItemRect获得后,X.RIGHT高达3000多象素。很菜的问题,谁能帮我一下啊。谢谢

解决方案 »

  1.   

    http://topic.csdn.net/t/20050312/00/3844717.html
      

  2.   

    这两天我刚好在写这方面的,下面是个对话框上的编辑框随对话框最大化的WM_SIZE处理函数,把它先在WM_SHOWWINDOW处理函数里或是别的什么合适的函数里执行一次就可以预先初始化位置了。如过控件多不防在纸上画一草图,好好计算一下,我想没有本质的不同。   
      void   DI::OnSize(UINT   nType,   int   cx,   int   cy)   
      {   
      CDialog::OnSize(nType,   cx,   cy);   
      CRect   rect;   
      CEdit   *   wnd;   
      GetClientRect(rect);                                     //获取客户区大小   
      wnd=(CEdit   *)GetDlgItem(IDC_EDIT1);     //获取其上控件的指针,是个编辑框   
      if(wnd)wnd->MoveWindow(rect);   
      }   
      可能还会用到这些函数获取别的控件的位置   
      GetWindowRect(&rect);               //屏幕绝对坐标   
      GetClientRect(rect);
      

  3.   

    我的问题解决了,是设备坐标和逻辑坐标的问题CRect x,y;
    GetWindowRect(y); 
    *********************
    CClientDC dc(this);
    **********************  
    TBBUTTON button;
    button.idCommand=nID;
    button.fsState=TBSTATE_ENABLED;
    button.fsStyle=TBSTYLE_CHECK;
    GetToolBarCtrl().InsertButton(index,&button);
    GetToolBarCtrl().GetItemRect(CommandToIndex(nID),&x);GetToolBarCtrl().ClientToScreen(&x);
     *****************   
    dc.DPtoLP(&x); 
    **********************
    if(x.left>1284)SetButtonStyle(CommandToIndex(nID),GetButtonStyle(CommandToIndex(nID))|TBBS_WRAPPED);