|
-
Nov 7th, 2008, 03:01 AM
#1
Thread Starter
Addicted Member
Use system open with dialogue box
Hi All,
Hope u all are in fine tune. Friends I am just trying to do some R & D with the system dialogue boxes. can anyone help me to know how I can use the system Open With Dialogue Box to open a file in the VB Exe.
For example:
Suppose I am having a form with a textbox or a RTFBox. Now I will click on a text file on the desktop and indicate it to open in my form using the system Open With Dialogue Box. Is this possible. If Yes the how I can do it. Please anyone give me some idea.
Thanx in advance
Arghya
-
Nov 7th, 2008, 03:39 AM
#2
Re: Use system open with dialogue box
Places this in a module
vb Code:
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public 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
Public Function SelectFileOpenDialog()
Dim strTemp, strTemp1, pathStr As String
Dim i, n, j As Long
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim Fname As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "Text Files (*.txt)" & Chr(0) & "*.TXT" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "C:\"
OpenFile.lpstrTitle = "Select File"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "You didn't select any file"
Else
Fname = Trim$(OpenFile.lpstrFileTitle) ' copy the filename to "Fname"
n = FileLen(OpenFile.lpstrFile) 'length of the file
End If
End Function
Place this in the command button click
vb Code:
Private Sub Command1_Click()
SelectFileOpenDialog
End Sub
Please amend the code as per your requirements...
Last edited by Siddharth Rout; Nov 7th, 2008 at 03:43 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Nov 7th, 2008, 06:37 AM
#3
Re: Use system open with dialogue box
to display the open with dialog is the default action for shellexecute if the file type is unregistered, to force the dialog to display you need to use shellexecuteex like this
vb Code:
Const SEE_MASK_INVOKEIDLIST = &HC Const SEE_MASK_NOCLOSEPROCESS = &H40 Const SEE_MASK_FLAG_NO_UI = &H400 Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As Long End Type Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long Sub openwith() Dim SEI As SHELLEXECUTEINFO Dim r As Long, filename As String filename = "c:\test\123.txt" With SEI 'Set the structure's size .cbSize = Len(SEI) 'Seet the mask .fMask = SEE_MASK_NOCLOSEPROCESS Or _ SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI 'Set the owner window .hwnd = 0 ' or someform.hwnd 'Show the properties .lpVerb = "openas" 'Set the filename .lpFile = filename .lpParameters = vbNullChar .lpDirectory = vbNullChar .nShow = 0 .hInstApp = 0 .lpIDList = 0 End With r = ShellExecuteEx(SEI) End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|