| Header file: | folderselect.h |
| Object name: | fFOLDERSELECT |
| Object index: | 1 of 1 Object |
The fFOLDERSELECT creates and handles a nice little dialog with which you can select folders from. It's another Windows common dialog - with a few differences.
I'll say this right now: this object can be a pain to use. It's tangled up with some funny COM stuff, and you can't undo that - so when using this object, you have to have the COM headers included, and in the case of MinGW, you'll need to link libole32.a and compile with the command line option "-fvtable-thunks". If that wasn't enough complication, here's another one: when the dialog is being executed, it is best not to use any graphics functions. Why not? Everything becomes sluggish and then the graphics will be drawn with (0,0) being at the top right hand corner of the screen (instead of being at the top left hand corner of your window). Not pretty. I have written some methods to work around this if you have problems. If you don't have any problems, then that's great, and you're well on your way to a good application. Otherwise, please see the example code at the end of the documentation to see how to employ this workaround.
Please note that it is not possible to set where the folder browsing starts. Future consideration may correct this - and an understanding of what a 'Shell pID' is might help too...
| Prototype | Description |
| void SetBrowseForComputer(bool Set); | This function sets whether the dialog works by only looking for network computers. Pass TRUE to set the state where it only looks for computers, or FALSE otherwise. Initially this is at FALSE. |
| void SetBrowseForPrinter(bool Set); | This function sets whether the dialog works by only looking for printers attached to this or other computers. Pass TRUE to make it only show printers. Or FALSE if you don't want it to. Initially this is FALSE. |
| void SetBrowseForFile(bool Set); | This function sets whether or not you can look at folders that are part of the file system. You might want to turn this off if you only want to look for printers or computers. You can look for networked folders, but you can't select the computers from which they come from. Pass TRUE to make it so that you can look at these directories, or FALSE to set otherwise. This parameter is TRUE by default. |
| bool Execute(HWND Owner, char* Title); | This function actually shows the dialog for the user to select something. You can pass it an owner window, which the dialog becomes a child of. The other parameter is a title that goes at the top of the dialog. This function returns TRUE if you properly selected something and clicked OK, or returns FALSE if you clicked Cancel. |
| char* GetFolder(void); | This function returns the full path of the folder that you selected. If you selected a network folder, then the path will use the usual UNC (Universal Naming Convention - which would look like \\ComputerName\Folder\SubFolder). If you selected nothing, I think this should be NULL. |
| char* GetDisplayName(void); | This function returns the display name of the folder. Say that you selected the Desktop - the Folder might be C:\Windows\Desktop, but the 'Display Name' will be Desktop. |
The following snippet gives a basic idea of how to use this component.
//First, create the object...
fFOLDERSELECT Folder;
//Then, set any appropriate options...
...
//Now execute the dialog...
if (Folder.Execute(NULL, "Hello! Choose a file!"))
{
... = Folder.GetFolder();
} else {
//No file selected!!
}
//Wasn't that simple? Now, sometime it doesn't work
//well with repainted Windows, and then you'll need
//the workaround. It goes like follows...
//In your message queue...
... Message Queue ...
case WM_PAINT:
//Have this line first...
if (__FOLDERSELECT_IN_USE)
{
return DefWindowProc(hWnd, Message,
wParam, lParam);
}
//You might have to replace some variable names.
... Rest of usual WM_PAINT code ...
break;/return 0;/return Whatever;
... Rest of message queue ...
| Back to index | The FreeFoote Foundation Classes Documentation |