Initial Commit of the PDM project (ready for DWS migration)
This commit is contained in:
151
documentation/api_extracted/cppmenuitem.htm
Normal file
151
documentation/api_extracted/cppmenuitem.htm
Normal file
@@ -0,0 +1,151 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Creating Menu Commands (C++)</title>
|
||||
<meta name=MS-HKWD content="Add-ins, C++">
|
||||
<meta name=MS-HKWD content="C++, add-ins">
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
||||
<style>
|
||||
<!--
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
||||
<h1>Creating Menu Commands (C++)</h1>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-family:Verdana'>This topic shows how to create a
|
||||
C++ add-in in Microsoft Visual Studio that adds menu commands to the
|
||||
context-sensitive and Tools menus of vaults in File
|
||||
Explorer.</span></p>
|
||||
|
||||
<ol style="font-family: serif; font-size: 8pt">
|
||||
<li>
|
||||
<p class=MsoNormal><span style="font-family: Verdana">Create </span>
|
||||
<span lang=EN-US style='font-family:Verdana'>an add-in as described in the <a href="cppaddin.htm">basic framework sample</a>.<o:p></o:p></span></p></li>
|
||||
</ol>
|
||||
<ol style="font-family: Verdana; font-size: 8pt" start="3">
|
||||
<li value="2">
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='mso-fareast-font-family:"MS Mincho"'>
|
||||
<font face="Verdana">Replace your add-in's implementation of
|
||||
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~GetAddInInfo.html"> IEdmAddIn5::GetAddInInfo</a>
|
||||
with the following code:</font></span></p></li>
|
||||
</ol>
|
||||
<blockquote>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>STDMETHOD(GetAddInInfo)(EdmAddInInfo
|
||||
* poInfo, IEdmVault5 * poVault, IEdmCmdMgr5 * poCmdMgr)<br>{<br>
|
||||
<span style='color:green'> //The AFX_MANAGE_STATE macro is needed for MFC
|
||||
applications but should not <br> //be used for applications that are MFC-free.</span><br> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
|
||||
<br> if (poInfo == NULL || poCmdMgr == NULL )<br> return E_POINTER;<br>
|
||||
<br><span style='color:green'> //Return some information for the
|
||||
Administrate Add-ins dialog box<br></span> poInfo->mbsAddInName = SysAllocString( L"Menu command
|
||||
sample" );<br> poInfo->mbsCompany = SysAllocString( L"SOLIDWORKS Corporation"
|
||||
);<br> poInfo->mbsDescription= SysAllocString( L"Adds menu items" );<br> poInfo->mlAddInVersion = 1;<br><br>
|
||||
<span style='color:green'> //SOLIDWORKS PDM Professional
|
||||
<st1:metricconverter
|
||||
ProductID="5.2 in" w:st="on">5.2 or later is required</st1:metricconverter> to
|
||||
install this add-in<br></span> poInfo->mlRequiredVersionMajor = 5;<br> poInfo->mlRequiredVersionMinor = 2;<br><br>
|
||||
<span style='color:green'> //Add a command for each of the buttons
|
||||
(the command ID numbers 1000 and 1001 are <br> //arbitrary; SOLIDWORKS PDM Professional
|
||||
does not use them; instead, it only passes them to
|
||||
your <br> //implementation of OnCmd so that it knows which command was selected)<br>
|
||||
</span> poCmdMgr->AddCmd( 1000, bstr_t("First command"),
|
||||
EdmMenu_Nothing, </span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'> bstr_t("This
|
||||
is the first command"), </span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>
|
||||
bstr_t("First command"), -1, 0 );<br><br> poCmdMgr->AddCmd( 1001, bstr_t("Second command"),
|
||||
EdmMenu_MustHaveSelection, </span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'> bstr_t("This
|
||||
is the second command"), </span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>
|
||||
bstr_t("Second command"), -1, 0 );<br><br> return S_OK;<br>}</span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-family:Verdana;
|
||||
mso-fareast-font-family:"MS Mincho"'>The flag
|
||||
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmMenuFlags.html"> EdmMenuFlags.EdmMenu_MustHaveSelection</a>
|
||||
indicates that only the second command is available to the user if the user
|
||||
selects one or more files or folders.</span></p>
|
||||
</blockquote>
|
||||
<ol style="font-family: Verdana; font-size: 8pt" start="4">
|
||||
<li value="3">
|
||||
<p class=MsoNormal><span style="font-family: Verdana">Replace your add-in's implementation of
|
||||
</span>
|
||||
<span lang=EN-US style='font-family:Verdana;
|
||||
mso-fareast-font-family:"MS Mincho"'>
|
||||
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~OnCmd.html"> IEdmAdd5::OnCmd</a>
|
||||
with the following code:</span></p>
|
||||
<blockquote>
|
||||
<p class=MsoNormal style='line-height:11.3pt'>
|
||||
<span lang=EN-US
|
||||
style='font-size:10.0pt;font-family:"Courier New"'>STDMETHOD(OnCmd)(EdmCmd *
|
||||
poCmd, SAFEARRAY * * ppoData)<br>{<br><span style='color:green'> //The AFX_MANAGE_STATE macro is needed for MFC
|
||||
applications but should not <br> //be used for applications that are MFC-free<br>
|
||||
</span> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br><br> if (poCmd == NULL ||ppoData == NULL)<br> return E_POINTER;<br>
|
||||
<br><span style='color:green'> //Check the command ID to see which
|
||||
command was selected<br> //(this only affects the caption of the message box below)<br>
|
||||
</span> CString oName;<br> if( poCmd->mlCmdID = = 1000 )<br> oName = "The first command";<br> else<br> oName = "The second command";<br>
|
||||
<br> if( SafeArrayGetDim( *ppoData ) != 1 )<br> return E_INVALIDARG;<br>
|
||||
<br><span style='color:green'> //Get a pointer to the actual array
|
||||
elements<br></span> EdmCmdData *poElements = NULL;<br> HRESULT hRes = SafeArrayAccessData( *ppoData, (void**)&poElements
|
||||
);<br> if( FAILED(hRes) )<br> return hRes;<br><br>
|
||||
<span style='color:green'> //Create a message showing the names and
|
||||
IDs of all selected files and folders<br></span> CString oRow;<br> CString oMessage = "You have selected the following files and
|
||||
folders:\n";<br> int iCount=(*ppoData)->rgsabound->cElements;<br> for( int i = 0; i < iCount; ++i )<br> {
|
||||
<br> if(poElements->mlObjectID1 == 0 )<br> {<br> oRow.Format( "Folder: (ID= %d)
|
||||
",poElements->mlObjectID2 );<br> }<br> else<br> {<br> oRow.Format( "File: (ID= %d)
|
||||
",poElements->mlObjectID1 );<br> }<br> oMessage += oRow + (LPCTSTR)bstr_t(poElements->mbsStrData1
|
||||
);<br> oMessage += "\n";<br> ++poElements;<br> }<br>
|
||||
<br><span style='color:green'> //Release the array data and display the
|
||||
message<br></span> SafeArrayUnaccessData( *ppoData );<br> MessageBox((HWND)poCmd->mlParentWnd, oMessage, oName, MB_OK );
|
||||
<br> return S_OK;<br>}</span></p>
|
||||
</blockquote>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal style='line-height:11.3pt'>Save and compile the project.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
|
||||
<span lang=EN-GB
|
||||
style='font-family:Verdana;mso-ansi-language:EN-GB'>Add the add-in DLL to the
|
||||
file vault using the</span><font face="Verdana"><span lang=EN-GB style='mso-ansi-language:EN-GB'>
|
||||
</span></font>
|
||||
<span lang=EN-GB style='font-family:Verdana;mso-ansi-language:EN-GB'>
|
||||
<a href="AdminDlg.htm">Administration tool</a>.</span></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal><font face="Verdana">The first menu command appears in
|
||||
the</font><span lang=EN-US style='mso-fareast-font-family:"MS Mincho"'><font face="Verdana">
|
||||
context-sensitive and Tools menus of vaults in File Explorer. The second menu command appears in the context-sensitive menus
|
||||
only when one or
|
||||
more files or folders are selected.</font> </span>
|
||||
<span style="font-family: Verdana">Right-click a file in the vault
|
||||
and</span><span lang=EN-US style='font-family:Verdana;
|
||||
mso-fareast-font-family:"MS Mincho"'> select <b>Second command</b>. A dialog
|
||||
similar to the following is displayed:</span></p>
|
||||
<p class=MsoNormal>
|
||||
<span lang=EN-US style='font-size:10.0pt;font-family:Arial;
|
||||
mso-fareast-font-family:"MS Mincho"'>
|
||||
<img border=0 width=266 height=185
|
||||
id="_x0000_i1030" src=advancedmenu.gif></span></p>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user