| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1605 人关注过本帖
标题:关于控件“容器”求助
只看楼主 加入收藏
dragonfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:1024
专家分:0
注 册:2006-3-20
收藏
 问题点数:0 回复次数:3 
关于控件“容器”求助
图片附件: 游客没有浏览图片的权限,请 登录注册


控件一个一个地移动真麻烦,如果把他们放到一个“容器”里,然后移动“容器”,所有的控件不就都动了吗?

VC中的 Group Box 控件把一些诸如Button,Edit Boxt等控件框起来以表示他们是“一伙”的,而VB中的Frame控件和他相似,可VB中的Frame控件还有一个功能就是,Frame移动时,他上面的控件也跟着移动,可是VC中的Group Box 就不行了,不知VC中还有没有其他控件,可以实现这种功能?
搜索更多相关主题的帖子: 容器 控件 
2006-03-22 09:29
dragonfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:1024
专家分:0
注 册:2006-3-20
收藏
得分:0 

能否自己顶一下呢?
如果一个一个移动,代码大致如下:
//曲线选择区
pWnd = GetDlgItem(IDC_IconArea);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
WinRight -= rect.Width();
pWnd->MoveWindow(WinRight,rect.top,rect.Width(),WinBottom-WinTop+7);

//参数显示区
pWnd = GetDlgItem(IDC_STATIC_Par);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
// WinRight-=5;
WinBottom-=rect.Height();
TmpWidth =WinRight-10-WinLeft;
TmpHeight =rect.Height();
pWnd->MoveWindow(WinLeft,WinBottom,TmpWidth,TmpHeight);

//Sn
pWnd = GetDlgItem(IDC_STATIC_SN);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Sn);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//Kn
pWnd = GetDlgItem(IDC_STATIC_KN);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Kn);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_KNu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//Bn
pWnd = GetDlgItem(IDC_STATIC_BN);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+2*TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Bn);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+2*TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_BNu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+2*TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//Wn
pWnd = GetDlgItem(IDC_STATIC_WN);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+3*TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Wn);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+3*TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_WNu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+3*TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//Head
pWnd = GetDlgItem(IDC_STATIC_HEAD);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+4*TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Head);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+4*TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_HEADu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+4*TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//End
pWnd = GetDlgItem(IDC_STATIC_END);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+5*TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_End);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+5*TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_ENDu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+5*TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//Unit
pWnd = GetDlgItem(IDC_STATIC_UNIT);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+6*TmpWidth/7,WinBottom+20,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_Unit);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+6*TmpWidth/7,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

pWnd = GetDlgItem(IDC_STATIC_UNITu);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+10+6*TmpWidth/7+60,WinBottom+5+TmpHeight/2,rect.Width(),rect.Height());

//HSet
pWnd = GetDlgItem(IDC_HSet);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
WinBottom -= 10; //改变WinBottom
pWnd->MoveWindow(WinLeft,WinBottom-rect.Height(),rect.Width(),rect.Height());

//HScalEdit
pWnd = GetDlgItem(IDC_HScalEdit);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+20,WinBottom-3*rect.Height()/2,rect.Width(),rect.Height());

//HScalCtrl
pWnd = GetDlgItem(IDC_HScalCtrl);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+40,WinBottom-3*rect.Height()/2,rect.Width(),rect.Height());

//VSet
pWnd = GetDlgItem(IDC_VSet);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//VScalEdit
pWnd = GetDlgItem(IDC_VScalEdit);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+20+TmpWidth/9,WinBottom-3*rect.Height()/2,rect.Width(),rect.Height());

//VScalCtrl
pWnd = GetDlgItem(IDC_VScalCtrl);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+40+TmpWidth/9,WinBottom-3*rect.Height()/2,rect.Width(),rect.Height());

//Capture
pWnd = GetDlgItem(IDC_Capture);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+2*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//CtrlCCD
pWnd = GetDlgItem(IDC_CtrlCCD);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+3*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//LoadData
pWnd = GetDlgItem(IDC_LoadData);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+4*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//SaveData
pWnd = GetDlgItem(IDC_SaveData);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+5*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//PutBitmap
pWnd = GetDlgItem(IDC_PutBitmap);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+6*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//SUB_BJ
pWnd = GetDlgItem(IDC_SUB_BJ);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+7*TmpWidth/9,WinBottom-2*rect.Height()-8,rect.Width(),rect.Height());

//Get_BJ
pWnd = GetDlgItem(IDC_GET_BJ);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+7*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

//IDOK
pWnd = GetDlgItem(IDOK);
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(WinLeft+8*TmpWidth/9,WinBottom-rect.Height(),rect.Width(),rect.Height());

....还没完,正在编写中!

但是如果能找到我说道那个“容器”,那么十多行代码就解决问题了

墨镜墨镜告诉我,高手到底在哪里?


2006-03-22 13:06
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
十分不幸,在下没用过VC2005,至少到VC2003为止,没有办法作这事。连MoveWindow()这函数也不是对所有Control都有用的。不过你的程序完全可以写的更简单一些,最简单的就是作个数组:

int intarResourceIdList[] = {
IDC_IconArea,
IDC_Static_Par,
....
};
CWnd *pWnd;

for (int intControlCount = 0; intControlCount = sizeof(intarResourceIdList)/sizeof(int); intControlCount++)
{
if (!(pWnd = GetDlgItem(intarResourceIdList[intControlCount])))
continue;
pWnd->GetWindowRect(rect);
ScreenToClient(rect);
pWnd->MoveWindow(.......); //这里算准点就是了。
}


http://myajax95./
2006-03-22 14:31
dragonfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:1024
专家分:0
注 册:2006-3-20
收藏
得分:0 

方法不错!多谢了!我还是想着控件“容器”


2006-03-23 08:55
快速回复:关于控件“容器”求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051356 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved