Using VB programming When using VB programming, we usually need to add a COMMONDIALOGUE control. Using this control, you can complete a number of functions such as "Open", "Save", "Color", "Print", but if a function is simple, use this control but also cause some unnecessary trouble. One is to install, and then add the volume of the published file package.
Here is how to display a "open" dialog box using the WINDOW API:
General.bas:
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long 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 StringEnd Type
Enter the following code in the Click event of the button calling the dialog:
Private sub fileopen_click () DIM OFN As OpenFileName Dim RTN As String
ofn.lStructSize = Len (ofn) ofn.hwndOwner = Me.hWnd ofn.hInstance = App.hInstance ofn.lpstrFilter = "all files" ofn.lpstrFile = Space (254) ofn.nMaxFile = 255 ofn.lpstrFileTitle = Space (254 ) OFN.NMAXFILETIL = 255 ofn.lpstrinitialdir = app.path off.lpstitle = "Open file" OFN.FLAGS = 6148
RTN = GetopenFileName (OFN)
IF RTN> = 1 Then msgbox ofn.lpstrfile else msgbox "Cancel Was Pressed" End IFEND SUB