Modal Common Dialog Boxes using Windows API Calls 
Author Message
 Modal Common Dialog Boxes using Windows API Calls

 I am using Windows API Calls to display Open and Save dialogs; however,
unlike with COMDLG32.OCX the dialogs are not modal, so they can get lost
behind the application.  Is there a way I can make them modal (a flag to
set or some such thing)?

VB Code follows:

Code Module:
--------------------
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias
"GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000            'Windows 95 Only
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000          'Windows 95 Only
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000 'Windows 95 Only
Public Const OFN_NOLONGNAMES = &H40000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHOWHELP = &H10

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

In a form:
-------------
    Dim OpenFile As OPENFILENAME
    Dim wSize As Long
    Dim memhandle As Long
    Dim hWnd As Long
    Dim szFile As String
    Dim szFilter As String
    Dim lngResult As Long
    szFile = String$(128, 0)
    szFilter = "Playlist Files (*.lst)" + vbNullChar + "*.lst" +
vbNullChar + vbNullChar + vbNullChar
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = hWnd
    OpenFile.flags = OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or
OFN_PATHMUSTEXIST
    OpenFile.nFilterIndex = 1
    OpenFile.nMaxFile = Len(szFile)
    OpenFile.lpstrInitialDir = strOpenSavePath
    OpenFile.lpstrFile = szFile
    OpenFile.lpstrFilter = szFilter
    OpenFile.lpstrTitle = "Open Playlist"
    lngResult = GetOpenFileName(OpenFile)

Any help appreciated.
Thanx.



Sat, 03 Jun 2000 03:00:00 GMT  
 Modal Common Dialog Boxes using Windows API Calls

James,

Quote:
>  I am using Windows API Calls to display Open and Save dialogs; however,
> unlike with COMDLG32.OCX the dialogs are not modal, so they can get lost
> behind the application.  Is there a way I can make them modal (a flag to
> set or some such thing)?

Try setting the hwndOwner member of OPENFILENAME to your form's hWnd.
If this value is not set, the desktop becomes the dialog's owner and the dialog
is created as a top-level window.

--
Brad Martinez
http://members.aol.com/btmtz/vb

Common Controls Replacement Project
http://www.zeode-sd.com/ccrp/



Sat, 03 Jun 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Using VBA to call API (common dialogs)

2. Centering a Open Dialog box using the Common dialog

3. Dialog Boxes - Application Modal vs. System Modal

4. API call to common dialogs

5. HELP: Common Dialog FindText and ReplaceText API Calls.

6. Common Dialog API calls

7. API Calls to Use Common Dialogs without COMDLG32.OCX

8. How to use API call instead of Common Dialog Control

9. Common dialog API calls

10. Hot to call default common dialog box?

11. common dialog box and windows 98

12. Common Dialog Box in Windows 95 - Error 380

 

 
Powered by phpBB® Forum Software