1. RE: Common Dialogs

Cassidy,

The directory selection is actually a shell function, not a common 
dialog (I made the same assumption!).  Here's a partially working 
program to show how to make this happen.  There is a problem with it, 
however.  The memory for the calls to these routines should be allocated 
with shell functions, not typical memory routines (I think this is 
right, I seem to remember reading this in the SDK docs).  I was going to 
finish this to get it working but never got there.  Maybe someone else 
has done this?

HTH,

Jonas

------------------------------------------------
include win32lib.ew
with trace

atom binfo, result,memfolder
sequence folder

constant xSHBrowseForFolder = registerw32Function(shell32, 
"SHBrowseForFolder",
{C_POINTER}, C_POINTER)

constant xSHGetPathFromIDList = 
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULONG)


global constant
bfOwner = allot( Long ),
bfpidlRoot = allot( Long ),
bfDisplayName = allot( Lpsz ),
bfTitle = allot( Lpsz ),
bfFlags = allot( Long ),
bfFunction = allot( Long ),
bfParam = allot( Long ),
bfImage = allot( Long ),
SIZEOF_BROWSEINFO = allotted_size()

binfo = acquire_mem(0, SIZEOF_BROWSEINFO)

store( binfo, bfOwner, 0)
store( binfo, bfpidlRoot, NULL)
store( binfo, bfDisplayName, "")
store( binfo, bfTitle, "Select a Folder")
store( binfo, bfFlags, NULL)
store( binfo, bfFunction, NULL)
store( binfo, bfParam, NULL)
store( binfo, bfImage, NULL)

result = w32Func(xSHBrowseForFolder, {binfo})
memfolder= acquire_mem(0,repeat(1024,0))
if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
   --the string pointed to by folder now contains the path
   folder = peek_string(memfolder)
else
   folder = ""
end if
--release_mem(memfolder)
release_mem(binfo)

if message_box("Folder: " & folder, "Test", MB_OK) then end if
-----------------------------------------

Cassidy Napoli wrote:
> How would I get the win32 common dialog for directory selection?  It 
> appears as a treeview of directories that a user can choose from, and 
> returns the directory selected.

new topic     » topic index » view message » categorize

2. RE: Common Dialogs

Thanks, I found this from a message a "ak- at inbox.as" posted a few weeks 
ago.  He claims it works.  I'm going to attempt using it now.  I'll let 
you know how it goes after I'm sure it does/doesn't work.

Try this, append to end of win32lib.
This version doesn't crash on my machine, and cannot select
my computer or network neighborhood.
You can select the selected directory name.
If this is better you can include this to next release of
win32lib. but change the memory routines to win32lib's.
Example use: x = getFolder(Window1, "c:\\windows",
"Select folder")

----------------------------
constant xSHBrowseForFolder = 
registerw32Function(shell32,"SHBrowseForFolderA", {C_POINTER}, 
C_POINTER)

constant xSHGetPathFromIDList =
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULONG)


function callbackselect(atom hWnd, atom uMsg, atom lParam, atom lpData)
object x
        if uMsg = 1 then
                x = w32Func(xSendMessage, {hWnd, 1126, 1, lpData})
        end if
        return 0
end function

global function getFolder(atom id, sequence filename, sequence title)
object bi, pbi, ret, folder, pfolder
        if length(filename)=2 and filename[2]=':' then
                filename &= '\\'
        elsif filename[length(filename)] = '\\' then
                filename = filename[1..length(filename)-1]
        end if
        bi = {0,0,0,0,         -- hwndOwner = 1
              0,0,0,0,         -- pIDLRoot = 5
              0,0,0,0,         -- pszDisplayName = 9
              0,0,0,0,         -- lpszTitle = 13
              0,0,0,0,         -- ulFlags = 17
              0,0,0,0,         -- lpfnCallback = 21
              0,0,0,0,         -- lParam = 25
              0,0,0,0}         -- iImage = 29
        bi[1..4] = int_to_bytes(getHandle(id))
        bi[13..16] = int_to_bytes(allocate_string(title))
        bi[17..20] = int_to_bytes(1)
        bi[21..24] = 
int_to_bytes(call_back(routine_id("callbackselect")))
        bi[25..28] = int_to_bytes(allocate_string(filename))
        pbi = allocate(length(bi))
        poke(pbi, bi)
        ret = w32Func(xSHBrowseForFolder, {pbi})
        free(bytes_to_int(bi[13..16]))
        free(bytes_to_int(bi[21..24]))
        free(bytes_to_int(bi[25..28]))
        free(pbi)
        
        pfolder = allocate(256)
        if w32Func(xSHGetPathFromIDList,{ret,pfolder}) then
                folder = peek_string(pfolder)
        else
                folder = ""
        end if
        free(pfolder)
        return folder
end function 


