Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Example for CExtToolControlBar Collapse All
Subject Author Date
Torsten Ihben Aug 26, 2005 - 6:39 AM

Hi!

I tried to add a new button to a CExtPropertyGridToolBar. So I used CExtPropertyGridCtrl::GetChildByRTC to retrieve a pointer to the CExtPropertyGridToolBar and applied the example source code from the help of CExtToolControlBar.:

UINT nCmdID = ID_COMMANDID;
LPCTSTR sToolBarBtnText = _T("Move to front");
CExtCmdItem * p_cmd = g_CmdManager->CmdGetPtr(g_CmdManager->ProfileNameFromWnd(GetSafeHwnd()),nCmdID);
p_cmd->m_sToolbarText = sToolBarBtnText;
HICON hIcon =(HICON)::LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE( nCmdID ),IMAGE_ICON,16,16,0);
if( hIcon != NULL )
{
VERIFY(g_CmdManager->CmdSetIcon(g_CmdManager->ProfileNameFromWnd(GetSafeHwnd()),nCmdID,hIcon,false));
} // if( hIcon != NULL )
pToolbar->InsertButton( -1, nCmdID, FALSE );

I don’t understand this code, and it doesn’t work. What is the nCmdId?

I understand that I need an icon that is referenced by an ID. So I created an icon resource with the ID ID_COMMANDID - since LoadImage needs the ID of an icon and nCmdId is given. But then g_CmdManager->CmdGetPtr returns NULL.

I don’t see how the button is handled, i.e. which function is called when the button is pressed. Normally the button has an ID and the icon has a different ID, the function called when clicking the button is defined in the message map of the class containing the button.

Could you explain how this example is supposed to work?

Regards,
Torsten Ihben

Technical Support Aug 27, 2005 - 8:14 AM

It is not difficult to fix the source code. The command manager contains named command profiles and each profile contains the CExtCmdItem command descriptions for commands and icons if they were set. Each command profile is associated with one or more HWND window handles. Typically the application initializes one command profile and attaches an HWND handle of the main frame or dialog window to it. So, this design allows toolbars and menus work inside the main window and find their command profile and get information on commands from it. The CExtPropertyGridCtrl window initializes its own command profile with a unique on-the-fly generated profile name. It seems your code accesses the command profile of the main window instead of the profile associated with the property grid control. So, you need to replace the GetSafeHwnd() invocations with pPropertyGridCtrl->GetSafeHwnd(). Besides, information on commands can be added to the command profile with the UpdateFromMenu() or UpdateFromToolBar() methods of the command manager. Otherwise, you need to allocate the command identifiers using the CmdAllocPtr() method and only after that CmdGetPtr() will return a pointer to the valid CExtCmdItem object.