我刚刚尝试在调试中运行CDialog
应用,但出现异常。它与我创建的myu工具栏有关。
我在OnInitDialog
中称此提及:
void CMeetingScheduleAssistantDlg::CreateToolbar()
{
DWORD dwCtrlStyle = TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CBRS_SIZE_DYNAMIC;
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE;
if (m_ToolBar.CreateEx(this, dwCtrlStyle,
dwStyle, CRect(1, 1, 1, 1), IDR_TOOLBAR))
{
dwStyle = CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC;
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() | dwStyle);
CMFCToolBarInfo info;
info.m_uiColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiHotResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeHotResID = IDB_PNG_MAIN_TOOLBAR;
m_ToolBar.LoadToolBarEx(IDR_TOOLBAR, info, FALSE);
CSize sizeToolBar = m_ToolBar.CalcFixedLayout(TRUE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy,
SWP_NOACTIVATE | SWP_NOZORDER);
// Move all controls down
CPoint ptOffset(0, sizeToolBar.cy);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
if (pwndChild->GetSafeHwnd() != m_ToolBar.GetSafeHwnd())
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
}
pwndChild = pwndChild->GetNextWindow();
}
// Resize the window
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.bottom += sizeToolBar.cy;
MoveWindow(rcWindow, FALSE);
}
}
此行例外:
LoadToolBarEx
当我跟踪代码时,我最终到达此ASSERT
:
// Load large images:
if (params.m_uiLargeHotResID != 0)
{
if (!m_LargeImages.Load(params.m_uiLargeHotResID, NULL, TRUE))
{
return FALSE;
}
ASSERT(m_Images.GetCount() == m_LargeImages.GetCount());
}
当我查看这些变量时:
m_Images
有10张图像。m_LargeImages
有5张图像。这是调用堆栈:
> Meeting Schedule Assistant.exe!CMFCToolBar::LoadBitmapEx(CMFCToolBarInfo & params, int bLocked) Line 781 C++
Meeting Schedule Assistant.exe!CMFCToolBar::LoadToolBarEx(unsigned int uiToolbarResID, CMFCToolBarInfo & params, int bLocked) Line 872 C++
Meeting Schedule Assistant.exe!CMeetingScheduleAssistantDlg::CreateToolbar() Line 2288 C++
Meeting Schedule Assistant.exe!CMeetingScheduleAssistantDlg::OnInitDialog() Line 246 C++
Meeting Schedule Assistant.exe!AfxDlgProc(HWND__ * hWnd, unsigned int message, unsigned __int64 __formal, __int64 __formal) Line 28 C++
[External Code]
Meeting Schedule Assistant.exe!CWnd::DefWindowProcW(unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 1100 C++
Meeting Schedule Assistant.exe!CWnd::Default() Line 299 C++
Meeting Schedule Assistant.exe!CDialog::HandleInitDialog(unsigned __int64 __formal, __int64 __formal) Line 721 C++
Meeting Schedule Assistant.exe!CWnd::OnWndMsg(unsigned int message, unsigned __int64 wParam, __int64 lParam, __int64 * pResult) Line 2441 C++
Meeting Schedule Assistant.exe!CWnd::WindowProc(unsigned int message, unsigned __int64 wParam, __int64 lParam) Line 2099 C++
Meeting Schedule Assistant.exe!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 265 C++
Meeting Schedule Assistant.exe!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 418 C++
[External Code]
Meeting Schedule Assistant.exe!IsolationAwareCreateDialogIndirectParamW(HINSTANCE__ * hInstance, const DLGTEMPLATE * lpTemplate, HWND__ * hWndParent, __int64(*)(HWND__ *, unsigned int, unsigned __int64, __int64) lpDialogFunc, __int64 dwInitParam) Line 569 C++
Meeting Schedule Assistant.exe!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst) Line 358 C++
Meeting Schedule Assistant.exe!CWnd::CreateRunDlgIndirect(const DLGTEMPLATE * lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst) Line 460 C++
Meeting Schedule Assistant.exe!CDialog::DoModal() Line 633 C++
Meeting Schedule Assistant.exe!CMeetingScheduleAssistantApp::InitInstance() Line 251 C++
Meeting Schedule Assistant.exe!AfxWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 37 C++
Meeting Schedule Assistant.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26 C++
[External Code]
我的主要PNG工具栏资源有10张图像。但是我指定了以下代码:
info.m_uiColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiHotResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeHotResID = IDB_PNG_MAIN_TOOLBAR;
我的工具栏图像是320 x 32。
如何处理此异常?
我认为我遇到了答案here。
CMFCToolBar::m_dblLargeImageRatio
指定大号的尺寸(高度或宽度)之间的比例图片和常规图片的尺寸。
备注默认比率为2。您可以更改此值以使较大或较小的大型工具栏图像。
当您未指定一组大图像。例如,如果您仅提供一组小图像尺寸为16x16,并希望大图片的尺寸为24x24,请设置此数据成员为1.5。
CMFCToolBar::m_dblLargeImageRatio = 1.0;