简单的问题请教高手

redwrite 2003-01-02 12:17:39
一. 我想做一个别存为的功能,就是可以把某个文件保存到用户指定目录,这样的窗体是自己做还是调用什么东东就行了?

二. 我想把程序重新动行一次,其功能就等于关闭程序然后再打开它,该怎么做呢
...全文
6 点赞 收藏 21
写回复
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2003-01-02
用shell
在程序中需要重新运行的地方加上shell 外壳(功能就是shell出应用程序),执行shell后,然后退出应用程序(用end)。
不过在应用程序之前加一个登录或者splash窗体,然后再加载应用程序
回复
redwrite 2003-01-02
第二个问题,用load_form不行呀,用为我用了ado对象,还有一些动态生成的控件,再运行一次的话就会出错说"对像已经被加载",我想作这样的功能,就是程序内容全部被卸载后再重新运行。
回复
holydiablo 2003-01-02
当然你如果非要用API也未必不可

Option Explicit

Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'ITEMIDLIST

Public Type BROWSEINFO 'bi
'lfont As String
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Type SHITEMID 'mkid
cb As Long 'Size of the ID (including cb itself)
abID As Byte 'The item ID (variable length)
End Type
Type ITEMIDLIST 'idl
mkid As SHITEMID
End Type
Public Const BIF_RETURNONLYFSDIRS = &H1

' Does not include network folders below the domain level in the tree view control.
' For starting the Find Computer
Public Const BIF_DONTGOBELOWDOMAIN = &H2

' Includes a status area in the dialog box. The callback function can set
' the status text by sending messages to the dialog box.
Public Const BIF_STATUSTEXT = &H4

' Only returns file system ancestors. If the user selects anything other
' than a file system ancestor, the OK button is grayed.
Public Const BIF_RETURNFSANCESTORS = &H8

' Only returns computers. If the user selects anything other
' than a computer, the OK button is grayed.
Public Const BIF_BROWSEFORCOMPUTER = &H1000

' Only returns (network) printers. If the user selects anything other
' than a printer, the OK button is grayed.
Public Const BIF_BROWSEFORPRINTER = &H2000

Public Const FO_MOVE As Long = &H1
Public Const FO_COPY As Long = &H2
Public Const FO_DELETE As Long = &H3
Public Const FO_RENAME As Long = &H4
Public Const FOF_MULTIDESTFILES As Long = &H1
Public Const FOF_CONFIRMMOUSE As Long = &H2
Public Const FOF_SILENT As Long = &H4
Public Const FOF_RENAMEONCOLLISION As Long = &H8
Public Const FOF_NOCONFIRMATION As Long = &H10
Public Const FOF_WANTMAPPINGHANDLE As Long = &H20
Public Const FOF_CREATEPROGRESSDLG As Long = &H0
Public Const FOF_ALLOWUNDO As Long = &H40
Public Const FOF_FILESONLY As Long = &H80
Public Const FOF_SIMPLEPROGRESS As Long = &H100
Public Const FOF_NOCONFIRMMKDIR As Long = &H200

Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Long
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type

Public Function SelectPath(ByVal Control As Form, ByVal Title As String) As String
Dim bi As BROWSEINFO
Dim idl As ITEMIDLIST
Dim rtn&, pidl&, Path$, pos%
Dim T
Dim SpecOut, SpecIn As String

bi.hOwner = Control.hwnd 'centres the dialog on the screen

bi.lpszTitle = Title '"Browsing is limited to: " & Option1(CurOptIdx%).Caption
' set the type of folder to return
' play with these option constants to see what can be returned
bi.ulFlags = BIF_RETURNONLYFSDIRS 'the type of folder(s) to return
pidl& = SHBrowseForFolder(bi) 'show the dialog box

Path = Space(512) 'sets the maximum characters
T = SHGetPathFromIDList(ByVal pidl&, ByVal Path) 'gets the selected path

pos% = InStr(Path$, Chr$(0)) 'extracts the path from the string
SpecIn = Left(Path$, pos - 1) 'sets the extracted path to SpecIn

If Right$(SpecIn, 1) = "\" Then 'makes sure that "\" is at the end of the path
SpecOut = SpecIn 'if so then, do nothing
Else 'otherwise
SpecOut = SpecIn + "\" 'add the "\" to the end of the path
End If

If SpecOut = "\" Then Exit Function
SelectPath = SpecOut


End Function
回复
bobob 2003-01-02
在“工程”-》“部件”里面找common dialog添加
然后用它的“saveas”
回复
日总是我哥 2003-01-02
'

中间插播广告:)哈哈哈

-----------------------------------------------------------------
欢迎访问:http://CoolSlob.fykj.com/
本站◆第一主打:《查询利器》,在这里你可以查询CSDN FAQ---目前唯一可查询的站点(CSDN自身也不支持)
  ◆第二主打:《CSDN精华贴》,在这里你可以看到网友们出奇的搞笑本领;可以看到网友们高深莫测的技术功底:)
  ◆第三主打:《下载专区》,在这里你可以下载到C++ Primer 3rd这样的经典书籍,可以下载到够Inside的《Insdie SQL Server7.0》,前些时候,我本人就是借助这本书来破解MS SQL Server数据库的.mdf和.ldf文件的:)
  ◆只要有大家的支持,网站有可能加入搜索“CSDN精华贴”功能!
回复
starbaby 2003-01-02
对啊,同意。。。。。
回复
OFFICE之门 2003-01-02
调用通用对话框
回复
litsnake1 2003-01-02
就是啊,用common dialog不就可以了吗?
回复
lxcc 2003-01-02
common dialog 控件
回复
redwrite 2003-01-02
在大家的帮助和zyl910(910:分儿,我来了!) 的指导下终于弄清楚了
结帐了,谢谢
回复
zyl910 2003-01-02
CommonDialog是用来取得文件名
取得目录用holydiablo(鱼头)贴的那个API
回复
zyl910 2003-01-02
打开工程
Ctrl+T
选择“MicroSoft Common Dialog Control 6.0”
回复
wuwenlin 2003-01-02
load form
回复
suntt 2003-01-02
1.调用通用对话框
2.重新调用form_load()
回复
redwrite 2003-01-02
"通用对话框"这个控件在哪里呀
回复
chenyu5188 2003-01-02
有现成的控件哈
调用通用对话框
回复
redwrite 2003-01-02
这个比较复杂,我研究一下看看

还有再想问一下common dialog这个控件被运行程序以后,点击确定产生什么样的事件呀(也就是说我该把代码写在哪里呢),再有,我想在打开的文件夹里只显示我想显示的文件类型(比如.mdb和.lbt...)我该怎么做呢?
回复
lxcc 2003-01-02
shell 程序:
Private Sub Form_Load()

Open App.Path & "\path.ini" For Input As #1
Input #1, strExecPathName
Close #1

Me.Hide
Dim i
i = Shell(strExecPathName, vbNormalFocus)
Unload Me
End
End Sub

path.ini的内容:

your_path\your_app_name.exe
回复
redwrite 2003-01-02
呵呵,我真的不知道,复杂吗,你知道哪里有详细的资料吗?
回复
lxcc 2003-01-02
?我想把程序重新动行一次,其功能就等于关闭程序然后再打开它,该怎么做呢

就是制作一个外部程序来加载应用程序(shell方法,不会不知道吧?)

在需要重新运行程序之前,在主程序里先shell出那个外部程序,然后退出主程序(end方法),在外部程序里(可以用延时)再加载应用程序,不就完成了重新启动一次了吗,一般软件升级的方法类似这样
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告