Code:
HRESULT hr = S_OK;
bool bEdgeSupportsMultipleMenus = EdgeVersionSupportsMultipleTabs(m_pCommands->GetApplicationPtr());
// Create the string info for a command (big button)
CString strBigButton;
CString CommandBar; HINSTANCE hInstance;
long index = 0;
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hInstance = AfxGetInstanceHandle();
LPCTSTR szCommandBigButton[1] = { _T("F375A38F_3DButtonCommand") };
UINT StringResourceIDBigButton[NUMBER_OF_COMMANDS] = { IDS_CMD_STRING3DBUTTON };
// Load the command with a big button's data.
strBigButton.LoadString(IDS_CMD_STRING);
CommandBar = szCommandBigButton[0] + strBigButton;
CommandBar.LoadString(IDS_COMMANDBAR_NAME);
}
CComSafeArray<BSTR> saBigButtonString;// For OLE automation, strings are passed as BSTRs in a safe array.
hr = saBigButtonString.Create();
RETURN_ON_FAILURE(hr)
CComSafeArray<long> saBigButtonCommandID;// For OLE automation, command IDs are passed in a safe array.
hr = saBigButtonCommandID.Create();
RETURN_ON_FAILURE(hr)
CComSafeArray<long> saBigButtonCommandStyle;// For OLE automation, command button styles are passed in a safe array.
hr = saBigButtonCommandStyle.Create();
RETURN_ON_FAILURE(hr)
saBigButtonString.Add(strBigButton.AllocSysString());
saBigButtonCommandID.Add(NUMBER_OF_COMMANDS);
saBigButtonCommandStyle.Add(seButtonIconAndCaptionBelow);// seButtonIconAndCaptionBelow is the way to get a big button.
_bstr_t bszCategoryName(strBigButton);
// Now push the data into the safe arrays.
if (SUCCEEDED(hr))
{
ISEAddInEx2Ptr pAddInEx2 = m_pCommands->GetAddIn();
ISEAddInExPtr pAddInEx = m_pCommands->GetAddIn();
if (NULL != pAddInEx)
{
TCHAR ResourceFilename[MAX_PATH];
GetModuleFileName(hInstance, ResourceFilename, sizeof(ResourceFilename));
if (bEdgeSupportsMultipleMenus)
{
if (NULL != pAddInEx2)
{
bszCategoryName = CommandBar;
VERIFY_OK(pAddInEx2->SetAddInInfoEx2(ResourceFilename, EnvironmentCatid,
bszCategoryName, IDB_PNG1, IDB_PNG3, -1,
-1, 1, saBigButtonString.GetSafeArrayPtr(),
saBigButtonCommandID.GetSafeArrayPtr(), saBigButtonCommandStyle.GetSafeArrayPtr()));
}
else
{
VERIFY_OK(pAddInEx->SetAddInInfoEx(ResourceFilename, EnvironmentCatid,
bszCategoryName, IDB_PNG1, IDB_PNG3, -1,
-1, 1, saBigButtonString.GetSafeArrayPtr(),
saBigButtonCommandID.GetSafeArrayPtr()));
}
}
}
else
{
AfxMessageBox(_T("Unfortunately the Button is not supported in this Version of Solid Edge"));
}
if (VARIANT_TRUE == bFirstTime && pAddInEx2 == NULL)
{
_bstr_t bszCommandBarName1(CommandBar);
for (index = 0; index < NUMBER_OF_COMMANDS; ++index)
{
CommandBarButtonPtr pButton = m_pCommands->GetAddIn()->AddCommandBarButton(EnvironmentCatid, bszCommandBarName1, index);
if (pButton)
{
pButton->Style = seButtonIconAndCaptionBelow;
}
}
if (bEdgeSupportsMultipleMenus)
{
long CmdIndex = 5;
CommandBarButtonPtr pBigButton = m_pCommands->GetAddIn()->AddCommandBarButton(EnvironmentCatid, bszCommandBarName1, CmdIndex);
if (pBigButton)
{
pBigButton->Style = seButtonIconAndCaptionBelow;
}
}
}
// Useless for ST but no harm done as this add-in has been around since day one.
EnvironmentPtr pEnv = pEnvironment;
if (NULL != pEnv)
{
CommandBarsPtr pBars = pEnv->CommandBars;
if (NULL != pBars)
{
CommandBarPtr pBar = pBars->Item(bszCategoryName);
if (NULL != pBar)
{
// Wizard default is to position it in the top area of the Solid Edge frame.
pBar->Position = seBarTop;
}
}
}
_bstr_t CommandName = "3DButton";
// Notice that the command ID returned from the call is the real command ID behind the command inside Edge.
s_LocTestCmdId = m_pCommands->GetAddIn()->AddCommand(EnvironmentCatid, CommandName, (long)10);
}
else
{
hr = E_OUTOFMEMORY;
}
return hr;