Initial Commit of the PDM project (ready for DWS migration)

This commit is contained in:
will
2026-04-20 08:42:38 -05:00
commit dda7b664e7
2721 changed files with 442772 additions and 0 deletions

View 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'>&nbsp; //The AFX_MANAGE_STATE macro is needed for MFC
applications but should not <br>&nbsp; //be used for applications that are MFC-free.</span><br>&nbsp; AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
<br>&nbsp; if (poInfo == NULL || poCmdMgr == NULL )<br>&nbsp;&nbsp;&nbsp; return E_POINTER;<br>
<br><span style='color:green'>&nbsp; //Return some information for the
Administrate Add-ins dialog box<br></span>&nbsp;poInfo-&gt;mbsAddInName = SysAllocString( L&quot;Menu command
sample&quot; );<br>&nbsp;poInfo-&gt;mbsCompany = SysAllocString( L&quot;SOLIDWORKS Corporation&quot;
);<br>&nbsp; poInfo-&gt;mbsDescription= SysAllocString( L&quot;Adds menu items&quot; );<br>&nbsp;poInfo-&gt;mlAddInVersion = 1;<br><br>
<span style='color:green'>&nbsp; //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>&nbsp;poInfo-&gt;mlRequiredVersionMajor = 5;<br>&nbsp;poInfo-&gt;mlRequiredVersionMinor = 2;<br><br>
<span style='color:green'>&nbsp; //Add a command for each of the buttons
(the command ID numbers 1000 and 1001 are <br>&nbsp; //arbitrary; SOLIDWORKS PDM Professional
does not use them; instead, it only passes them to
your <br>&nbsp; //implementation of OnCmd so that it knows which command was selected)<br>
</span>&nbsp; poCmdMgr-&gt;AddCmd( 1000, bstr_t(&quot;First command&quot;),
EdmMenu_Nothing, </span></p>
<p class=MsoNormal>
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bstr_t(&quot;This
is the first command&quot;), </span></p>
<p class=MsoNormal>
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bstr_t(&quot;First command&quot;), -1, 0 );<br><br>&nbsp; poCmdMgr-&gt;AddCmd( 1001, bstr_t(&quot;Second command&quot;),
EdmMenu_MustHaveSelection, </span></p>
<p class=MsoNormal>
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bstr_t(&quot;This
is the second command&quot;), </span></p>
<p class=MsoNormal>
<span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bstr_t(&quot;Second command&quot;), -1, 0 );<br><br>&nbsp; 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&nbsp;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'>&nbsp; //The AFX_MANAGE_STATE macro is needed for MFC
applications but should not <br>&nbsp; //be used for applications that are MFC-free<br>
</span>&nbsp; AFX_MANAGE_STATE(AfxGetStaticModuleState());<br><br>&nbsp; if (poCmd == NULL ||ppoData == NULL)<br>&nbsp;&nbsp;&nbsp; return E_POINTER;<br>
<br><span style='color:green'>&nbsp; //Check the command ID to see which
command was selected<br>&nbsp; //(this only affects the caption of the message box below)<br>
</span>&nbsp; CString oName;<br>&nbsp; if( poCmd-&gt;mlCmdID = = 1000 )<br>&nbsp;&nbsp;&nbsp; oName = &quot;The first command&quot;;<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; oName = &quot;The second command&quot;;<br>
<br>&nbsp; if( SafeArrayGetDim( *ppoData ) != 1 )<br>&nbsp;&nbsp;&nbsp; return E_INVALIDARG;<br>
<br><span style='color:green'>&nbsp; //Get a pointer to the actual array
elements<br></span>&nbsp; EdmCmdData *poElements = NULL;<br>&nbsp; HRESULT hRes = SafeArrayAccessData( *ppoData, (void**)&amp;poElements
);<br>&nbsp; if( FAILED(hRes) )<br>&nbsp;&nbsp;&nbsp; return hRes;<br><br>
<span style='color:green'>&nbsp; //Create a message showing the names and
IDs of all selected files and folders<br></span>&nbsp; CString oRow;<br>&nbsp; CString oMessage = &quot;You have selected the following files and
folders:\n&quot;;<br>&nbsp; int iCount=(*ppoData)-&gt;rgsabound-&gt;cElements;<br>&nbsp; for( int i = 0; i &lt; iCount; ++i )<br>&nbsp; {
<br>&nbsp; &nbsp; if(poElements-&gt;mlObjectID1 == 0 )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp;&nbsp;&nbsp; oRow.Format( &quot;Folder: (ID= %d)
&quot;,poElements-&gt;mlObjectID2 );<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp;&nbsp;&nbsp; oRow.Format( &quot;File: (ID= %d)
&quot;,poElements-&gt;mlObjectID1 );<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; oMessage += oRow + (LPCTSTR)bstr_t(poElements-&gt;mbsStrData1
);<br>&nbsp; &nbsp; oMessage += &quot;\n&quot;;<br>&nbsp; &nbsp; ++poElements;<br>&nbsp; }<br>
<br><span style='color:green'>&nbsp; //Release the array data and display the
message<br></span>&nbsp; SafeArrayUnaccessData( *ppoData );<br>&nbsp; MessageBox((HWND)poCmd-&gt;mlParentWnd, oMessage, oName, MB_OK );
<br>&nbsp; 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>