Jonas  Temple wrote:
> Cassidy,
> 
> The directory selection is actually a shell function, not a common 
> dialog (I made the same assumption!).  Here's a partially working 
> program to show how to make this happen.  There is a problem with it, 
> however.  The memory for the calls to these routines should be allocated 
> 
> with shell functions, not typical memory routines (I think this is 
> right, I seem to remember reading this in the SDK docs).  I was going to 
> 
> finish this to get it working but never got there.  Maybe someone else 
> has done this?
> 
> HTH,
> 
> Jonas
> 
> 
> atom binfo, result,memfolder
> sequence folder
> 
> constant xSHBrowseForFolder = registerw32Function(shell32, 
> "SHBrowseForFolder",
> {C_POINTER}, C_POINTER)
> 
> constant xSHGetPathFromIDList = 
> registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULONG)
> 
> 
> global constant
> bfOwner = allot( Long ),
> bfpidlRoot = allot( Long ),
> bfDisplayName = allot( Lpsz ),
> bfTitle = allot( Lpsz ),
> bfFlags = allot( Long ),
> bfFunction = allot( Long ),
> bfParam = allot( Long ),
> bfImage = allot( Long ),
> SIZEOF_BROWSEINFO = allotted_size()
> 
> binfo = acquire_mem(0, SIZEOF_BROWSEINFO)
> 
> store( binfo, bfOwner, 0)
> store( binfo, bfpidlRoot, NULL)
> store( binfo, bfDisplayName, "")
> store( binfo, bfTitle, "Select a Folder")
> store( binfo, bfFlags, NULL)
> store( binfo, bfFunction, NULL)
> store( binfo, bfParam, NULL)
> store( binfo, bfImage, NULL)
> 
> result = w32Func(xSHBrowseForFolder, {binfo})
> memfolder= acquire_mem(0,repeat(1024,0))
> if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
>    --the string pointed to by folder now contains the path
>    folder = peek_string(memfolder)
> else
>    folder = ""
> end if
> --release_mem(memfolder)
> release_mem(binfo)
> 
> if message_box("Folder: " & folder, "Test", MB_OK) then end if
> -----------------------------------------
> 
> Cassidy Napoli wrote:
> > How would I get the win32 common dialog for directory selection?  It 
> > appears as a treeview of directories that a user can choose from, and 
> > returns the directory selected. 
> 
>

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

3. RE: Common Dialogs

The code ak- at inbox.as posted seems to work great! I wish I could find his/her name so I could thank them. If you're reading the list, well, thank you. -=Csasidy=- euman at bellsouth.net wrote: > And to think I've been doing it like this for sometime now..... > > Makes me want to revert back to win32lib > ,, > ,, > ,, > ,, > naw..hehe > > global function getDrives() > sequence drive,Drives,DrivesReady,info > atom bit > integer DriveLetter > > retv=c_func(hGetLogicalDrives,{}) > Drives={} > DrivesReady={} > bit=1 > for k=1 to 26 do > if and_bits(bit,retv) then > DriveLetter=k+64 > drive=DriveLetter&":\\" > Drives=append(Drives,drive) > end if > bit=bit*2 > end for > return Drives > end function > > global sequence drives > drives = getDrives() -- check for drives > > integer Serial, Dtype_str, Dtype > sequence Drive_ids Drive_ids = {} -- get volume name and serial # > sequence Drive_type Drive_type = {} -- type of drive > > for i = 1 to length(drives) do > > Dtype_str = allocate_string2(drives[i]) > Dtype = c_func(xGetDriveType, {Dtype_str}) > Drive_ids = append(Drive_ids, getVolSerial(drives[i])) > Drive_type = append(Drive_type, Dtype) > free(Dtype_str) > > end for > > atom TreeView1 > TreeView1 = 0 > > global function WndProc(atom hwnd, atom iMsg, atom wParam, atom lParam) > > if iMsg = WM_CREATE then > > TreeView1 = MakeTreeView(hwnd, "TreeView1", 175, 190, 175, 150) > > c_proc(ShowWindow,{TreeView1, 1}) > > for i = 1 to length(drives) do > > if length(Drive_ids[i][1]) > 0 then > iParent = allocate_string2(Drive_ids[i][1] & " " & drives[i]) > else > iParent = allocate_string2(drives[i]) > end if > > poke4( tvstruct + TVINSERTSTRUCTITEM_pszText,iParent) > poke4( tvstruct + TVINSERTSTRUCTITEM_iImage,Drive_type[i]-2) > poke4( tvstruct + > TVINSERTSTRUCTITEM_iSelectedImage,Drive_type[i]-2) > hParent = c_func(SendMessage,{TreeView1,TVM_INSERTITEM, 0, > tvstruct}) > free(iParent) > > end for > > elsif iMsg = WM_NOTIFY then > > id = peek4s(lParam + NMHDR_hwndFrom) > > elsif id = TreeView1 then > > iMsg = peek4s(lParam + NMHDR_code) > > if iMsg = TVN_SELCHANGED then --NM_CLICK then -- TreeView > > count = c_func(SendMessage,{id, TVM_GETCOUNT, 0, 0}) > > item = c_func(SendMessage,{id,TVM_GETNEXTITEM, 0, > TVGN_ROOT}) > poke4(tvitem + tvitem_hItem,item) > > poke4(tvitem + tvitem_mask,TVIF_TEXT) > poke4(tvitem + tvitem_stateMask, TVIS_SELECTED) > txtbuff = allocate(256) > poke4(tvitem + tvitem_pszText,txtbuff) > poke4(tvitem + tvitem_cchTextMax,256) > > junk = c_func(SendMessage,{id, TVM_GETITEM, 0, tvitem}) > > for i = 1 to count do > cmd = peek4s(tvitem + tvitem_state ) > if and_bits(cmd, TVIS_SELECTED) then > exit > end if <snip>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu