Home > Software engineering >  Vb inside, if you don't use CommonDialog1 controls, how to open a file (to appear that choose t
Vb inside, if you don't use CommonDialog1 controls, how to open a file (to appear that choose t

Time:10-08

Vb inside, if you don't use CommonDialog1 controls, how to open a file (to appear that choose the file box)?

CodePudding user response:

You can use the API.

CodePudding user response:

 Option Explicit 

Private Const VER_PLATFORM_WIN32_NT=2
Private Type OSVERSIONINFO
DwOSVersionInfoSize As Long
DwMajorVersion As Long
DwMinorVersion As Long
DwBuildNumber As Long
DwPlatformId As Long
SzCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetFileNameFromBrowseW Lib "shell32" Alias "# 63" (ByVal hwndOwner As Long, ByVal lpstrFile As Long, ByVal nMaxFile As Long, ByVal lpstrInitialDir As Long, ByVal lpstrDefExt As Long, ByVal lpstrFilter As Long, ByVal lpstrTitle As Long) As Long
Private Declare Function GetFileNameFromBrowseA Lib "shell32" Alias "# 63" (ByVal hwndOwner As Long, ByVal lpstrFile As String, ByVal nMaxFile As Long, ByVal lpstrInitialDir As String, ByVal lpstrDefExt As String, ByVal lpstrFilter As String, ByVal lpstrTitle As String) As Long

Private Sub Command1_click ()
'KPD - Team 2001
'the URL: http://www.allapi.net/
'E - Mail: [email protected]
Dim sSave As String
SSave=Space (255)
'If we' r e on WinNT, call the unicode version of the function
If IsWinNT Then
GetFileNameFromBrowseW Me hWnd, StrPtr (sSave), 255, StrPtr (" c: \ "), StrPtr (" TXT "), StrPtr (" Text files (*.txt) "+ CRH $(0) +" *.txt "+ $(0) CRH +" All files (*. *) "+ CRH $(0) +" *. * "+ $(0)) CRH, StrPtr (" The Title")
'If we' r e not on WinNT, call the ANSI version of the function
The Else
GetFileNameFromBrowseA Me. HWnd sSave, 255, "c: ", "TXT", "Text files (*.txt)" + CRH $(0) + "*.txt" + $(0) CRH + "All files (*. *)" + CRH $(0) + "*. *" + CRH $(0), "The Title"
End the If
'Show the result
If the Trim (Replace (sSave, CRH (0), "")) & gt; "" Then MsgBox sSave
End Sub

The Public Function IsWinNT () As a Boolean
Dim myOS As OSVERSIONINFO
. MyOS dwOSVersionInfoSize=Len (myOS)
GetVersionEx myOS
IsWinNT=(myOS dwPlatformId=VER_PLATFORM_WIN32_NT)
End the Function
  • Related