Author Topic: MS common dialog box in lisp  (Read 10132 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: MS common dialog box in lisp
« Reply #15 on: January 17, 2006, 07:27:20 PM »
:-(

Well I tried.....

BTW, I work here as a Janitor... I do code or pretending doing code.. and still learning... 8-)

Okay.  I will try.  I will be asking a lot of questions though, so be ready.   :lmao:

From what I can tell, the CommonDialog control is for use on VB forms. These types of controls, AFAIK, are not usable in VBA or Lisp. For instance, I just tried to place a CommonDialog control into a form in VBA and I recieved an error message stating that the program was not properly licensed to use such control.

Thanks for pointing that out Jeff.  Here is the page that I found the code that I thought was for VBA.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: MS common dialog box in lisp
« Reply #16 on: January 17, 2006, 08:07:39 PM »
After a quick perusal of the help files, it looks to me like you could create your own little FileSelectDialog with lisp/dcl. A list_box control allows the use of multi-select....you could fill the list_box with data obtained from (vl-directory-files).

I'd offer up a solution, but as most everyone here knows....I don't do DCL :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: MS common dialog box in lisp
« Reply #17 on: January 17, 2006, 08:15:02 PM »
Tim, Have a look at this in the mean time.

Look at dos_getfilem

added : It's been around for 14 years ..
Quote
© 1992-2004 Robert McNeel & Associates. All rights reserved.
...
Permission to use, copy, and distribute this software for any purpose and without fee is hereby granted, ....
« Last Edit: January 17, 2006, 08:24:34 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: MS common dialog box in lisp
« Reply #18 on: January 17, 2006, 11:18:34 PM »
The  commondialog can be accessed by scripting, however, since it was designed entirely for a development platform it may not work properly if you do not have the proper licenses to use it .. i.e. a development tool licensed from MicroSoft installed. You can try the following code just to test, and if it works then good for you .. if not, then you could create a wrapper dll that invokes the common dialog and call that dialog from lisp .. if I get time I'll look up the KB article on it ....

Code: [Select]
(setq mscd (vlax-create-object  "MSComDlg.CommonDialog")) ;create the object
(vlax-put-property mscd "Filename" "*.*") ;set the file filters
(vlax-put-property mscd "MaxFileSize" 10000) ;set the maximum size of the filename
(vlax-put-property mscd "Flags" 524800) ;set the dialog flags (you can find these in the API reference)
(vlax-put-property mscd "Action" 1) ;set the action of the dialog ... i.e. invoke it as "Open File"
(setq strFileName (vlax-get-property mscd "Filename"))
Now, this is the least number of items required to invoke this dialog, there are a whole lot of other items that may be set, such as dialog title, file name to search for, starting folder etc ... just vlax-dump-object to see the rest ....

To change the dialog type.. use the following as actions ..
0 = Do Nothing
1 = Open File
2 = Save As
3 = Color Dialog
4 = Font Dialog
5 = Printers
6 = WinHelp

Have fun ... and I want to start seeing alot of this kind of thing in future programming ... :)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: MS common dialog box in lisp
« Reply #19 on: January 18, 2006, 07:27:27 AM »
I wrote this a couple of years ago. It was based on a (useless) sample of Frank O.
Code: [Select]
;
; =============================================================================
; == CommonDialog functions library ===========================================
; =============================================================================
;
; Copyright:
;   ©2003 MENZI ENGINEERING GmbH, Switzerland
;
; See also:
;   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmdlg98/html/vbobjcommondialog.asp
;   for detailed information about CommonDialog Control
;
; CommonDialog Flag values:
; cdlOFNAllowMultiselect   &H200 (512) Specifies that the File Name list
; box allows multiple selections.
; cdlOFNCreatePrompt    &H2000 (8092) Specifies that the dialog box
; prompts the user to create a file
; that doesn't currently exist. This
; flag automatically sets the
; cdlOFNPathMustExist and
; cdlOFNFileMustExist flags.
; cdlOFNExplorer    &H80000 (524288) Use the Explorer-like Open A File
; dialog box template. Works with
; Windows 95, Windows NT 4.0, or
; later versions.
; cdlOFNExtensionDifferent &H400 (1024) Indicates that the extension of the
; returned filename is different from
; the extension specified by the
; DefaultExt property. This flag isn't
; set if the DefaultExt property is
; Null, if the extensions match, or if
; the file has no extension. This flag
; value can be checked upon closing
; the dialog box.
; cdlOFNFileMustExist    &H1000 (4096) Specifies that the user can enter
; only names of existing files in the
; File Name text box. If this flag is
; set and the user enters an invalid
; filename, a warning is displayed.
; This flag automatically sets the
; cdlOFNPathMustExist flag.
; cdlOFNHelpButton    &H10 (16) Causes the dialog box to display the
; Help button.
; cdlOFNHideReadOnly    &H4 (4) Hides the Read Only check box.
; cdlOFNLongNames    &H200000 (2097152) Use long filenames.
; cdlOFNNoChangeDir    &H8 (8) Forces the dialog box to set the
; current directory to what it was
; when the dialog box was opened.
; CdlOFNNoDereferenceLinks &H100000 (1048576) Do not dereference shell links
; (also known as shortcuts). By
; default, choosing a shell link
; causes it to be dereferenced by the
; shell.
; cdlOFNNoLongNames    &H40000 (262144) No long file names.
; CdlOFNNoReadOnlyReturn   &H8000 (32768) Specifies that the returned file
; won't have the Read Only attribute
; set and won't be in a write-protected
; directory.
; cdlOFNNoValidate    &H100 (256) Specifies that the common dialog box
; allows invalid characters in the
; returned filename.
; cdlOFNOverwritePrompt    &H2 (2) Causes the Save As dialog box to
; generate a message box if the selected
; file already exists. The user must
; confirm whether to overwrite the file.
; cdlOFNPathMustExist    &H800 (2048) Specifies that the user can enter only
; valid paths. If this flag is set and
; the user enters an invalid path, a
; warning message is displayed.
; cdlOFNReadOnly    &H1 (1) Causes the Read Only check box to be
; initially checked when the dialog box
; is created. This flag also indicates
; the state of the Read Only check box
; when the dialog box is closed.
; cdlOFNShareAware    &H4000  (16384) Specifies that sharing violation
; errors will be ignored.
;
; == Function MeFileOpen
; Opens the CommonDialog for open a file.
; Arguments [Type]:
;   Fnm = Initial file name [STR]
;         or nil if not used
;   Flt = Filter string [STR]
;         or nil if not used
;   Dir = Initial directory [STR]
;         or nil if not used
;   Tit = Dialog title [STR]
;         or nil if not used
;   Flg = Flag value (see header) [INT]
; Return [Type]:
;   > List of file name(s) [LIST]
;     nil if dialog cancelled
; Notes:
;   - None
; Sample:
; (MeFileOpen nil "AutoCAD Drawing (*.dwg)|*.dwg" "C:\\Temp" "Open an AutoCAD drawing" 524800)
;
(defun MeFileOpen (Fnm Flt Dir Tit Flg / ComDlg ExpDlg RetVal TmpLst)
 (setq ComDlg (vlax-create-object "MSComDlg.CommonDialog")
       ExpDlg (and Flg (= (logand Flg 524288) 524288))
 )
 (if Fnm (vlax-put ComDlg 'Filename Fnm))
 (if Flt (vlax-put ComDlg 'Filter Flt))
 (if Dir (vlax-put ComDlg 'InitDir Dir))
 (if Tit (vlax-put ComDlg 'DialogTitle Tit))
 (vlax-put ComDlg 'MaxFileSize 16384)
 (vlax-put ComDlg 'Flags Flg)
 (vlax-put ComDlg 'Action 1)
 (setq RetVal (vlax-get ComDlg 'FileName))
 (vlax-release-object ComDlg)
 (if (not (eq RetVal ""))
  (progn
   (setq TmpLst (MeString2ListByAscii RetVal (if ExpDlg 256 32)))
   (if (> (length TmpLst) 1)
    (mapcar
    '(lambda (l) (strcat (car TmpLst) (if ExpDlg "\\" "") l))
     (cdr TmpLst)
    )
    TmpLst
   )
  )
 )
)
;
; == Function MeFileSaveAs
; Opens the CommonDialog for save a file.
; Arguments [Type]:
;   Fnm = Initial file name [STR]
;         or nil if not used
;   Flt = Filter string [STR]
;         or nil if not used
;   Dir = Initial directory [STR]
;         or nil if not used
;   Tit = Dialog title [STR]
;         or nil if not used
;   Flg = Flag value (see header) [INT]
; Return [Type]:
;   > List of file name and filter index [LIST]
;     nil if dialog cancelled
; Notes:
;   - None
; Sample:
; (MeFileSaveAs "MyFileName" "AutoCAD Drawing (*.dwg)|*.dwg|AutoCAD DXF (*.dxf)|*.dxf" "C:\\Temp" nil 6)
;
(defun MeFileSaveAs (Fnm Flt Dir Tit Flg / ComDlg FltIdx RetVal)
 (setq ComDlg (vlax-create-object "MSComDlg.CommonDialog"))
 (if Fnm (vlax-put ComDlg 'Filename Fnm))
 (if Flt (vlax-put ComDlg 'Filter Flt))
 (if Dir (vlax-put ComDlg 'InitDir Dir))
 (if Tit (vlax-put ComDlg 'DialogTitle Tit))
 (vlax-put ComDlg 'MaxFileSize 16384)
 (vlax-put ComDlg 'Flags Flg)
 (vlax-put ComDlg 'Action 2)
 (setq RetVal (vlax-get ComDlg 'FileName)
       FltIdx (vlax-get ComDlg 'FilterIndex)
 )
 (vlax-release-object ComDlg)
 (if (not (eq RetVal "")) (list RetVal FltIdx))
)
;
; == Function MeString2ListByAscii
; Converts a string to a list by an ASCII delimiter.
; Arguments [Typ]:
;   Stg = String to convert [STR]
;   Del = Delimiter ASCII code [INT]
; Return [Typ]:
;   > Converted String [LIST]
; Notes:
;   - None
;
(defun MeString2ListByAscii (Stg Del / StrPos TmpLst TmpStr)
 (setq TmpStr Stg
       StrPos (vl-string-position Del TmpStr)
 )
 (while StrPos
  (setq TmpLst (cons (substr TmpStr 1 StrPos) TmpLst)
        TmpStr (substr TmpStr (+ StrPos 2))
        StrPos (vl-string-position Del TmpStr)
  )
 )
 (if (> (strlen TmpStr) 0)
  (setq TmpLst (cons TmpStr TmpLst))
 )
 (reverse TmpLst)
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

T.Willey

  • Needs a day job
  • Posts: 5251
Re: MS common dialog box in lisp
« Reply #20 on: January 18, 2006, 11:26:44 AM »
After a quick perusal of the help files, it looks to me like you could create your own little FileSelectDialog with lisp/dcl. A list_box control allows the use of multi-select....you could fill the list_box with data obtained from (vl-directory-files).

I'd offer up a solution, but as most everyone here knows....I don't do DCL :-)
There in lies the problem.  We have had consultants that want to process more than 250 (or around there) drawings, but you can't show that many drawings (items) in a list box.  I have done stuff like this aready, but it won't work here.

Tim, Have a look at this in the mean time.

Look at dos_getfilem

added : It's been around for 14 years ..
Quote
© 1992-2004 Robert McNeel & Associates. All rights reserved.
...
Permission to use, copy, and distribute this software for any purpose and without fee is hereby granted, ....
We have DosLib now, but we were wanting to develop something that isn't dependant on anyone else.

The commondialog can be accessed by scripting, however, since it was designed entirely for a development platform it may not work properly if you do not have the proper licenses to use it .. i.e. a development tool licensed from MicroSoft installed. You can try the following code just to test, and if it works then good for you .. if not, then you could create a wrapper dll that invokes the common dialog and call that dialog from lisp .. if I get time I'll look up the KB article on it ....
<snip>
I have tried this, and it won't work on my computer.  From the others, it seems like I have to register it, and that hasn't worked for me either.

Jurg, same as above.  I couldn't get your code to work on my compter.

Thanks for trying everyone.  I don't know why the ideas posted here won't work on my computer, as they all look like they should.  I will try to find another solution.  Post back if/when I do.

Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: MS common dialog box in lisp
« Reply #21 on: January 18, 2006, 11:00:14 PM »
I found this:

Code: [Select]
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_NOLONGNAMES = &H40000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHOWHELP = &H10
Public Const OFS_MAXPATHNAME = 128


'OFS_FILE_OPEN_FLAGS and OFS_FILE_SAVE_FLAGS below
'are mine to save long statements; they're not
'a standard Win32 type.
Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or
OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS
Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or
OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY


Public Type OPENFILENAME
    nStructSize As Long
    hwndOwner As Long
    hInstance As Long
    sFilter As String
    sCustomFilter As String
    nCustFilterSize As Long
    nFilterIndex As Long
    sFile As String
    nFileSize As Long
    sFileTitle As String
    nTitleSize As Long
    sInitDir As String
    sDlgTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExt As Integer
    sDefFileExt As String
    nCustDataSize As Long
    fnHook As Long
    sTemplateName As String
 End Type


Public OFN As OPENFILENAME


Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias
"GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias
"GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As
String, ByVal cchBuffer As Long) As Long


Public Function File_Dialog(ByVal File_Op As String, ByVal Multi_Select As
Boolean, ByVal FilterString As String, ByVal FilterExt As String, ByVal
TitleString As String) As String
  Dim r As Long
  Dim sp As Long
  Dim LongName As String
  Dim shortName As String
  Dim ShortSize As Long


 'to keep lines short(er), I've abbreviated a
 'Null$ to n and n2, and the filter$ to f.
  Dim n As String
  Dim n2 As String
  Dim f As String
  n = Chr$(0)
  n2 = n & n


 '------------------------------------------------
 'INITIALIZATION
 '------------------------------------------------
 'fill in the size of the OFN structure
  OFN.nStructSize = Len(OFN)


 'assign the owner of the dialog; this can
 'be null if no owner.
 'OFN.hwndOwner = Form1.hwnd


 '------------------------------------------------
 'FILTERS
 '------------------------------------------------


 'Using OFN.sFilter, fills
 'the combo with the specified filters, and works as
 'the VB common dialog does. These must be in the
 '"Friendly Name"-null$-Extension format,
 'terminating with 2 null strings.
  f = FilterString & n & FilterExt & n
  OFN.sFilter = f


 'nFilterIndex specifies an index into
 'the buffer pointed to by sFilter. The system uses the
 'index value to obtain a pair of strings to use as the
 'initial filter description and filter pattern for the
 'dialog box. The first pair of strings has an index value
 'of 1. When the user closes the dialog box, the system
 'copies the index of the selected filter strings
 'into this location.
  OFN.nFilterIndex = 2   '  "AutoCAD Drawings"


 '------------------------------------------------
 'FILENAME
 '------------------------------------------------
 'sFile points to a buffer that contains a filename used
 'to initialize the File Name edit control. The first
 'character of this buffer must be NULL if initialization
 'is not necessary. When the GetOpenFileName or GetSaveFileName
 'function returns, this buffer contains the drive designator,
 'path, filename, and extension of the selected file.


 'pass a default filename and initialize for
 'return value
 OFN.sFile = FilterExt & Space$(1024) & n


 OFN.nFileSize = Len(OFN.sFile)


 'default extension applied to a selected file if
 'it has no extension.
  OFN.sDefFileExt = FilterExt


 'sFileTitle points to a buffer that receives the
 'title of the selected file. The application should
 'use this string to display the file title. If this
 'member is NULL, the function does not copy the file
 'title.
  OFN.sFileTitle = Space$(512)
  OFN.nTitleSize = Len(OFN.sFileTitle)


 'sInitDir is the string that specifies the initial
 'file directory. If this member is NULL, the system
 'uses the current directory as the initial directory.
 'OFN.sInitDir = "d:\vb4\projects\misc\common dialogs"


 '------------------------------------------------
 'MISC
 '------------------------------------------------
 'sDlgTitle is the title to display in the dialog. If null
 'the default title for the dialog is used.
  OFN.sDlgTitle = TitleString


 'flags are the actions and options for the dialog.


  Select Case File_Op
     Case "Open"
        If Multi_Select = True Then
           OFN.flags = OFS_FILE_OPEN_FLAGS + OFN_ALLOWMULTISELECT
        Else
           OFN.flags = OFS_FILE_OPEN_FLAGS
        End If
        r = GetOpenFileName(OFN)
     Case "Save"
        If Multi_Select = True Then
           OFN.flags = OFS_FILE_SAVE_FLAGS + OFN_ALLOWMULTISELECT
        Else
           OFN.flags = OFS_FILE_SAVE_FLAGS
        End If
        r = GetSaveFileName(OFN)
  End Select


 'Finally, show the File Open Dialog


 '------------------------------------------------
 'RESULTS
 '------------------------------------------------
  If r Then


    'Path & File Returned (OFN.sFile):
     Dim FileString As String
     Dim I As Integer
     Do Until Right(FileString, 2) = Chr$(0) & " " Or Right(FileString, 2) =
Chr$(0) & Chr$(0)
        I = I + 1
        FileString = Left(OFN.sFile, I)
     Loop
     File_Dialog = Left(FileString, I - 2)


    'File Path (from OFN.nFileOffset):
    'Text2 = Left$(OFN.sFile, OFN.nFileOffset)


    'File Name (from OFN.nFileOffset):
    'Text3 = Mid$(OFN.sFile, OFN.nFileOffset + 1, Len(OFN.sFile) -
OFN.nFileOffset - 1)


    'Extension (from OFN.nFileExt):
    'Text4 = Mid$(OFN.sFile, OFN.nFileExt + 1, Len(OFN.sFile) -
OFN.nFileExt)


    'File Name (OFN.sFileTitle):
    'Text5 = OFN.sFileTitle


    'Short 8.3 File Name (using (OFN.sFileTitle):
    'LongName = OFN.sFileTitle
    'shortName = Space$(128)
    'ShortSize = Len(shortName)


    'sp = GetShortPathName(LongName, shortName, ShortSize)
    'Text6 = Left$(shortName, sp)


    'Short 8.3 File Name (using OFN.sFile):
    'LongName = OFN.sFile
    'shortName = Space$(128)
    'ShortSize = Len(shortName)


    'sp = GetShortPathName(LongName, shortName, ShortSize)
    'Text7 = Left$(shortName, sp)


    'User Requested this file be opened as Read Only:
    'chkReadOnly.Value = Abs((OFN.flags And OFN_READONLY) = OFN_READONLY)


  End If
End Function


then call using this code
    Dim FileName As String
    FileName = File_Dialog("Open", True, "AutoCAD Drawing (*.dwg)", "*.dwg",
"Open")

T.Willey

  • Needs a day job
  • Posts: 5251
Re: MS common dialog box in lisp
« Reply #22 on: January 19, 2006, 10:45:53 AM »
I found this:

<snip>

Thanks Luis.  I will digest this when I have some time.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.