解决 LoadToolbarEx 的异常和正常 v 大图像计数之间的差异
Resolving an exception with LoadToolbarEx and difference between count of normal v large images
我刚刚在调试中尝试 运行 我的 CDialog
应用程序,但出现异常。和我创建myu toolbar有关
我在 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
Specifies the ratio between the dimension (height or width) of large
images and the dimension of regular images.
Remarks The default ratio is 2. You can change this value to make
large toolbar images larger or smaller.
The framework uses this data member when you do not specify a set of
large images. For example, if you provide only the set of small images
with size 16x16 and want the large images to have the size 24x24, set
this data member to 1.5.
CMFCToolBar::m_dblLargeImageRatio = 1.0;
我刚刚在调试中尝试 运行 我的 CDialog
应用程序,但出现异常。和我创建myu toolbar有关
我在 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
Specifies the ratio between the dimension (height or width) of large images and the dimension of regular images.
Remarks The default ratio is 2. You can change this value to make large toolbar images larger or smaller.
The framework uses this data member when you do not specify a set of large images. For example, if you provide only the set of small images with size 16x16 and want the large images to have the size 24x24, set this data member to 1.5.
CMFCToolBar::m_dblLargeImageRatio = 1.0;