Browse Button

This is a discussion on Browse Button within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am making a Browse Button in an Win 32 API using MSV++. I've got the button made, but ...

  1. #1
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47

    Browse Button

    Hi, I am making a Browse Button in an Win 32 API using MSV++. I've got the button made, but I was wondering if anyone knew the code for it.
    Thanks


    // BlastIt message handlers //My dialog box name

    void BlastIt::OnBrowse()
    {
    // TODO: Add your control notification handler code here

    }

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You look like you are using MFC, so I don't know for sure how you would use it, but I'm guessing you are browsing for a filename, in which case the common dialog GetOpenFileName() API routine is your baby.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    If you are coding your own browse button you are just reinventing the wheel. Using one of the common dialog boxes would be much better. Then it would just be a matter of retrieving the information from the dialog box via a structure and you could open the correct file based on what was in the structure.

    You would probably want to use the GetOpenFileName() common dialog box. There is not a browse button per se, but it allows the user to browse via a file list box, drive list box, a directory list box, and a single line edit control. You can also specify a default extension to look for.

    For info on how to use it check your SDK or check on Microsoft's web site.

    You could also just call the common dialog box function when the user presses the browse button and change the title structure member to 'Browse' - if you really feel you have to have a browse button. Also do Start->Run->Browse for an example of what controls you would need to create your own browse dialog if you must absolutely create your own.

  4. #4
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    CFileDialog txt(NULL, TRUE, "Text Files|*.txt|*.txt|");
    if(txt.GetFileName() = TRUE)
    {
    //Stuff Here//
    }


    This is the basic structure of the browsing function, although i don't think it will work like this b/c i feel something is missing, let some one else smarter elaborate on it for you.
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I'm sure that function is just using the common dialog boxes. If that is from MFC all they are doing is encapsulating the dialog box functions to make them easier to use. If not then they have created a specific window and class for this task.


    OWL just encapsulates all of the common dialog box functions and you call them - but it is just as easy to use the API to do this.

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    jinx, how would use that same function as you have done here, but instead of getting the filename, get the file's path?

  7. #7
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    Code:
    CFileDialog txt(TRUE, NULL, NULL, "Text Files|*.txt|*.txt");
    if(txt.GetPathName() = TRUE) 
    { 
    
    //Stuff Here// 
    
    }
    anything else?
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  8. #8
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    so would the following work?
    Code:
    CFileDialog wav(TRUE, NULL, NULL, "Wav Files|*.wav|*.wav");
    if(wav.GetPathName() = TRUE) 
    { 
    
    char wav_path[] = wav.GetPathName();
    
    }
    Thanks

  9. #9
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    I Believe that it would, however I don't remember off the top of my head if the char some_wav[] has to have a value between its "[]"s or if that is dos coding. Heck, try it. The rest looks good.

  10. #10
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    what header do I need to use that, by the way?

  11. #11
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    how would I use that code so that it comes up asking me to open a file (only allowing text files or whatever) then get the url and filename of that file then saving it again with a save as dialog box(just put comments where things like file output etc. go).

    Thanks heaps

  12. #12
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    would information on this be in the msdn library? If so, what would I look up to find it?

  13. #13
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    ok...I found out how to do this. I need to fill out this thing (does it go in a header?) and then call GetOpenFileName, but there's a whole lot of stuff that I don't understand, so can anybody help me with the below structure...
    Code:
    typedef struct tagOFN { 
      DWORD         lStructSize; 
      HWND          hwndOwner; 
      HINSTANCE     hInstance; 
      LPCTSTR       lpstrFilter; 
      LPTSTR        lpstrCustomFilter; 
      DWORD         nMaxCustFilter; 
      DWORD         nFilterIndex; 
      LPTSTR        lpstrFile; 
      DWORD         nMaxFile; 
      LPTSTR        lpstrFileTitle; 
      DWORD         nMaxFileTitle; 
      LPCTSTR       lpstrInitialDir; 
      LPCTSTR       lpstrTitle; 
      DWORD         Flags; 
      WORD          nFileOffset; 
      WORD          nFileExtension; 
      LPCTSTR       lpstrDefExt; 
      LPARAM        lCustData; 
      LPOFNHOOKPROC lpfnHook; 
      LPCTSTR       lpTemplateName; 
    #if (_WIN32_WINNT >= 0x0500)
      void *        pvReserved;
      DWORD         dwReserved;
      DWORD         FlagsEx;
    #endif // (_WIN32_WINNT >= 0x0500)
    } OPENFILENAME, *LPOPENFILENAME;
    It looks really confusing but it looks like it would go in a header, then the function is called in the cpp file. Is this correct? In that case, could it be used over and over again, just changing 1 or 2 things like the handle, the flags or whatever?

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    1
    I've used some of that function in a program. Some of it I still don't understand how to make it work. Example:

    void CDialogsDlg::OnBfileopen()
    {
    // TODO: Add your control notification handler code here
    CFileDialog ldFile(TRUE);
    //THE FILTER ISN'T WORKING YET. DON'T KNOW WHY 2/23/02
    ldFile.m_ofn.lpstrFilter = "Text Files (*.txt)","*.doc||";
    ldFile.m_ofn.lpstrTitle = "My File Open Dialog Title";
    ldFile.m_ofn.lpstrInitialDir = "D:\\My Documents\\";

    //show the File Open dialog and capture the result
    if (ldFile.DoModal() == IDOK)
    {
    //get the file name selected
    m_strResults = ldFile.GetFileName();

    //update the dialog
    UpdateData(FALSE);
    }
    }

    The dialog box title and initial directory code works.
    If anybody has any ideas about the file filter, I'd appreciate it. BTW, this code is in the dialog cpp file.

  15. #15
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Don't forget to link to

    Comdlg32.lib

    and may have to InitCommonCtrlEx()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 09:30 PM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  3. browse button and stuff
    By viaxd in forum Windows Programming
    Replies: 10
    Last Post: 12-19-2005, 06:35 PM
  4. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 12:32 PM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21