天天看點

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