1. win32lib getOpenFileName


new topic     » topic index » view message » categorize

2. Re: win32lib getOpenFileName


new topic     » goto parent     » topic index » view message » categorize

3. Re: win32lib getOpenFileName

----- Original Message -----
>From: <aku at inbox.as>
>To: "EUforum" <EUforum at topica.com>
>Sent: Sunday, August 19, 2001 12:45 AM
>Subject: win32lib getOpenFileName
>
>How to make user can select multiple filenames in a dialog box like
>using getOpenFileName?

Hi Aku,
here is how you can do this.

First, find the routine called "buildDefaultOfn" in win32lib and change this
to a global function.

Then you need to use a new routine called "getFileNames". Below is the code
for this new routine plus an example of how to use it. Basically though,
this returns a sequence of names. If it returns a sequence of length 0, then
the user pressed the Cancel button, if it returns a sequence of length 1,
the user picked one file only - the sequence[1] returned is the full path
name to the file. If the length is 2 or more, then the first sequence is the
directory name, and sequence #2 onwards are the file names selected by the
user.

The parameters to this new routine are identical to the getOpenFilename
routine in win32lib.

-- getFileNames -----------------
global function getFileNames( integer id, sequence fName, sequence filters )

    atom ofn, strs, start
    integer instr

    -- build the structure
    ofn = buildDefaultOfn( id, fName, filters,
                    or_bits(OFN_FILEMUSTEXIST,OFN_ALLOWMULTISELECT))

    -- call the routine
    if w32Func(xGetOpenFileName, {ofn})
    then
        -- get the name
        strs = peek4u(ofn + ofnFile[1])
        instr = True
        fName = {}
        start = strs
        while instr do
            if peek(strs) then
                strs += 1
            else
                fName = append(fName, peek({start, (strs - start)}))
                start = strs + 1
                instr = peek(start)
                strs += 2
            end if
        end while

    else
        -- return blank
        fName = ""
    end if

    -- release the structure and strings
    release_mem( ofn )

    return fName

end function
--------------------

An example of its usage...
--------------------
include win32lib.ew
include getfilenames.ew

sequence thefiles
integer mywin, thelist, dirname

mywin   = create(Window,"Files", 0, 0, 0, 400, 0400, 00)
thelist = create(List, "", mywin, 5,35, 350, 300, 0)
dirname = create(LText,"", mywin, 5,5, 350, 20, 0)


thefiles = getFileNames(mywin, "",
            {"Backups","*.BAK", "All files", "*.*"})
if length(thefiles) != 0 then
    if length(thefiles) = 1 then
        setText(dirname, "")
    else
        setText(dirname, thefiles[1])
        thefiles = thefiles[2 .. length(thefiles)-1]
    end if
    addItem(thelist, thefiles)
else
    setText(dirname, "**No files selected**")
end if

WinMain(mywin,0)

------------------
hope this helps,
Derek.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu