天天看点

MFC Toolbar图标尺寸调整出错解决方法

解决方法转自

https://social.msdn.microsoft.com/Forums/vstudio/en-US/8e8b8995-706f-43cc-9463-700d9fa6a010/how-can-i-adjust-icon-size-of-toolbar?forum=vcgeneral

当调整Toolbar中的图标大小的时候,会导致MFC打开后afxToolbar类型的名称的cpp出错。

原因是,默认在程序目录中有一个UserImages.bmp文件,其中的图标尺寸是16*15。

默认的MFC程序会自动加载这个图片,导致程序出错。解决方法如下:

problem solved.

reason is the CMainFrame.cpp  OnCreate event,

the following code cause problem, quote them , problem solved.

there is a UserImages.bmp in project folder, size 15*16,  and we change size, so the two size different, so cause this.

exactly assertion error is from here , the bold  italic underline words.

BOOL __stdcall CMFCToolBar::SetUserImages(CMFCToolBarImages* pUserImages)

{

 ENSURE(pUserImages != NULL);

 if (!pUserImages->IsValid())

 {

  ASSERT(FALSE);

  return FALSE;

 }

 if (m_sizeImage != pUserImages->GetImageSize())

 {

  ASSERT(FALSE);

  return FALSE;

 }

 m_pUserImages = pUserImages;

 return TRUE;

}

另外,添加或减少Toolbar中的图标后,用编辑器打开XXX.rc文件,检查TOOLBAR下面的BUTTON项中是否也更新,

如果没有更新,自行手动处理,添加或删除图标使之和Toolbar图片的上的保持一致。

IDR_MAINFRAME TOOLBAR 17, 15

BEGIN

    BUTTON      ID_FILE_NEW

    BUTTON      ID_FILE_OPEN

    BUTTON      ID_FILE_SAVE

    BUTTON      ID_FILE_PRINT

    BUTTON      ID_BUTTON_RESET_VIEW

    BUTTON      ID_BUTTON_ZOOM_ALL

    BUTTON      ID_APP_ABOUT

END