News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Some control reference needed

Started by vogelsang, June 17, 2014, 04:17:44 AM

Previous topic - Next topic

vogelsang

Hi assembly coders

I need a control or function to browse through folders. Which will return path of choosen folder.
Something similiar to GetOpenFileName. MSDN reference would be good.

Any ideas?
Thanks in advance.


vogelsang

Thanks dedndave. I need some time to read and try it. I'll be back with questions.

dedndave

SHBrowseForFolder is much simpler than GetOpenFilename   :biggrin:

there is also an example: \Masm32\Examples\exampl04\listview

vogelsang



push 0
call CoInitialize
     
        mov eax, hWnd
        mov bi.hwndOwner, eax
        mov bi.pidlRoot, NULL
        mov eax, OFFSET tSelectedDir
        mov bi.pszDisplayName, eax
        mov eax, OFFSET tFolderDialogTitle
        mov bi.lpszTitle, eax
        mov bi.ulFlags, BIF_EDITBOX
        mov bi.lpfn, NULL
        mov bi.lParam, NULL
        mov bi.iImage, NULL
       
        lea eax, bi
        push eax
        call SHBrowseForFolder


I'm not sure do i've written code correctly. But it seems to work.
It returns selected folder name. But i need full path. I guess that getting
full path has something to do with BROWSEINFO.pidlRoot and returned value by
SHBrowseForFolder.Am i right??? It's to complex stuff for me.

I should always call CoInitalize before i'm using SHBrowseForFolder?

Quote
SHBrowseForFolder is much simpler than GetOpenFilename   :biggrin:

there is also an example: \Masm32\Examples\exampl04\listview

I'll also take a look at it latter. Almost sleeping now :icon_confused:

dedndave

SHBrowseForFolder will return a non-zero pointer, if successful
it is a pointer to an ID list (pidl)
you can pass that pointer to SHGetPathFromIDList to get a full path

also, you may prefer to use OleInitialize instead of CoInitialize because you can use drag-n-drop
generally, when i initialze COM, i do it once at startup, and leave it initialized until exit

a couple other links i should have provided, earlier
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762194%28v=vs.85%29.aspx

be specific with the BROWSEINFO ulFlags member values   :P

dedndave

#6
oddly enough, the SHBrowseForFolder documentation does not mention this
but it is mentioned on this page (last sentance)

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776914%28v=vs.85%29.aspx

QuoteIt is the responsibility of the calling application to free the IDList
returned by SHBrowseForFolder using CoTaskMemFree.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms680722%28v=vs.85%29.aspx

so, when you are done with the pidl....
    INVOKE  CoTaskMemFree,pidl

your code might look something like this (assuming you have initialized COM)
    INVOKE  SHBrowseForFolder,addr bi   ;BROWSEINFO structure address
    .if eax
        lea     edx,buffer  ;MAXPATH sized buffer address
        push    eax
        INVOKE  SHGetPathFromIDList,eax,edx
        pop     eax
        INVOKE  CoTaskMemFree,eax
    .else
        mov byte ptr buffer,0
    .endif

dedndave

the pidlRoot member is used to tell it where to start browsing
many applications i have seen use NULL, and browsing starts at the Desktop folder
actually, i find that a little annoying, too
i would often prefer they started at the last folder i browsed for   :biggrin:
as you can see, that would require some pidl management
to save the pidl returned rather than releasing it - and make sure the last one is released at exit

jj2007

Quote from: dedndave on June 17, 2014, 09:06:57 AM
many applications i have seen use NULL, and browsing starts at the Desktop folder
actually, i find that a little annoying, too

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Inkey "Selected: ", FolderOpen$("Pick a folder:","AppTitle", "\Masm32\Examples")
  Exit
end start


Looks simple but there is some sophisticated code under the hood to overcome a Windows bug.

dedndave

in the SHBrowseForFolder documentation:

QuoteFor Windows Vista or later, it is recommended that you use IFileDialog with the FOS_PICKFOLDERS option rather than the SHBrowseForFolder function. This uses the Open Files dialog in pick folders mode and is the preferred implementation.

i wonder if that's what they are calling a "bug fix"   :lol:

i suspect there will be a hotfix for that, at some point

vogelsang

I'll try examples and follow the links.
Thanks for help guys.