Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

PB/DLL, improved Open/Save dialogs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB/DLL, improved Open/Save dialogs

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Test of hooked Open/Save Common dialogs
    ' Centers dialog in App', increases File type combo list height and
    ' in Save Dlg Hook procedure, corrects stupid default renaming bug
    ' when save as other file type (like when .BAS becomes .BAS.INC, etc..)
    '
    ' To test, compile/run program, click on Save and select different
    ' file types from File type combo. The extension will be altered
    ' accordingly in the dialog's File name field..    [img]http://www.powerbasic.com/support/forums/smile.gif[/img]
    '
    ' NOTE: This is sample. If you change the Filter strings in initial
    ' call for the dialogs, remember to change the Select Case tables
    ' in connecting dlg- and hook'd procedures so they match.
    '
    ' Public Domain by Borje Hagsten, July 2001
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    $COMPILE EXE
    #INCLUDE "WIN32API.INC" 'Win API declarations, etc.
     
    %ID_OPEN     = 10
    %ID_SAVE     = 12
    %ID_EXIT     = 20
     
    DECLARE CALLBACK FUNCTION DlgMainProc
    DECLARE FUNCTION OpenDlgHookProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                                     BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    DECLARE FUNCTION SaveDlgHookProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                                     BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
     
    '--------------------------------------------------------------------
    'Following declarations have been lifted from COMMCTRL.INC and COMDLG32.INC,
    'generously provided to us by PowerBasic Inc.
    %CDN_FIRST          = (0???-601???) 'from COMMCTRL.INC 
    %CDN_LAST           = (0???-699???) 'from COMMCTRL.INC 
     
    %CDN_INITDONE       = ( %CDN_FIRST - 0000 )
    %CDN_SELCHANGE      = ( %CDN_FIRST - 0001 )
    %CDN_FOLDERCHANGE   = ( %CDN_FIRST - 0002 )
    %CDN_SHAREVIOLATION = ( %CDN_FIRST - 0003 )
    %CDN_HELP           = ( %CDN_FIRST - 0004 )
    %CDN_FILEOK         = ( %CDN_FIRST - 0005 )
    %CDN_TYPECHANGE     = ( %CDN_FIRST - 0006 )
     
    ' Filename common dialogs
    %OFN_READONLY             = &H00000001???
    %OFN_OVERWRITEPROMPT      = &H00000002???
    %OFN_HIDEREADONLY         = &H00000004???
    %OFN_NOCHANGEDIR          = &H00000008???
    %OFN_SHOWHELP             = &H00000010???
    %OFN_ENABLEHOOK           = &H00000020???
    %OFN_ENABLETEMPLATE       = &H00000040???
    %OFN_ENABLETEMPLATEHANDLE = &H00000080???
    %OFN_NOVALIDATE           = &H00000100???
    %OFN_ALLOWMULTISELECT     = &H00000200???
    %OFN_EXTENSIONDIFFERENT   = &H00000400???
    %OFN_PATHMUSTEXIST        = &H00000800???
    %OFN_FILEMUSTEXIST        = &H00001000???
    %OFN_CREATEPROMPT         = &H00002000???
    %OFN_SHAREAWARE           = &H00004000???
    %OFN_NOREADONLYRETURN     = &H00008000???
    %OFN_NOTESTFILECREATE     = &H00010000???
    %OFN_NONETWORKBUTTON      = &H00020000???
    %OFN_NOLONGNAMES          = &H00040000??? ' force no long names for 4.x modules
    %OFN_EXPLORER             = &H00080000??? ' new look commdlg
    %OFN_NODEREFERENCELINKS   = &H00100000???
    %OFN_LONGNAMES            = &H00200000??? ' force long names for 3.x modules
    %OFN_ENABLEINCLUDENOTIFY  = &H00400000???
    %OFN_ENABLESIZING         = &H00800000???
     
    ' Return values for the registered message sent to the hook function
    ' when a sharing violation occurs.  %OFN_SHAREFALLTHROUGH allows the
    ' filename to be accepted, %OFN_SHARENOWARN rejects the name but puts
    ' up no warning (returned when the app has already put up a warning
    ' message), and %OFN_SHAREWARN puts up the default warning message
    ' for sharing violations.
    '
    ' Note:  Undefined return values map to OFN_SHAREWARN, but are
    '        reserved for future use.
     
    %OFN_SHAREFALLTHROUGH     = 2
    %OFN_SHARENOWARN          = 1
    %OFN_SHAREWARN            = 0
     
    %FNERR_FILENAMECODES      = &H3000
    %FNERR_SUBCLASSFAILURE    = &H3001
    %FNERR_INVALIDFILENAME    = &H3002
    %FNERR_BUFFERTOOSMALL     = &H3003
     
    TYPE OPENFILENAME
        lStructSize       AS DWORD
        hWndOwner         AS DWORD
        hInstance         AS DWORD
        lpstrFilter       AS ASCIIZ PTR
        lpstrCustomFilter AS ASCIIZ PTR
        nMaxCustFilter    AS DWORD
        nFilterIndex      AS DWORD
        lpstrFile         AS ASCIIZ PTR
        nMaxFile          AS DWORD
        lpstrFileTitle    AS ASCIIZ PTR
        nMaxFileTitle     AS DWORD
        lpstrInitialDir   AS ASCIIZ PTR
        lpstrTitle        AS ASCIIZ PTR
        Flags             AS DWORD
        nFileOffset       AS WORD
        nFileExtension    AS WORD
        lpstrDefExt       AS ASCIIZ PTR
        lCustData         AS LONG
        lpfnHook          AS DWORD
        lpTemplateName    AS ASCIIZ PTR
    END TYPE
     
    TYPE OFNOTIFY
        hdr     AS NMHDR
        lpOFN   AS OPENFILENAME PTR
        pszFile AS ASCIIZ PTR
    END TYPE
     
    DECLARE FUNCTION GetOpenFileName LIB "COMDLG32.DLL" ALIAS "GetOpenFileNameA" _
                                    (lpofn AS OPENFILENAME) AS LONG
    DECLARE FUNCTION GetSaveFileName LIB "COMDLG32.DLL" ALIAS "GetSaveFileNameA" _
                                    (lpofn AS OPENFILENAME) AS LONG
    DECLARE FUNCTION GetFileTitle LIB "COMDLG32.DLL" ALIAS "GetFileTitleA" _
                                    (ASCIIZ, ASCIIZ, BYVAL INTEGER) AS INTEGER
     
    DECLARE FUNCTION OpenFileDialog (BYVAL hWnd AS LONG, _            ' parent window
                                     BYVAL Caption AS STRING, _       ' caption
                                     Filespec AS STRING, _            ' filename
                                     BYVAL InitialDir AS STRING, _    ' start directory
                                     BYVAL Filter AS STRING, _        ' filename filter
                                     BYVAL DefExtension AS STRING, _  ' default extension
                                     Flags AS DWORD ) AS LONG         ' flags
     
    DECLARE FUNCTION SaveFileDialog (BYVAL hWnd AS LONG, _         ' parent window
                                     BYVAL Caption AS STRING, _    ' caption
                                     Filespec AS STRING, _         ' filename
                                     BYVAL InitialDir AS STRING, _ ' start directory
                                     BYVAL Filter AS STRING, _     ' filename filter
                                     DefExtension AS STRING, _     ' default extension
                                     Flags AS DWORD ) AS LONG      ' flags
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create Dialog and controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
      DIALOG NEW 0, "Common Dialog test..",,, 136, 30, %WS_CAPTION OR %WS_SYSMENU TO hDlg
     
      CONTROL ADD BUTTON, hDlg,   %ID_OPEN, "Open..",     4, 4,  40,  14
      CONTROL ADD BUTTON, hDlg,   %ID_SAVE, "Save as..", 48, 4,  40,  14
      CONTROL ADD BUTTON, hDlg,   %ID_EXIT, "Exit",      92, 4,  40,  14
     
      DIALOG SHOW MODAL hDlg, CALL DlgMainProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Dialog Callback procedure
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgMainProc
      LOCAL lRes AS LONG, Style AS DWORD, _
            Filter AS STRING, f AS STRING, Path AS STRING, fType AS STRING
     
      SELECT CASE CBMSG
         CASE %WM_COMMAND
            SELECT CASE CBCTL                       'handle all controls here
               CASE %ID_OPEN                        'Show Open File dialog
                  f      = "*.BAS;*.INC"
                  Path   = CURDIR$
                  Filter =          "PB Files (*.BAS, *.INC)|*.BAS;*.INC|"
                  Filter = Filter & "Resource Files (*.RC)|*.RC|"
                  Filter = Filter & "Help files (*.HLP)|*.HLP|"
                  Filter = Filter & "Text Files (*.TXT)|*.TXT|"
                  Filter = Filter & "Word processing (*.RTF)|*.RTF|"
                  Filter = Filter & "All Files (*.*)|*.*"
                  fType  = "BAS"
                  Style  = %OFN_ENABLEHOOK OR %OFN_EXPLORER OR %OFN_FILEMUSTEXIST OR _
                           %OFN_HIDEREADONLY
     
                  IF OpenFileDialog(CBHNDL, "", f, Path, Filter, fType, Style) THEN
                     'here you can place code to open selected file
                      MSGBOX f, %MB_ICONINFORMATION, "Selected filename:"
                  END IF
     
               CASE %ID_SAVE                        'Show Save File dialog
                  f     = "Untitled.bas"
                  Path  = CURDIR$
                  'NOTE: In Save dialog, each file type must be separate item so hook'd
                  '      procedure can select correct format.
                  Filter =          "PB Code Files (*.BAS)|*.BAS|"
                  Filter = Filter & "PB Include Files (*.INC)|*.INC|"
                  Filter = Filter & "Resource Files (*.RC)|*.RC|"
                  Filter = Filter & "Text Files (*.TXT)|*.TXT|"
                  Filter = Filter & "All Files (*.*)|*.*"
                  fType  = UCASE$(MID$(f, INSTR(-1, f, ".") + 1 ))
                  Style  = %OFN_ENABLEHOOK OR %OFN_EXPLORER OR %OFN_FILEMUSTEXIST OR _
                            %OFN_HIDEREADONLY OR %OFN_OVERWRITEPROMPT
     
                  'Show Save dialog. If user selects Cancel in Save dialog, exit.
                  IF SaveFileDialog(CBHNDL, "", f, Path, Filter, fType, Style) THEN
                     'here you can place code to save selected file
                      MSGBOX f, %MB_ICONINFORMATION, "Selected filename:"
                  END IF
     
               CASE %ID_EXIT : DIALOG END CBHNDL    'close the program
            END SELECT
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Show Open File dialog
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION OpenFileDialog (BYVAL hWnd AS LONG, _            ' parent window
                             BYVAL Caption AS STRING, _       ' caption
                             Filespec AS STRING, _            ' filename
                             BYVAL InitialDir AS STRING, _    ' start directory
                             BYVAL Filter AS STRING, _        ' filename filter
                             BYVAL DefExtension AS STRING, _  ' default extension
                             Flags AS DWORD ) AS LONG         ' flags
     
      LOCAL Ofn         AS OPENFILENAME
      LOCAL zFile       AS ASCIIZ * %MAX_PATH
      LOCAL zFileTitle  AS ASCIIZ * %MAX_PATH
      LOCAL zFilter     AS ASCIIZ * %MAX_PATH
      LOCAL zInitialDir AS ASCIIZ * %MAX_PATH
      LOCAL zTitle      AS ASCIIZ * %MAX_PATH
      LOCAL zDefExt     AS ASCIIZ * %MAX_PATH
     
      REPLACE "|" WITH CHR$(0) IN Filter
     
      IF LEN(InitialDir) = 0 THEN InitialDir = CURDIR$
     
      zFilter     = Filter + CHR$(0)
      zInitialDir = InitialDir + CHR$(0)
      zFile       = Filespec + CHR$(0)
      zDefExt     = DefExtension + CHR$(0)
      zTitle      = Caption + CHR$(0)
     
      ofn.lStructSize       = SIZEOF(ofn)
      ofn.hWndOwner         = hWnd
      ofn.lpstrFilter       = VARPTR(zFilter)
      ofn.lpstrFile         = VARPTR(zFile)
      ofn.nMaxFile          = SIZEOF(zFile)
      ofn.lpstrFileTitle    = VARPTR(zFileTitle)
      ofn.nMaxFileTitle     = SIZEOF(zFileTitle)
      ofn.lpstrInitialDir   = VARPTR(zInitialDir)
      IF LEN(zTitle) THEN
          ofn.lpstrTitle    = VARPTR(zTitle)
      END IF
      ofn.Flags             = Flags
      ofn.lpfnHook          = CODEPTR(OpenDlgHookProc)
      ofn.lpstrDefExt       = VARPTR(zDefExt)
     
      'Note: following Select Case table must be adjusted to match used Filter string
      '     (also remeber to do the same in hook'd procedure..)
      SELECT CASE UCASE$(DefExtension)
         CASE "BAS"        : ofn.nFilterIndex = 1 'nFilterIndex decides Filytype combo's listitem
         CASE "INC"        : ofn.nFilterIndex = 1
         CASE "RC"         : ofn.nFilterIndex = 2
         CASE "HLP"        : ofn.nFilterIndex = 3
         CASE "TXT"        : ofn.nFilterIndex = 4
         CASE "RTF"        : ofn.nFilterIndex = 5
         CASE ELSE         : ofn.nFilterIndex = 6
      END SELECT
     
      FUNCTION = GetOpenFilename(ofn)
     
      Filespec = zFile
      Flags    = ofn.Flags
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Open File dialog hook procedure, for centering the dialog and
    ' increasing height of filetype combo (to avoid tiny scrollbuttons..)
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION OpenDlgHookProc( BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                               BYVAL wParam AS LONG, BYVAL lParam AS LONG ) EXPORT AS LONG
     
      LOCAL X AS LONG, Y AS LONG, hftCombo AS LONG, R AS RECT, ofnPtr AS OFNOTIFY PTR
     
      SELECT CASE wMsg
         CASE %WM_NOTIFY
            ofnPtr = lParam
            SELECT CASE @ofnPtr.hdr.Code
               CASE %CDN_INITDONE
                  'CENTER DIALOG IN PARENT
                  GetWindowRect GetParent(GetParent(hWnd)), R     'get parent's data - dialog is child of child..
                  X = R.nLeft + ((R.nRight   - R.nLeft) \ 2)      'calculate parent's width
                  Y = R.nTop  + ((R.nBottom  - R.nTop)  \ 2)      'calculate parent's height
     
                  GetWindowRect GetParent(hWnd), R                'get dialog's width and height
                  X = X - (( R.nRight   - R.nLeft ) \ 2)          
                  Y = Y - (( R.nBottom  - R.nTop  ) \ 2)
                  SetWindowPos GetParent(hWnd), %NULL, X, Y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER 'set centered pos
     
                  'INCREASE HEIGHT OF DROPPED LIST IN FILETYPE COMBO (AUTO-ADJUSTS TO ITEM COUNT)
                  hftCombo = GetDlgItem(GetParent(hWnd), %cmb1)    'handle, Filetype combo
                  IF hftCombo THEN                                 'if we get handle
                     GetClientRect hftCombo, R                     'get combo's width and set new height
                     SetWindowPos hftCombo, %NULL, 0, 0, R.nRight, 200, %SWP_NOMOVE OR %SWP_NOZORDER
                  END IF
                  FUNCTION = %TRUE : EXIT FUNCTION
     
            END SELECT
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Show Save File dialog
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION SaveFileDialog (BYVAL hWnd AS LONG, _         ' parent window
                             BYVAL Caption AS STRING, _    ' caption
                             Filespec AS STRING, _         ' filename
                             BYVAL InitialDir AS STRING, _ ' start directory
                             BYVAL Filter AS STRING, _     ' filename filter
                             DefExtension AS STRING, _     ' default extension
                             Flags AS DWORD ) AS LONG      ' flags
     
      LOCAL Ofn           AS OPENFILENAME
      LOCAL zFile         AS ASCIIZ * %MAX_PATH
      LOCAL zFileTitle    AS ASCIIZ * %MAX_PATH
      LOCAL zFilter       AS ASCIIZ * %MAX_PATH
      LOCAL zInitialDir   AS ASCIIZ * %MAX_PATH
      LOCAL zTitle        AS ASCIIZ * %MAX_PATH
      LOCAL zDefExt       AS ASCIIZ * %MAX_PATH
     
      REPLACE "|" WITH CHR$(0) IN Filter
     
      IF LEN(InitialDir) = 0 THEN InitialDir = CURDIR$
     
      zFilter     = Filter + CHR$(0)
      zInitialDir = InitialDir + CHR$(0)
      zFile       = Filespec + CHR$(0)
      zDefExt     = DefExtension + CHR$(0)
      zTitle      = Caption + CHR$(0)
     
      ofn.lStructSize       = SIZEOF(ofn)
      ofn.hWndOwner         = hWnd
      ofn.lpstrFilter       = VARPTR(zFilter)
      ofn.lpstrFile         = VARPTR(zFile)
      ofn.nMaxFile          = SIZEOF(zFile)
      ofn.lpstrFileTitle    = VARPTR(zFileTitle)
      ofn.nMaxFileTitle     = SIZEOF(zFileTitle)
      ofn.lpstrInitialDir   = VARPTR(zInitialDir)
      IF LEN(zTitle) THEN
          ofn.lpstrTitle    = VARPTR(zTitle)
      END IF
      ofn.Flags             = Flags
      ofn.lpfnHook          = CODEPTR(SaveDlgHookProc)
      ofn.lpstrDefExt       = VARPTR(zDefExt) '%NULL
     
      'Note: following Select Case table must be adjusted to match used Filter string
      '     (also remeber to do the same in hook'd procedure..)
      SELECT CASE UCASE$(DefExtension)
         CASE "BAS"        : ofn.nFilterIndex = 1 'nFilterIndex decides Filytype combo's listitem
         CASE "INC"        : ofn.nFilterIndex = 2
         CASE "RC"         : ofn.nFilterIndex = 3
         CASE "TXT"        : ofn.nFilterIndex = 4
         CASE ELSE         : ofn.nFilterIndex = 5 '*.*
      END SELECT
     
      FUNCTION = GetSaveFilename(ofn)
     
      Filespec = zFile
      Flags    = ofn.Flags
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Save File dialog hook procedure, for centering the dialog and
    ' increasing height of filetype combo (to avoid tiny scrollbuttons..)
    ' This one also corrects stupid mistakes made by default dialog, where
    ' extensions otherwise can end up being doubled, like .BAS.INC, etc.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION SaveDlgHookProc( BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                               BYVAL wParam AS LONG, BYVAL lParam AS LONG ) EXPORT AS LONG
     
      LOCAL X AS LONG, Y AS LONG, hftCombo AS LONG, R AS RECT, ofnPtr AS OFNOTIFY PTR
     
      SELECT CASE wMsg
         CASE %WM_NOTIFY
            ofnPtr = lParam
            SELECT CASE @ofnPtr.hdr.Code
               CASE %CDN_INITDONE
                  'CENTER DIALOG IN PARENT
                  GetWindowRect GetParent(GetParent(hWnd)), R     'get parent's data - dialog is child of child..
                  X = R.nLeft + ((R.nRight   - R.nLeft) \ 2)      'calculate parent's width
                  Y = R.nTop  + ((R.nBottom  - R.nTop)  \ 2)      'calculate parent's height
     
                  GetWindowRect GetParent(hWnd), R                'get dialog's width and height
                  X = X - (( R.nRight   - R.nLeft ) \ 2)          
                  Y = Y - (( R.nBottom  - R.nTop  ) \ 2)
                  SetWindowPos GetParent(hWnd), %NULL, X, Y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER 'set centered pos
     
                  'INCREASE HEIGHT OF DROPPED LIST IN FILE TYPE COMBO (AUTO-ADJUSTS TO ITEM COUNT)
                  hftCombo = GetDlgItem(GetParent(hWnd), %cmb1)    'handle, File type combo
                  IF hftCombo THEN                                 'if we get handle
                     GetClientRect hftCombo, R                     'get combo's width and set new height
                     SetWindowPos hftCombo, %NULL, 0, 0, R.nRight, 120, %SWP_NOMOVE OR %SWP_NOZORDER
                  END IF
                  FUNCTION = %TRUE : EXIT FUNCTION
     
               CASE %CDN_TYPECHANGE
                  LOCAL hftEdit AS LONG, lRes AS LONG, zTxt AS ASCIIZ * %MAX_PATH
     
                  'CORRECT STUPID DEFAULT BEHAVIOR WITH FILE TYPE EXTENSIONS..
                  IF @[email protected] < 5 THEN          'ignore last one, *.*
                     hftCombo = GetDlgItem(GetParent(hWnd), %cmb1) 'handle, File type combo
                     hftEdit  = GetDlgItem(GetParent(hWnd), %edt1) 'handle, File name text field
                     GetWindowText hftEdit, zTxt, %MAX_PATH        'get name in text field
                     IF LEN(zTxt) THEN
                        lRes = INSTR(-1, zTxt, ".")                   'look for prefix (file type part)
                        IF lRes THEN zTxt = LEFT$(zTxt, lRes - 1)     'if success, remove prefix
     
                        SELECT CASE @[email protected]       'compare selection against combo list
                           CASE 1    : zTxt = zTxt + ".bas"           'and add matching prefix
                           CASE 2    : zTxt = zTxt + ".inc"
                           CASE 3    : zTxt = zTxt + ".rc"
                           CASE 4    : zTxt = zTxt + ".txt"
                        END SELECT
                        SetWindowText hftEdit, zTxt                   'set corrected name to text field
                     END IF
                  END IF
     
            END SELECT
      END SELECT
    END FUNCTION
    ------------------
    Added check for LEN(zTxt) to SaveDlgHookProc.
    Sept 26, corrected OPENFILENAME structure according to latest COMDLG32.INC



    [This message has been edited by Borje Hagsten (edited September 26, 2001).]

  • #2
    Sorry for bringing this one to top again, but in case someone is using this code:
    have corrected the OPENFILENAME structure so it matches latest COMDLG32.INC


    ------------------

    Comment

    Working...
    X