我在编程序的时候,属性页上显示3个按钮,确定,取消,应用。
我想把"应用"和"取消"隐藏,然后把"确定"按钮移动到边上,大概就是"应用"按钮的位置,我用的是以下方法。
CWnd pWnd = GetDlgItem( ID_APPLY_NOW );
RECT rect;
pWnd->GetClientRect(&rect); //得到位置
pWnd->ShowWindow( FALSE ); //隐藏
pWnd = GetDlgItem( IDOK );
pWnd->SetWindowText("关闭"); //改文本
pWnd->MoveWindow(&rect); //设定位置
pWnd->GetDlgItem(IDCANCEL);
pWnd->ShowWindow(FALSE); //隐藏
可是这样程序运行以后那个按钮就显示在属性页的最左上角了,不是我要的原来"应用"按钮的位置。
我想把"应用"和"取消"隐藏,然后把"确定"按钮移动到边上,大概就是"应用"按钮的位置,我用的是以下方法。
CWnd pWnd = GetDlgItem( ID_APPLY_NOW );
RECT rect;
pWnd->GetClientRect(&rect); //得到位置
pWnd->ShowWindow( FALSE ); //隐藏
pWnd = GetDlgItem( IDOK );
pWnd->SetWindowText("关闭"); //改文本
pWnd->MoveWindow(&rect); //设定位置
pWnd->GetDlgItem(IDCANCEL);
pWnd->ShowWindow(FALSE); //隐藏
可是这样程序运行以后那个按钮就显示在属性页的最左上角了,不是我要的原来"应用"按钮的位置。
解决方案 »
- MFC 自动化 程序的好处?
- 50分 请问为什么我在属性页上关联CComboBox变量后 程序出错呢,请高手帮忙
- 请问怎样用ATL编写一个控件?
- 告各位游侠书:wince入门战士啼血拜求C#开发视频播放控件秘籍,已图升级
- 关于子对话框的问题,CDialog:Create的对话框怎么样初始化
- 还在学习和使用VC的同志们,你们危险啊!!!!!
- 菜鸟级问题 ??
- 上海的朋友,Give me help!100相送,求工作!
- 在VC中,如何将我的应用程序关联几个不同类型的文件。
- 如何实现photoshop 色相调节功能
- 菜鸟问题:如果获取按钮的“是否有效的属性”
- 关于 FormView 中的 RadioButton 的问题
把上面的代码加到 Oninitdialog 里面
要在CPropertySheet::Oninitdialog后面处理
这时各个按钮才在最后的位置
{
BOOL bResult = CPropertySheet::OnInitDialog();
int ids [] = {IDOK, IDCANCEL};//, ID_APPLY_NOW, IDHELP };
// Hide Apply and Help buttons
CWnd *pWnd = GetDlgItem (ID_APPLY_NOW);
pWnd->ShowWindow (FALSE);
pWnd = GetDlgItem (IDHELP);
pWnd->ShowWindow (FALSE);
CRect rectBtn;
int nSpacing = 6; // space between two buttons... for( int i =0; i < sizeof(ids)/sizeof(int); i++)
{
GetDlgItem (ids [i])->GetWindowRect (rectBtn);
ScreenToClient (&rectBtn);
int btnWidth = rectBtn.Width();
rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2;
rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2; GetDlgItem (ids [i])->MoveWindow(rectBtn);
}
return bResult;
}
//OK and CANCEL Button move right
CRect rectBtn;
int nSpacing = 6; //Button distance
for( int i =0; i < sizeof(ids)/sizeof(int); i++)
{
GetDlgItem (ids [i])->GetWindowRect (rectBtn);
ScreenToClient (&rectBtn);
int btnWidth = rectBtn.Width();
rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2;
rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2;
GetDlgItem (ids [i])->MoveWindow(rectBtn);
GetWindowRect()这个函数将CWnd对象的边界矩形的大小拷贝到lpRect所指向的结构中。大小是用相对于显示器屏幕左上角的屏幕坐标给出的,其中包括了标题条,边框和滚动条的大小,如果有的话。两个范围是不一样的
RECT rect;
pWnd->GetWindowRect(&rect); //得到位置
pWnd->ShowWindow( FALSE ); //隐藏
pWnd = GetDlgItem( IDOK );
pWnd->SetWindowText("关闭"); //改文本
pWnd->MoveWindow(&rect); //设定位置
pWnd->GetDlgItem(IDCANCEL);
pWnd->ShowWindow(FALSE); //隐藏