“Explorer ‘浏览文件夹'”

huangapple go评论46阅读模式
英文:

Explorer "Browse for Folder"

问题

我尝试创建一个脚本,需要用户选择项目的起始文件夹。我找到了几个资源,但它们使用的编程语言与我使用的不同。我使用的语言是Autolisp,很可能会调用shell应用程序来打开所需的GUI。

  • Java问题:https://stackoverflow.com/questions/4779360/browse-for-folder-dialog
  • MFC和Visual-C++问题:https://stackoverflow.com/questions/1304784/cfiledialog-browse-folders

此外,Lee Mac创建的代码接近要求,但它使用了一个对话框,如果提供了起始目录,将限制用户访问父目录:浏览文件夹

是否有一种方式可以打开如下所示的“选择文件夹”GUI,最好使用AutoLisp?

“Explorer ‘浏览文件夹'”

英文:

I'm trying to create a script that requires the user to select the starting folder for their project. I have found several sources, but the coding languages are not what I'm using. The language I'm using is Autolisp which will most likely be calling for the shell application to open the desired GUI.

In addition, there is the code created by Lee Mac which comes close, but it uses a dialog box that restricts the user from accessing parent directories if a starting directory is given: Browse for Folder

Is there a way to open the "Select Folder" GUI as shown below, preferably by using AutoLisp?

“Explorer ‘浏览文件夹'”

答案1

得分: 1

以下是翻译好的内容:

"我熟悉的另一种方法(除了使用Windows Shell对象的BrowseForFolder方法(如示例中所示))并且可以用于ActiveX的是利用MS Office文件对话框对象,例如:

;; 文件对话框  -  Lee Mac
;; 利用MS Office文件对话框对象向用户呈现对话框
;; msg - [str] 对话框标题(使用""作为默认值)
;; btn - [str] 按钮名称(使用""作为默认值)
;; ini - [str] 初始文件名/目录
;; typ - [int] MsoFileDialogType(1-4)
;; mtp - [bol] 允许多选(:vlax-true/:vlax-false)

(defun LM:filedialog ( msg btn ini typ mtp / dlg rtn xla )
    (if (setq xla (vlax-create-object "excel.application"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                    (function
                        (lambda ( / tmp )
                            (setq dlg (vlax-get-property xla 'filedialog typ))
                            (vlax-put-property dlg 'title msg)
                            (vlax-put-property dlg 'buttonname btn)
                            (vlax-put-property dlg 'initialfilename ini)
                            (vlax-put-property dlg 'allowmultiselect mtp)
                            (vlax-put-property xla 'visible :vlax-true)
                            (if (= -1 (vlax-invoke-method dlg 'show))
                                (vlax-for itm (vlax-get-property dlg 'selecteditems)
                                    (setq tmp (cons itm tmp))
                                )
                            )
                        )
                    )
                )
            )
            (if dlg (vlax-release-object dlg))
            (if xla (vlax-release-object xla))
            (if (vl-catch-all-error-p rtn)
                (prompt (vl-catch-all-error-message rtn))
                rtn
            )
        )
    )
)

示例

(LM:filedialog "选择文件夹" "选择文件夹" "" 4 :vlax-false)

然而,由于对话框是使用源自MS Office应用程序对象的方法调用的,因此需要实例化该应用程序对象,因此显然不是一种很干净的结果。"

英文:

The only other method with which I'm familiar (aside from utilising the BrowseForFolder method of the Windows Shell object - per this example) and which is exposed to ActiveX is to leverage the MS Office File Dialog object, e.g.:

;; File Dialog  -  Lee Mac
;; Leverages the MS Office File Dialog object to present a dialog to the user
;; msg - [str] Dialog title ("" for default)
;; btn - [str] Button name  ("" for default)
;; ini - [str] Initial filename/directory
;; typ - [int] MsoFileDialogType (1-4)
;; mtp - [bol] Allow multiple selection (:vlax-true/:vlax-false)

(defun LM:filedialog ( msg btn ini typ mtp / dlg rtn xla )
    (if (setq xla (vlax-create-object "excel.application"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                    (function
                        (lambda ( / tmp )
                            (setq dlg (vlax-get-property xla 'filedialog typ))
                            (vlax-put-property dlg 'title msg)
                            (vlax-put-property dlg 'buttonname btn)
                            (vlax-put-property dlg 'initialfilename ini)
                            (vlax-put-property dlg 'allowmultiselect mtp)
                            (vlax-put-property xla 'visible :vlax-true)
                            (if (= -1 (vlax-invoke-method dlg 'show))
                                (vlax-for itm (vlax-get-property dlg 'selecteditems)
                                    (setq tmp (cons itm tmp))
                                )
                            )
                        )
                    )
                )
            )
            (if dlg (vlax-release-object dlg))
            (if xla (vlax-release-object xla))
            (if (vl-catch-all-error-p rtn)
                (prompt (vl-catch-all-error-message rtn))
                rtn
            )
        )
    )
)

Example

(LM:filedialog "Select a Folder" "Select Folder" "" 4 :vlax-false)

However, since the dialog is invoked using a method derived from an MS Office Application object, this requires instantiating said application object and is therefore obviously not quite as clean an outcome.

huangapple
  • 本文由 发表于 2023年4月7日 00:52:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定