having trouble with LoadToolBarEx function of the

2019-09-01 08:06发布

问题:

I have created a new empty dialog to test the code Some notes on CMFCToolBar – Docking Large Buttons and use of the MDIClientArea but I see that this line produces false:

bool b = m_FirstToolbar.LoadToolBarEx(IDR_MAINFRAME, tbi, TRUE);  

and this is the resources of my project:

what's the problem and what should I add to the resources?
please help me. this is the third question that I ask today about toolbars on an MFC dialog based application.
My toolbar on a dialog based mfc application is not shown
after writing the code to add a toolbar to a dialog-based mfc the dialog doesn't run
and I have read many questions on this site and also studied lots of pages on the web. finally I came to the point to use CMFCToolBar class instead of CToolbar to support 32bit 24x24 icons for the toolbar but none of the pages helped really and I haven't still seen the toolbar at top of my dialog.
Could you please help me introduce a link,a video tutorial and etc which has taught adding toolbars that support icons of 32bit images in Visual studio 2010 to a dialog-based mfc application **
**I'd prefer a tutorial which has started from scratch and is good for a beginner of MFC as well a to aguru

thanks.I'd be glad to here your answers.

Edited section of my question based on @Edward Clements useful guidances
this is my project's Resource.h file

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by InitialJobProject2.rc
//
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_INITIALJOBPROJECT2_DIALOG   102
#define IDR_MAINFRAME                   128
#define IDB_BITMAP1                     130
#define IDR_TOOLBAR1                    132
#define IDI_ICON1                       135
#define IDC_NewBtnTbr                   135
#define IDC_ZoomInBtnTbr                136
#define IDC_ZoomOutBtnTbr               137
#define IDI_ICON2                       138
#define IDC_PanBtnTbr                   138
#define IDC_TXTDataFile                 1001
#define IDC_EDTDataPath                 1002
#define IDC_BTNBrowse                   1003
#define IDC_RICHEDTHeader               1005
#define IDC_OPENGL                      1009

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        139
#define _APS_NEXT_COMMAND_VALUE         32776
#define _APS_NEXT_CONTROL_VALUE         1010
#define _APS_NEXT_SYMED_VALUE           104
#endif
#endif  

I don't know how the numbers are set? and how should I compute the number to assign to the new ID?
what's the difference between _APS_NEXT_RESOURCE_VALUE,_APS_NEXT_COMMAND_VALUE,_APS_NEXT_CONTROL_VALUE and _APS_NEXT_SYMED_VALUE?
and if I assign the number 1010 to the new ID then what should I write in front of _APS_NEXT_CONTROL_VALUE?
and one more question that rose up is this one:

I have used the MFC/C++ Helper Class for Window Resizing from codeproject to anchor controls of dialog to it. This class uses ID of controls. and I have added a COpenGLControl from codeguru for Setting Up OpenGL in an MFC Control which does not need ID in its constructor but since it is derived from CWnd class,it has a function setHelpIDCould I add this way anIDM,IDB,IDD,IDR,IDS,IDI or IDC (I don't know which one please help me how to choose between themand then assign this ID through functionsetHelpIDto the instance of the classCOpenglControl? and then use this ID to hook the openGL window to the main window through classCWndResizer`?

Problem solved
the way that I suggested for setting ID for the opengl window does work except that you should use SetDlgCtrlID member function instead of SetHelpID

回答1:

I'm not familiar with loading toolbars into a dialog, but you need to create a Toolbar resource with an ID (I would not use IDR_MAINFRAME myself since it is confusing and you may need multiple toolbars) and use this ID in LoadToolBarEx; the toolbar would contain buttons with their own images and IDs. You will need a ON_COMMAND and ON_UPDATE_COMMAND_UI in your message map to enable/disable the buttons and to respond to the button clicks.

This MSDN forum post mentions that your dialog needs to be derived from CDialogEx instead of CDialog.

There's very little clear documentation on the MFC Featurepack Controls (like CMFCToolbar), this CodeProject article might help (even though it's about porting a legacy application, it still has quite a lot of useful do's and dont's).

Some more info in ths SO article, this is about creating toolbars dynamically (without having a toolbar resource).