-
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
}
-
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.
-
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.
-
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.
-
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.
-
jinx, how would use that same function as you have done here, but instead of getting the filename, get the file's path?
-
Code:
CFileDialog txt(TRUE, NULL, NULL, "Text Files|*.txt|*.txt");
if(txt.GetPathName() = TRUE)
{
//Stuff Here//
}
anything else?
-
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
-
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.
-
what header do I need to use that, by the way?
-
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
-
would information on this be in the msdn library? If so, what would I look up to find it?
-
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?
-
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.
-
Don't forget to link to
Comdlg32.lib
and may have to InitCommonCtrlEx()