Announcement

Collapse
No announcement yet.

Directory list box??

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

  • Directory list box??

    Hi there. I'm using PBDLL/6.0 and was wondering if anyone has written a directory list box (similar to VB's) that I can use with "Control Add"?
    Thanks!
    Brad Stone
    The Salinon Corp

  • #2
    Here is probably the easiest way to get a directory listbox:

    - Jim


    %bif_returnonlyfsdirs=&h0001
    %bif_dontgobelowdomain=&h0002
    %bif_statustext=&h0004
    %bif_returnfsancestors=&h0008
    %bif_browseforcomputer=&h1000
    %bif_browseforprinter=&h2000

    type browseinfo
    hwndowner as long
    pidlroot as long
    pszdisplayname as asciiz ptr
    lpsztitle as asciiz ptr
    ulflags as long
    lpfncallback as long
    lparam as long
    iimage as long
    end type

    %bffm_initialized=1
    %bffm_selchanged=2
    %bffm_setstatustext=%wm_user+100
    %bffm_enableok=%wm_user+101
    %bffm_setselection=%wm_user+102

    declare function shbrowseforfolder lib "shell32.dll" alias "SHBrowseForFolderA" (browseinfo) as long
    declare function shgetpathfromidlist lib "shell32.dll" alias "SHGetPathFromIDListA" (byval long,byval long) as long

    function getdiskdir(byval hwnd&,byval title$,byval startdir$) as string

    local zbuffer as asciiz*%max_path
    local zstartdir as asciiz*%max_path
    local bi as browseinfo

    b$=rtrim$(startdir$,"\")
    ip$=right$(b$,1)
    if ip$=":" then b$=b$+"\"

    zstartdir=b$

    bi.hwndowner=hwnd&
    bi.lpsztitle=strptr(title$)
    bi.ulflags=%bif_returnonlyfsdirs or %bif_dontgobelowdomain or %bif_statustext
    bi.pidlroot=0
    bi.lpfncallback=codeptr(fbrowseproc)
    bi.lparam=varptr(zstartdir)

    lpidlist&=shbrowseforfolder(bi)

    if lpidlist& then
    shgetpathfromidlist lpidlist&,varptr(zbuffer)
    function=zbuffer
    else
    function=""
    end if

    end function

    function fbrowseproc(byval hwnd&,byval msg&,byval a&,byval startdir&) as long

    static zdir as asciiz*%max_path

    select case msg&
    case %bffm_initialized
    sendmessage hwnd&,%bffm_setselection,%true,startdir&
    case %bffm_selchanged

    if shgetpathfromidlist(a&,byval varptr(zdir)) then
    sendmessage hwnd&,%bffm_setstatustext,0,byval varptr(zdir)
    end if

    end select

    function=0
    end function


    -------------
    Jim Seekamp

    Jim Seekamp

    Comment


    • #3
      Hey thanks! Here are a couple of quick questions:
      1) Any sample code on how to use this...I'm a little confused on what to use for hwnd for getdiskdir.
      2) Where to add my code to update a seperate list box that I have for filenames?

      Thanks,
      Brad Stone

      Comment


      • #4
        hwnd is the handle of the parent window to the dialog.
        If you want a file-opening list use this:
        (It changes long file names to short, but you can remove that easily enough)


        function getfileopen(byval hwnd&,byval path$,byval namefile$,byval title$) export as string

        dim ofn as openfilename

        dim szfilter as asciiz*255
        dim szname as asciiz*255
        dim sztitle as asciiz*255
        dim szdefext as asciiz*255
        dim szinitialdir as asciiz*255

        szfilter="All Files (*.*)"+chr$(0)+"*.*"+chr$(0)
        szname=namefile$
        sztitle=title$
        szdefext="*.*"
        szinitialdir=path$

        ofn.lstructsize=len(ofn)
        ofn.hwndowner=hwnd&
        ofn.hinstance=hinstance&
        ofn.lpstrfilter=varptr(szfilter)
        ofn.lpstrcustomfilter=0&
        ofn.nmaxcustfilter=0
        ofn.nfilterindex=1
        ofn.lpstrfile=varptr(szname)
        ofn.nmaxfile=255
        ofn.lpstrfiletitle=0&
        ofn.nmaxfiletitle=255
        ofn.lpstrinitialdir=varptr(szinitialdir)
        ofn.lpstrtitle=varptr(sztitle)
        ofn.flags=%ofn_pathmustexist
        ofn.nfileoffset=0
        ofn.nfileextension=0&
        ofn.lpstrdefext=varptr(szdefext)
        ofn.lcustdata=0&
        ofn.lpfnhook=0&
        ofn.lptemplatename=0&

        namefile$=""

        if getopenfilename(ofn) then
        namefile$=szname
        if getshortpathname(szname,sztitle,255) then namefile$=sztitle
        end if

        function=namefile$
        end function


        -------------
        Jim Seekamp



        [This message has been edited by Jim Seekamp (edited January 20, 2000).]
        Jim Seekamp

        Comment


        • #5
          I guess I didn't make it too clear, but these are common windows dialogs that run by themselves;
          no additional code is needed; just change the parameters.

          In your winmain you could just have a line like this:

          namefile$=getdiskdir(hparent&,"Select A Folder","C:\windows")

          this example would start the window at c:\windows with the parent window hparent&


          - Jim


          -------------
          Jim Seekamp



          [This message has been edited by Jim Seekamp (edited January 20, 2000).]
          Jim Seekamp

          Comment


          • #6
            Thanks again Jim. I got them up and showing.

            But there is no way to have the lists as *part* of another window (i.e.
            dialog)? I was really hoping on having one window up with some graphics
            and having a directory list box (and maybe file list box) on that same
            window. Right now, the directory list box comes up as a stand alone
            window and then the file list box comes up as a stand alone window.

            Thanks again,
            Brad

            Comment


            • #7
              Here's a proc for selecting directory without the common dialogs shown above:


              dialogbox hdll&,"DISKDIR",0,codeptr(diskdirproc)

              function diskdirproc(byval hdiskdir&,byval msg&,byval a&,byval xparam&) as long

              select case msg&
              case %wm_initdialog

              centerwindow hdiskdir&

              static hdisk&,hdir&,hpath&
              static path$,title$,drv$

              ''path$= a global variable
              ''title$= a global variable

              settext hdiskdir&,title$

              hdisk&=getdlgitem(hdiskdir&,100)
              hdir&=getdlgitem(hdiskdir&,200)
              hpath&=getdlgitem(hdiskdir&,300)

              adddirlistbox hdisk&,"",%ddl_exclusive or %ddl_drives

              dilast%=totlineslistbox(hdisk&)
              chc%=0

              for x%=1 to dilast%
              b$=gettextlistbox(hdisk&,(x%-1))
              ip1$=lcase$(ltrim$(rtrim$(b$,"-]"),"[-"))
              ip2$=left$(path$,len(ip1$))

              if ip1$=ip2$ then
              drv$=ip1$+":"
              chc%=x%-1
              exit for
              end if

              next x%

              selectlistbox hdisk&,chc%

              gosub initdiskdir

              case %wm_command
              xparam2%=hiwrd(a&)

              select case lowrd(a&)
              case 100

              if xparam2%=%lbn_selchange then
              chc%=getcursellistbox(hdisk&)
              b$=gettextlistbox(hdisk&,chc%)
              drv$=ltrim$(rtrim$(b$,"-]"),"[-")+":"
              path$=drv$+"\"
              gosub initdiskdir
              end if

              case 200

              if xparam2%=%lbn_dblclk then
              chc%=getcursellistbox(hdir&)
              b$=gettextlistbox$(hdir&,chc%)

              if instr(b$,"..") then
              path$=rtrim$(path$,"\")

              do until right$(path$,1)="\"
              if path$="" then exit loop
              path$=left$(path$,len(path$)-1)
              loop

              else
              path$=path$+lcase$(ltrim$(rtrim$(b$,"]"),"["))+"\"
              end if

              gosub initdiskdir
              end if

              case 201,%idok
              path$=gettext(hpath&)

              ip1$=right$(path$,1)
              if ip1$<>"\" then path$=path$+"\"

              ''path$ = return global variable

              enddlg hdiskdir&,1
              function=1
              exit function
              case 202,%idcancel
              sparam1$=""
              sparam2$=title$
              enddlg hdiskdir&,0
              function=1
              exit function
              case 203 ''create directory
              b$=userinput("Enter Directory Name:","New Directory","")
              '''you can use inputbox (a std pb function)
              replace "/" with "" in b$
              replace "\" with "" in b$

              if instr(b$,".") then b$=left$(b$,instr(b$,".")-1)
              if b$="" then exit select

              newdir$=lcase$(trim$(b$))
              b$=gettext(hpath&)

              b$=rtrim$(b$,"\")+"\"

              newdir$=b$+newdir$
              mkdir newdir$
              gosub initdiskdir
              end select

              end select

              exit function

              initdiskdir:

              resetlistbox hdir&

              dim lppathspec as asciiz*255
              lppathspec=path$

              dlgdirlist hdiskdir&,lppathspec,200,300,%ddl_exclusive or %ddl_directory

              settext hpath&,path$

              lastentry%=totlineslistbox(hdir&)
              chc%=0

              for x%=1 to lastentry%
              b$=gettextlistbox(hdir&,(x%-1))
              ip1$=ltrim$(rtrim$(b$,"]"),"[")
              ip2$=right$(rtrim$(path$,"\"),len(ip1$))
              if ip1$=ip2$ then chc%=x%-1
              next x%

              selectlistbox hdir&,chc%

              return

              end function


              -------------
              Jim Seekamp

              Jim Seekamp

              Comment


              • #8
                And here is the .rc you could use with the above code:

                DISKDIR DIALOG LOADONCALL MOVEABLE 40, 50, 202, 90
                STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | DS_MODALFRAME | DS_LOCALEDIT
                BEGIN
                CONTROL "", 100, "LISTBOX", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_GROUP | WS_TABSTOP | LBS_DISABLENOSCROLL | LBS_NOTIFY, 4, 21, 30, 24
                CONTROL "", 200, "LISTBOX", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_GROUP | WS_TABSTOP | LBS_DISABLENOSCROLL | LBS_NOTIFY, 39, 21, 159, 64
                CONTROL "OK", 201, "BUTTON", WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON, 4, 54, 31, 15
                CONTROL "Cancel", 202, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 4, 70, 31, 15
                CONTROL "", 300, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 4, 4, 194, 12
                END

                -------------
                Jim Seekamp

                Jim Seekamp

                Comment


                • #9
                  As far as i know, this will return short filenames only.
                  Use filefindfirst.. etc..

                  Comment


                  • #10
                    Hey thanks again Jim. I'm not quite sure what the .rc is used for though.
                    By the way, in the latest code you provided I keep getting "Undefined
                    Sub/Function" errors for things like "centerwindow" and "settext"...any
                    suggestions?

                    Thanks for all your help!
                    Brad Stone

                    Comment


                    • #11
                      Check into the "helper" INC files in your PBDLL\WINAPI folder... you'll find all sorts of useful functions in the files.

                      -------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        The "centerwindow" function just centers the dialog; you can dump it or use your own routine.
                        The settext routine writes text to a control using setwindowtext API call.
                        The .rc file is the resource you can compile into a PBR file and call with your
                        dialogbox() function.

                        -------------
                        Jim Seekamp



                        [This message has been edited by Jim Seekamp (edited January 24, 2000).]
                        Jim Seekamp

                        Comment

                        Working...
                        X