• Home
  • Jukebox
  • MP3 Store
  • Works
  • Articoli
  • Downloads
  • Links
  • Suggest this site
  • I'd joined to...
FLTK 2 - Open and save files on Windows OS PDF
Written by Luigi Negretti Lanner   
Friday, 26 September 2008 22:49

Native Win code to open / save files on Win Os using FLTK / FLTK 2. I founded code to open files on Greg Ercolano's Home Page, colorated lines are that I added to load and save files effectively, on FLTK 2 standard text editor.

/*Open and load file*/

OPENFILENAME ofn;    // global
void Browse_CB(Widget*, void*) {
// OPEN WINDOWS FILE BROWSER
//     The following is WIN32-specific code, and therefore not pretty and 'non-fltk-ish' ;)
//
if ( ofn.lpstrFile       ) { delete [] ofn.lpstrFile; }
if ( ofn.lpstrInitialDir ) { delete [] ofn.lpstrInitialDir; }
memset((void*)&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.Flags       |= OFN_NOVALIDATE;          // prevent disabling of front slashes
ofn.Flags       |= OFN_HIDEREADONLY;        // hide readonly flag
ofn.Flags       |= OFN_EXPLORER;            // use 'newer' explorer windows
ofn.Flags       |= OFN_ENABLESIZING;        // allow window to be resized
ofn.Flags       |= OFN_NOCHANGEDIR;         // prevent dialog for messing up the cwd
ofn.lpstrFilter = "Lilypond Files (*.ly)\0*.ly\0All Files (*.*)\0*.*\0";
ofn.nMaxFile     = 4096-1;
ofn.lpstrFile    = new char[4096];
ofn.lpstrFile[0] = 0;
ofn.hwndOwner    = GetForegroundWindow();
ofn.lpstrTitle   = "Open Lilypond File";
const char *newfile = ofn.lpstrFile;
int err = GetOpenFileName(&ofn);
if ( err == 0 ) {
err = CommDlgExtendedError();           // extended error check
if ( err == 0 ) return;                 // user hit 'cancel'
fprintf(stderr, "CommDlgExtendedError() code=%d", err);
return;
}
//printf("User picked '%s'\n", ofn.lpstrFile);
load_file(newfile, -1);

}

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

/*Save fie*/

OPENFILENAME sfn;    // global
void save_as_win()
{
// OPEN WINDOWS FILE BROWSER
//     The following is WIN32-specific code, and therefore not pretty and 'non-fltk-ish' ;)
//
if ( sfn.lpstrFile       ) { delete [] sfn.lpstrFile; }
if ( sfn.lpstrInitialDir ) { delete [] sfn.lpstrInitialDir; }
memset((void*)&sfn, 0, sizeof(sfn));
sfn.lStructSize = sizeof(OPENFILENAME);
sfn.lpstrFilter = "Lilypond Files (*.ly)\0*.ly\0All Files (*.*)\0*.*\0";
sfn.nMaxFile     = 4096-1;
sfn.lpstrFile    = new char[4096];
sfn.lpstrFile[0] = 0;
sfn.hwndOwner    = GetForegroundWindow();
sfn.lpstrTitle   = "Open some file";
const char *newfile = sfn.lpstrFile;
int err = GetSaveFileName(&sfn);
if ( err == 0 ) {
err = CommDlgExtendedError();           // extended error check
if ( err == 0 ) return;                 // user hit 'cancel'
fprintf(stderr, "CommDlgExtendedError() code=%d", err);
return;
}
//printf("User picked '%s'\n", ofn.lpstrFile);
save_file(newfile);
}

 
Copyright © 2010 Luigi Negretti Lanner Home Page. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
Support by JoomlaPanel