Hi,

2008/10/13 Szabolcs Toth <toth / kw.gbm.ihost.com>:
> Hi, I have found this script but the filtering doesn't work. I can see
> all files instead I defined in the @ofn[:lpstrFilter]. Any idea what
> mistake I made?
> Thank you! Szabolcs
>
> require 'dl'
>
> $comdlg32 = DL.dlopen('comdlg32.dll')
>
> class TOpenFileDialog
>
>        OFN_READONLY                 = 0x00000001
>        OFN_OVERWRITEPROMPT          = 0x00000002
>        OFN_HIDEREADONLY             = 0x00000004
>        OFN_NOCHANGEDIR              = 0x00000008
>        OFN_SHOWHELP                 = 0x00000010
>        OFN_ENABLEHOOK               = 0x00000020
>        OFN_ENABLETEMPLATE           = 0x00000040
>        OFN_ENABLETEMPLATEHANDLE     = 0x00000080
>        OFN_NOVALIDATE               = 0x00000100
>        OFN_ALLOWMULTISELECT         = 0x00000200
>        OFN_EXTENSIONDIFFERENT       = 0x00000400
>        OFN_PATHMUSTEXIST            = 0x00000800
>        OFN_FILEMUSTEXIST            = 0x00001000
>        OFN_CREATEPROMPT             = 0x00002000
>        OFN_SHAREAWARE               = 0x00004000
>        OFN_NOREADONLYRETURN         = 0x00008000
>        OFN_NOTESTFILECREATE         = 0x00010000
>        OFN_NONETWORKBUTTON          = 0x00020000
>        OFN_NOLONGNAMES              = 0x00040000
>        OFN_EXPLORER                 = 0x00080000
>        OFN_NODEREFERENCELINKS       = 0x00100000
>        OFN_LONGNAMES                = 0x00200000
>        OFN_ENABLEINCLUDENOTIFY      = 0x00400000
>        OFN_ENABLESIZING             = 0x00800000
>        OFN_DONTADDTORECENT          = 0x02000000
>        OFN_FORCESHOWHIDDEN          = 0x10000000
>        OFN_EX_NOPLACESBAR           = 0x00000001
>
>        PROTOTYPE = 'LIISSLLSLSLSSLHHSIPS'
>        MAX_PATH = 260
>
>        def initialize
>
>                @ofn = DL.malloc(DL.sizeof(PROTOTYPE))
>                @ofn.struct!(PROTOTYPE,
>                        :lStructSize,
>                        :hwndOwner,
>                        :hInstance,
>                        :lpstrFilter,
>                        :lpstrCustomFilter,
>                        :nMaxCustFilter,
>                        :nFilterIndex,
>                        :lpstrFile,
>                        :nMaxFile,
>                        :lpstrFileTitle,
>                        :nMaxFileTitle,
>                        :lpstrInitialDir,
>                        :lpstrTitle,
>                        :Flags,
>                        :nFileOffset,
>                        :nFileExtension,
>                        :lpstrDefExt,
>                        :lCustData,
>                        :lpfnHook,
>                        :lpTemplateName
>                )
>                @ofn[:lStructSize]     = DL.sizeof(PROTOTYPE)
>                @ofn[:hwndOwner]       = 0
>                @ofn[:lpstrFile]       = DL.malloc(1024)
>                @ofn[:lpstrFile]       = "\0"
>                @ofn[:nMaxFile]        = MAX_PATH
>                @ofn[:lpstrFilter]     = "(*.rb)\0*.rb\0"
>                @ofn[:nFilterIndex]    = 1
>                @ofn[:lpstrFileTitle]  = "\0"
>                @ofn[:nMaxFileTitle]   = 0
>                @ofn[:lpstrInitialDir] = "\0"
>
>                @ofn[:Flags] = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST
>
>
>
>                @GetOpenFileName = $comdlg32['GetOpenFileName','IP']
>        end
>
>        def execute
>                @GetOpenFileName.call(@ofn)[0]
>        end
>
>        def filenames
>                @ofn[:lpstrFile].to_s
>        end
> end
>
> if __FILE__ == $0
>        dlg = TOpenFileDialog.new
>        if dlg.execute then
>                puts dlg.filenames
>        end
> end

Modify the line
        @ofn[:lpstrFilter]     = "(*.rb)\0*.rb\0"
to
        @ofn[:lpstrFilter]     = "(*.rb)\0*.rb\0".to_ptr


Regards,

Park Heesob