下面是一段徐景周译的(原作:Mustafa Demirhan)关于propertysheet的文章中的一段代码
首先,要获取按钮的句柄,然后就可以象对待窗体一样处理它们了. 下面代码先隐藏掉Apply和Help铵钮,再把OK和Cancel按移动到右侧。 BOOL CMyPropSheet::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;
}编译可以通过,但是在执行时总是报Debug Assertion Failer错误,调试进去之后发现是ASSERT(hWnd != NULL)错误,小弟不知道如何解决。在线等谢谢
首先,要获取按钮的句柄,然后就可以象对待窗体一样处理它们了. 下面代码先隐藏掉Apply和Help铵钮,再把OK和Cancel按移动到右侧。 BOOL CMyPropSheet::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;
}编译可以通过,但是在执行时总是报Debug Assertion Failer错误,调试进去之后发现是ASSERT(hWnd != NULL)错误,小弟不知道如何解决。在线等谢谢
解决方案 »
- CAN接口卡 接收数据线程问题?
- 客户端向服务器端发送一个数据(如1)怎么在服务器端edit控件上显示
- 照《MFC深入详解》做例题,出了Debug assertion Failed错误,求助
- 写个猜数字小游戏,结果总有问题
- 急!请问如何截获并修改windows中文件的操作?
- DSHOW的IMediaSample接口如何使用
- 请教:为什么找不到已经注册好了的控件呢?
- VC2005环境下使用ADO的问题
- 问一个VC里面结构体里面的变量的内存对齐问题
- 如何让VC6找到Windows XP2 系统DLL符号文件.符号文件从哪里下载
- 用adodata控件怎么修改conncectionstring的内容?
- 急求:
设置CPropertySheet的m_psh.dwFlags以及CPropertyPage的m_psp.dwFlags的风格
sheet
|= PSH_NOAPPLYNOW // no "Apply" button
&= ~PSH_HASHELP // no "Help" buttonpage
&= ~ PSP_HASHELP // no "Help" button
我是这样调用的
CPropertySheetTest m_mainfram("test");
//class CPropertySheetTest : public CPropertySheet
m_mainfram.OninitialDlg();而自己的OninitialDlg()就是照抄的那个例子程序
BOOL CPropertySheetTest::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;
}
BOOL CPropertySheet::OnInitDialog()
{
// change tab style if scrolling tabs desired (stacked tabs are default)
if (!m_bStacked)
{
HWND hWndTab = (HWND)::GetDlgItem(m_hWnd, AFX_IDC_TAB_CONTROL);
if (hWndTab != NULL)
CWnd::ModifyStyle(hWndTab, TCS_MULTILINE, TCS_SINGLELINE, 0);
} if (!IsWizard())
{
// resize the tab control so the layout is less restrictive
HWND hWnd = (HWND)::GetDlgItem(m_hWnd, AFX_IDC_TAB_CONTROL);
ASSERT(hWnd != NULL);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~这里会报错
CRect rectOld;
::GetWindowRect(hWnd, &rectOld);
ScreenToClient(rectOld);
CRect rectNew(0, 0, 0, 32);
::MapDialogRect(m_hWnd, &rectNew);
if (rectNew.bottom < rectOld.bottom)
{
// move tab control
int cyDiff = rectOld.Height() - rectNew.bottom;
::SetWindowPos(hWnd, NULL, 0, 0, rectOld.Width(), rectNew.bottom,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); // move buttons by similar amount
for (int i = 0; i < _countof(_afxPropSheetButtons); i++)
{
hWnd = ::GetDlgItem(m_hWnd, _afxPropSheetButtons[i]);
if (hWnd != NULL)
{
::GetWindowRect(hWnd, &rectOld);
ScreenToClient(&rectOld);
::SetWindowPos(hWnd, NULL,
rectOld.left, rectOld.top - cyDiff,
0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
} // resize property sheet itself similarly
GetWindowRect(&rectOld);
SetWindowPos(NULL, 0, 0, rectOld.Width(), rectOld.Height() - cyDiff,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
} BOOL bResult = (BOOL)Default(); if (m_bModeless && !IsWizard())
{
// layout property sheet so button area is not accounted for
CRect rectWnd;
GetWindowRect(rectWnd);
CRect rectButton;
HWND hWnd = ::GetDlgItem(m_hWnd, IDOK);
ASSERT(hWnd != NULL);
::GetWindowRect(hWnd, rectButton);
SetWindowPos(NULL, 0, 0,
rectWnd.Width(), rectButton.top - rectWnd.top,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); // remove standard buttons for modeless dialogs
for (int i = 0; i < _countof(_afxPropSheetButtons); i++)
{
HWND hWnd = ::GetDlgItem(m_hWnd, _afxPropSheetButtons[i]);
if (hWnd != NULL)
{
::ShowWindow(hWnd, SW_HIDE);
::EnableWindow(hWnd, FALSE);
}
}
} // center the property sheet relative to the parent window
if (!(GetStyle() & WS_CHILD))
CenterWindow(); return bResult;
}