Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

file browse button

way0endway0end Member Posts: 43
trying to set up a button so when you click on, it will open up the default file browser of windows, and when you point to a directory and subdirectory and click ok, it will fill in the an edit control with the selected directory path....

ok, maybe this is not clear so here is another example: when you click on file menu of this active internet explorer and select open, you get a box with a long white space for you to type the address of a file to open. but if you click on "browse..." button, you can just point to the file by the mouse to select it...


can someone guide me how to get this done using just windows functions not using MFC...

thanks a lot.

«1

Comments

  • pingpongpingpong Member Posts: 937
    Still not clear.

    Do you want to browse for a file or a folder? These are 2 different common dialogs in windows.

    In IE, when you click open/browse, you browse for files, not folders.

    Which one? I can give you an example for either.

  • way0endway0end Member Posts: 43
    i want to have char array to fill in the path of a directory, but not manually typing the path, rather to have the common windows browser fill it by the clicks of the mouse. in this case, i will look of the directory path... so if you could tell the directory one....


    thanks a lot.
  • pingpongpingpong Member Posts: 937
    Check out SHBrowseForFolder in MSDN.

    Or this link from groups.google.com

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=37CB6DB4.7FCCF6D3@ofek.org.il&rnum=4&prev=/groups?q=SHBrowseForFolder+&ie=UTF-8&oe=UTF-8&hl=en

    : i want to have char array to fill in the path of a directory, but not manually typing the path, rather to have the common windows browser fill it by the clicks of the mouse. in this case, i will look of the directory path... so if you could tell the directory one....
    :
    :
    : thanks a lot.
    :

  • way0endway0end Member Posts: 43
    [b][red]This message was edited by way0end at 2004-3-23 0:52:19[/red][/b][hr]
    thanks for the reply, and here is what i got...

    as soon as i inserted "BROWSEINFO bInfo" into my script, i got error (undecalred function first use), so i thought i would need to include some file, and searching around google got me to include "shlobj.h" which made my error count over 30, and latter found out by reading around that i need to include all of these [winnls.h, winnetwk.h, nspapi.h, winsock.h], now i left with nothing but waiting for reply...


    can i get a reply please....

    i am using dev c++ as a compiler...

    i get a flood of this compiler output:
    [code]
    In file included from C:DEV-C_~1Includeobjbase.h:49,
    from C:DEV-C_~1Includeole2.h:5,
    from C:DEV-C_~1Includeshlobj.h:8,

    C:DEV-C_~1Includeunknwn.h:23: `com_interface' only supported with -fvtable-thunks
    C:DEV-C_~1Includeunknwn.h:23: warning: `com_interface' attribute directive ignored
    [/code]


  • pingpongpingpong Member Posts: 937
    Well, I dont know about Dev C++, never used it before. In VC++, I include Windows.h followed by Shlobj.h and it works fine.

    Now, shlobj.h uses alot of COM interfaces, I dont know if this is going to work with Dev C++ or not. Can you verify that?

    : [b][red]This message was edited by way0end at 2004-3-23 0:52:19[/red][/b][hr]
    : thanks for the reply, and here is what i got...
    :
    : as soon as i inserted "BROWSEINFO bInfo" into my script, i got error (undecalred function first use), so i thought i would need to include some file, and searching around google got me to include "shlobj.h" which made my error count over 30, and latter found out by reading around that i need to include all of these [winnls.h, winnetwk.h, nspapi.h, winsock.h], now i left with nothing but waiting for reply...
    :
    :
    : can i get a reply please....
    :
    : i am using dev c++ as a compiler...
    :
    : i get a flood of this compiler output:
    : [code]
    : In file included from C:DEV-C_~1Includeobjbase.h:49,
    : from C:DEV-C_~1Includeole2.h:5,
    : from C:DEV-C_~1Includeshlobj.h:8,
    :
    : C:DEV-C_~1Includeunknwn.h:23: `com_interface' only supported with -fvtable-thunks
    : C:DEV-C_~1Includeunknwn.h:23: warning: `com_interface' attribute directive ignored
    : [/code]
    :
    :
    :

  • way0endway0end Member Posts: 43
    yes for this prog i'm working on, i installed msvc++ and it worked. i wish i could make it work with devc++ though. hopefully one day....


    now, after getting everything together, how come i only get the name of the folder that i select from the common directory dialog box. i am looking for something like "c:firstfoldersecondfolder" but reading the data on char path, which is declared as char path[MAX_PATH], i only get "secondfolder" ?


    can you please let me know????


    thanks so very much....


  • pingpongpingpong Member Posts: 937
    You need to convert the return value to a buffer, the display name is just that, the name of the folder, not the whole path. Since you dont care about that, use this code:
    [code]
    // get the IMalloc interface
    IMalloc* malloc;
    if(SUCCEEDED(SHGetMalloc(&malloc)))
    {
    // you dont care about the display name, so dont put anything there (NULL)
    BROWSEINFO bi;
    ZeroMemory(&bi, sizeof(BROWSEINFO));
    bi.hwndOwner = hWnd;
    bi.lpszTitle = TEXT("Select a folder");
    bi.ulFlags = BIF_EDITBOX; // or whatever flags you want, try different ones...
    LPITEMIDLIST idList = SHBrowseForFolder(&bi);
    if(idList != NULL)
    {
    // user selected something, convert to a normal buffer
    TCHAR buffer[_MAX_PATH];
    SHGetPathFromIDList(idList, buffer);

    // you need to free the id list with IMalloc
    malloc->Free(idList);

    MessageBox(hWnd, buffer, "Folder", 0);
    }

    // release the IMalloc interface
    malloc->Release();
    }
    [/code]
  • way0endway0end Member Posts: 43
    may God fullfil your needs like you did fullfil mine.


    thank you
  • pingpongpingpong Member Posts: 937
    No problem. Good luck with the rest of your project.

  • schumacher1011schumacher1011 Member Posts: 19
    : Still not clear.
    :
    : Do you want to browse for a file or a folder? These are 2 different common dialogs in windows.
    :
    : In IE, when you click open/browse, you browse for files, not folders.
    :
    : Which one? I can give you an example for either.
    :
    :

    [blue] i am working on a project that pops up a File browse window on click of a button. it wud be of great help if u could temme how this can be done

    thanx [/blue]
«1
Sign In or Register to comment.