Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Customizing the 'open menu'

Status
Not open for further replies.

Creigbm

Mechanical
Aug 1, 2003
161
I have been trying to customize the open menu dialog so that the links on the left side (such as History, My Documents, Desktop, etc) would contain other links to my network. I have looked in to the possibility of creating a macro that will serve this purpose, but I have been unable to locate any literature on how to change these links. I hope I have posed my question in a clear way. Thanks in advance for any help.
 
Replies continue below

Recommended for you

If you are referring to the File Open dialog that pops up when you click "File", "Open" from Solidworks; then yes, it is *technically* possible.

It's called "subclassing", and really has nothing to do with Solidworks. It requires hijacking of the Windows API messaging system, and is a considerable amount of work.

Grabbing the window when it pops up, and re-arranging/adding buttons to it is one thing, but when it comes down to actually interfacing with the events, I would not trust a macro to be able to catch even a limited subset of the event streams; even a compiled, standalone VB application cant get them all. And if you miss an event, your code will be sitting there in a loop, possibly even after the dialog is closed.

It might be a lot easier for your program to pop up its OWN custom-made file dialog window ; the VB runtime will handle the events for you. You can then pass the appropriate file name to a SW API call.
 
Thanks rocheey for the advice. I was actually leaning towards making my own custom made dialog and this is what I have so far.

Code:
Option Explicit
' declarations, used windows API calls and constants
' Deklarationen, benötigte Windows API-Calls und Konstanten

' Windows API to get the free discspace
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" ( _
    ByVal lpRootPathName As String, _
    lpFreeBytesAvailableToCaller As Currency, _
    lpTotalNumberOfBytes As Currency, _
    lpTotalNumberOfFreeBytes As Currency) As Long

' Windows API for the SaveAs Filebox
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long
' structure needed by Windows API
Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
' for more information on Open- or SaveAs dialogs look at
' [URL unfurl="true"]http://www.mvps.org/vbnet/index.html?code/comdlg/filedlgsoverview.htm[/URL]

' SolidWorks related declarations
Dim swApp As Object         ' SolidWorks session
Dim PauseTime As Double
Dim Start As Double
Dim Finish As Double
Dim ModelDoc2 As Object     ' active document
Dim filenameIn As String    ' desired filename for saved bitmap
Private Sub CommandButton1_Click()
    ' common dialog for browse for desired filename
    ' Auswahl des Dateinamens für Bitmap
    
    Dim OFName As OPENFILENAME
    Dim tmp As String
    'Set the structure size
    OFName.lStructSize = Len(OFName)
    'Set the filet
    OFName.lpstrFilter = "SolidWorks Part (*.sldprt)" + Chr$(0) + "*.sldprt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    'Create a buffer
    OFName.lpstrFile = Space$(254)
    'Set the maximum number of chars
    OFName.nMaxFile = 255
    'Create a buffer
    OFName.lpstrFileTitle = Space$(254)
    'Set the maximum number of chars
    OFName.nMaxFileTitle = 255
    'Set the initial directory (Doesn't Quite Work)
    'OFName.lpstrInitialDir =
    'Set the dialog title
    OFName.lpstrTitle = UserForm1.Caption
    'no extra flags
    OFName.flags = 0
    'default extension
    OFName.lpstrDefExt = "sldprt" + Chr$(0)

    'Show the 'Save File'-dialog
    If GetSaveFileName(OFName) Then
        FileName.Text = Trim$(OFName.lpstrFile)
    Else
        FileName.Text = ""
    End If

End Sub
Private Function FileExists(strDest As String) As Boolean
  ' checks if file strDest exists
  Dim intLen As Integer
 
  If strDest <> vbNullString Then
    On Error Resume Next
    intLen = Len(Dir$(strDest))
    On Error GoTo 0
    FileExists = (Not Err And intLen > 0)
  Else
    FileExists = False
  End If

End Function
Private Function GetPathPart(strPath As String) As String
  '
  Dim intCounter As Integer

  ' Parse the string backwards
  For intCounter = Len(strPath) To 1 Step -1
    ' Short-circuit when we reach the slash
    If Mid$(strPath, intCounter, 1) = &quot;\&quot; Then
      Exit For
    End If
  Next intCounter

  ' Return the value
  GetPathPart = Left$(strPath, intCounter)

End Function

This is what I have in the Userform and it pulls up an open dialog. Do you, or anyone for that matter, know how to modify this to suit a custom link on the left side with the others? Thanks
 
Hi Creigbm,

I know these code lines, you got them from one of my macros from ;-)

All I can say: no, it is not possible to &quot;customize&quot; the save/open dialog with API calls.

You may want to read MS knowledgebase article 205041 ( ) to see how you can customize this for Office, but AFAIK it is noit possible for SolidWorks.

Bye,
Stefan

--
unofficial german SolidWorks helppage
Shareware, freeware, tools and macros
 
>> I know these code lines, you got them from one of
>> my macros from
.. and I know that site .. it is the one that has the code for the feature-hide/show routine that I posted on the newsgroups about a year or so ago. I think the title of the original thread/post was called 'feature snatcher' .. a good Deja news search should pull it up.

Thanx for adding the foreign language support. Was that you that also took credit for it in the subscription section on the SW site?

>>it is not possible to &quot;customize&quot; the save/open
>>dialog with API calls

of course it is. That is the very way solidworks does it; call the API, subclass, and add their their own controls.
I've also done it myself, (because I HAD to) on a CAM application that didnt allow scripting/automation.
 
So rocheey, if it is possible, would you happen to know how to do it [smile]
 
Ok, well, to do it right, and robustly, is a major undertaking. If you wanna see a limited 'demo' in VB source, something like making the &quot;Open&quot; button in the SW common dialog change to &quot;Eng-Tips&quot; or something, that would be doable.

But Im not much for doing someones complete job, homework, or macro page <wink>.

Ill see if I can re-use some code and post something tomorrow.
 
Thanks for your help, and this is not a homework assignment! I think I found a way around it by using command buttons to set the working directory, then use Stefan's great 'open dialog menu' to open the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor