乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 56|回复: 4

在当前文件夹中打开对话框窗口

[复制链接]

86

主题

744

帖子

6

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1092
发表于 2008-12-10 03:05:22 | 显示全部楼层 |阅读模式
嗨,我需要帮助。我有两个单选按钮,当我在指定的列表中按下其中一个按钮时,它会显示当前文件夹中的所有dwg。本人'我把它放在一个浏览按钮上,这样我可以打开一个窗口并更改当前文件夹,但我没有'我不知道如何更新单选按钮和打开对话框窗口的路径,使其位于同一文件夹中。有人能帮我吗
谢谢你

5baefwp5mn2.JPG

5baefwp5mn2.JPG

回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2008-12-10 08:22:50 | 显示全部楼层
听起来,文件夹路径需要一个全局变量 当您从一个按钮更改路径时,它将自动为另一个按钮更新。
回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2008-12-10 08:35:11 | 显示全部楼层
这取决于你如何打开浏览窗口。一些关于如何处理的代码将非常有用。要更新单选按钮,你所需要做的就是更改按钮的标题属性
你需要浏览按钮吗?如果没有,您可以简单地使用dir函数返回位于特定路径中的所有DWG文件,例如:
  1. PlotFile = Dir(Folder & "\*.dwg")
  2. While PlotFile  ""
  3. ListBox.AddItem PlotFile
  4. PlotFile = Dir
  5. Wend

回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2008-12-11 02:01:30 | 显示全部楼层

1。我有全局变量,但我没有'我不知道如何通过打开对话框窗口。为了打开对话框窗口,我使用了这个命令:ThisDrawing。SendCommand(“打开”vbCr)。这个命令是打开一个窗口,就像你想从菜单中打开的一样:文件-打开…
2。刷新单选按钮的部分完成了,也完成了它的列表'好的。我需要浏览按钮,这样我可以打开一个对话框窗口来更改文件夹,并添加或选择新的图形。现在对我来说,唯一的问题是打开当前文件夹中的对话框窗口。本人'我也试过这样做:
  1. Sub open_project_window()
  2. Dim RetVal
  3. Dim dwg_path As String
  4. Dim PathTokens As Variant
  5. Dim ProjectPath As String
  6. dwg_path = ThisDrawing.Path
  7. PathTokens = Split(dwg_path, "")
  8. ProjectPath = PathTokens(0) & "" & PathTokens(1) & "" & PathTokens(2) & "" & PathTokens(3)
  9. [color=red]RetVal = Shell("C:\Windows\Explorer.exe " & ProjectPath, 1) - I don't want to open an explorer window[/color]
  10. End Sub
此代码为'没关系,但我不知道;我不想打开浏览器窗口,有什么想法吗?
回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2008-12-11 13:20:37 | 显示全部楼层

糟糕的事实是,无论你使用Shell还是调用文件打开对话框,它都是浏览器
但是,无论如何,最快捷、最肮脏的方式是“使用”;ChDir;。我不知道您是如何生成对话框的,但有时在这些情况下设置当前的windows目录是可行的
或者,如果你想把它做好,把下面的代码放到它自己的(.bas)模块中
它包含;“文件打开”;和“;“保存文件”;对话框。它实际上并没有为您打开或保存文件,但它为用户提供了一个界面,并返回所选文件(如果用户取消,则返回一个空字符串)
我还添加了;SetCurrentDirectory;函数,该函数为对话框的启动窗口设定种子。此API版本比;ChDir“;VB的函数,因为它也适用于网络驱动器等。一些示例调用:
  1. Sub main()
  2.     Dim retFile As String
  3.    
  4.     ' set directory you want  dialog to start in as the \windows directory
  5.     SetCurrentDirectory "c:\windows"
  6.    
  7.    
  8.     ' call File Open Dialog
  9.     FileOpen Application.hWnd, MyFile$, "*.dwg", "Acad Drawings", "Select a  Drawing"
  10.     MsgBox "The File selected to open was " & MyFile$
  11.    
  12.     ' set directory you want  dialog to start in as the root dir
  13.     SetCurrentDirectory "c:"
  14.    
  15.     ' call file save dialog
  16.     SaveFile Application.hWnd, MyFile$, "*.txt", "Text Files", "Save a text file"
  17.     MsgBox "The File selected to save was " & MyFile$
  18. End Sub
&039;以及附带的代码模块:
  1. Option Explicit
  2. Public Const OFN_ALLOWMULTISELECT = &H200
  3. Public Const OFN_CREATEPROMPT = &H2000
  4. Public Const OFN_ENABLEHOOK = &H20
  5. Public Const OFN_ENABLETEMPLATE = &H40
  6. Public Const OFN_ENABLETEMPLATEHANDLE = &H80
  7. Public Const OFN_EXPLORER = &H80000
  8. Public Const OFN_EXTENSIONDIFFERENT = &H400
  9. Public Const OFN_FILEMUSTEXIST = &H1000
  10. Public Const OFN_HIDEREADONLY = &H4
  11. Public Const OFN_LONGNAMES = &H200000
  12. Public Const OFN_NOCHANGEDIR = &H8
  13. Public Const OFN_NODEREFERENCELINKS = &H100000
  14. Public Const OFN_NOLONGNAMES = &H40000
  15. Public Const OFN_NONETWORKBUTTON = &H20000
  16. Public Const OFN_NOREADONLYRETURN = &H8000
  17. Public Const OFN_NOTESTFILECREATE = &H10000
  18. Public Const OFN_NOVALIDATE = &H100
  19. Public Const OFN_OVERWRITEPROMPT = &H2
  20. Public Const OFN_PATHMUSTEXIST = &H800
  21. Public Const OFN_READONLY = &H1
  22. Public Const OFN_SHAREAWARE = &H4000
  23. Public Const OFN_SHAREFALLTHROUGH = 2
  24. Public Const OFN_SHAREWARN = 0
  25. Public Const OFN_SHARENOWARN = 1
  26. Public Const OFN_SHOWHELP = &H10
  27. Public Const OFS_MAXPATHNAME = 128
  28. Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS
  29. Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY
  30. Public Const OFS_MULTIFILE_OPEN_FLAGS = OFN_ALLOWMULTISELECT Or OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS
  31. Public Type OPENFILENAME
  32.     nStructSize As Long
  33.     hwndOwner As Long
  34.     hInstance As Long
  35.     sFilter As String
  36.     sCustomFilter As String
  37.     nCustFilterSize As Long
  38.     nFilterIndex As Long
  39.     sFile As String
  40.     nFileSize As Long
  41.     sFileTitle As String
  42.     nTitleSize As Long
  43.     sInitDir As String
  44.     sDlgTitle As String
  45.     flags As Long
  46.     nFileOffset As Integer
  47.     nFileExt As Integer
  48.     sDefFileExt As String
  49.     nCustDataSize As Long
  50.     fnHook As Long
  51.     sTemplateName As String
  52. End Type
  53. Public Llama As OPENFILENAME
  54. Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  55. Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
  56. Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  57. Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
  58. Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
  59. '  +--------------------------------------------------------------------+
  60. '  |             -= Main sub to call File SAVE Dialog =-                |
  61. '  |                                                                    |
  62. '  | Parameters: FileName$ is a variable that the name of the SAVED     |
  63. '  |            file name is returned in. You do NOT have to pass       |
  64. '  |            a filename to this routine, one is returned. Note       |
  65. '  |            that the Win API checks for, and prompts, if the        |
  66. '  |            filename already exists.                                |
  67. '  |                                                                    |
  68. '  |            FileExt$ is the file extension name you wish the        |
  69. '  |            Dialog box to use, for default extension, file          |
  70. '  |            listings, and availablity innthe drop-down "file        |
  71. '  |            type" box.                                              |
  72. '  |                                                                    |
  73. '  |            FileDesc$ is a descriptive name for the File Name       |
  74. '  |            Extension, used to describe the filetype in the drop    |
  75. '  |            down type box.                                          |
  76. '  |                                                                    |
  77. '  |            DlgTitle$ is the name of the caption on the Dialog      |
  78. '  |                                                                    |
  79. '  |                                                                    |
  80. '  +--------------------------------------------------------------------+
  81. Public Sub SaveFile(hWnd As Long, FileName$, FileExt$, FileDesc$, DlgTitle$)
  82.   Dim lngGo As Long
  83.   Dim lngHwnd As Long
  84.   Dim strCurName As String
  85.   Dim strNewName As String
  86.     On Error GoTo Err_Control
  87.     strCurName = FileName$
  88.     lngHwnd = hWnd
  89.     FileName$ = vbdShowSave(lngHwnd, strCurName, FileExt$, FileDesc$, DlgTitle$)
  90.     Exit Sub
  91. Err_Control:
  92.     'Just get out, to many things to account for
  93.     MsgBox Err.Description, vbCritical, "Too many errors, aborting"
  94. End Sub
  95. '  +--------------------------------------------------------------------+
  96. '  |             -= Main sub to call File OPEN Dialog =-                |
  97. '  |                                                                    |
  98. '  | Parameters: FileName$ is a variable that the name of the SAVED     |
  99. '  |            file name is returned in. You do NOT have to pass       |
  100. '  |            a filename to this routine, one is returned.            |
  101. '  |                                                                    |
  102. '  |            FileExt$ is the file extension name you wish the        |
  103. '  |            Dialog box to use, for default extension, file          |
  104. '  |            listings, and availablity innthe drop-down "file        |
  105. '  |            type" box.                                              |
  106. '  |                                                                    |
  107. '  |            FileDesc$ is a descriptive name for the File Name       |
  108. '  |            Extension, used to describe the filetype in the drop    |
  109. '  |            down type box.                                          |
  110. '  |                                                                    |
  111. '  |                                                                    |
  112. '  |            DlgTitle$ is the name of the caption on the Dialog      |
  113. '  |                                                                    |
  114. '  |                                                                    |
  115. '  +--------------------------------------------------------------------+
  116. Public Sub FileOpen(hWnd As Long, FileName$, FileExt$, FileDesc$, DlgTitle$)
  117.    
  118.     Dim lngGo As Long
  119.     Dim lngHwnd As Long
  120.     Dim strCurName As String
  121.     Dim strNewName As String
  122.     On Error GoTo Err_Control
  123.     strCurName = FileName$
  124.      lngHwnd = hWnd
  125.     strNewName = vbdShowOpen(lngHwnd, strCurName, FileExt$, FileDesc$, DlgTitle$)
  126.     FileName$ = strNewName
  127. Exit Sub
  128. Err_Control:
  129.     'Just get out, to many things to account for
  130.     MsgBox Err.Description, vbCritical, "Too many errors, aborting"
  131. End Sub
  132. '   +---------------------------------------------------------------+
  133. '   |   Interface from the "OpenFile" routine to the Windows API     |
  134. '   +---------------------------------------------------------------+
  135. Public Function vbdShowOpen(lngHwnd As Long, strDwgName As String, FileExt$, FileDesc$, DlgTitle$) As Variant
  136. Dim lngReturn As Long, ShortSize As Long
  137. Dim LongName As String, shortName As String, strFill As String
  138. Dim strDblSpace As String, strFilter As String
  139.     strFill = Chr(0): strDblSpace = strFill & strFill
  140.     Llama.nStructSize = Len(Llama)
  141.     Llama.hwndOwner = lngHwnd
  142.     'This section is for the filter drop down list
  143.       strFilter = FileDesc$ & strFill & FileExt$ & strFill
  144.       strFilter = strFilter & "All Files" & strFill & "*.*" & strDblSpace
  145.       Llama.sFilter = strFilter
  146.     'This is the default information for the dialog
  147.       Llama.sFile = strDwgName & Space$(1024) & strFill
  148.       Llama.nFileSize = Len(Llama.sFile)
  149.       Llama.sDefFileExt = FileExt$
  150.      
  151.       Llama.sFileTitle = Space(512)
  152.       Llama.nTitleSize = Len(Llama.sFileTitle)
  153.       Llama.sInitDir = CurDir
  154.       Llama.sDlgTitle = DlgTitle$
  155.      
  156.     ' use below to call open dialog
  157.       Llama.flags = OFS_FILE_OPEN_FLAGS
  158.       lngReturn = GetOpenFileName(Llama)
  159.    
  160.       If lngReturn Then
  161.          vbdShowOpen = Llama.sFile
  162.       End If
  163. End Function
  164. '   +---------------------------------------------------------------+
  165. '   |   Interface from the "SaveFile" routine to the Windows API     |
  166. '   +---------------------------------------------------------------+
  167. Public Function vbdShowSave(lngHwnd As Long, strDwgName As String, FileExt$, FileDesc$, Caption$) As String
  168.   Dim lngReturn As Long, ShortSize As Long
  169.   Dim LongName As String, shortName As String
  170.   Dim strFill As String, strDblSpace As String, strFilter As String
  171.   strFill = Chr(0): strDblSpace = strFill & strFill
  172.   Llama.nStructSize = Len(Llama)
  173.   Llama.hwndOwner = lngHwnd
  174.    
  175.   'This section is for the filter drop down list
  176.     strFilter = FileDesc$ & strFill & FileExt$ & strFill
  177.     strFilter = strFilter & "All Files" & strFill & "*.*" & strDblSpace
  178.     Llama.sFilter = strFilter
  179.   'This is the default information for the dialog
  180.     Llama.sFile = strDwgName & Space$(1024) & strFill
  181.     Llama.nFileSize = Len(Llama.sFile)
  182.     Llama.sDefFileExt = FileExt$
  183.      
  184.     Llama.sFileTitle = Space(512)
  185.     Llama.nTitleSize = Len(Llama.sFileTitle)
  186.     Llama.sInitDir = CurDir
  187.     Llama.sDlgTitle = Caption$
  188.      
  189.   ' use below to call save dialog
  190.     Llama.flags = OFS_FILE_SAVE_FLAGS
  191.     lngReturn = GetSaveFileName(Llama)
  192.    
  193.     If lngReturn Then
  194.       vbdShowSave = Llama.sFile
  195.     End If
  196. End Function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-4 17:15 , Processed in 0.370251 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表