Otk Tutorial 3 - Using the File Browser

This is the third of several tutorials showing how to use Otk to make graphical user interfaces (GUI's) for C applications. The example shows how to make a complete application consisting of a single button with a call-back to a routine that invokes the file selection frowser. The file-browser is a useful convenience widget within Otk. When you select a file, the call-back routine my_file_answer, is called, which prints the name of the selected file.

	#include "otk_lib/otk_lib.c"
	char directory[999]=".", wildcards[999]="", filename[999]="";

	void my_file_answer( char *filename )	/* Print name of selected file. */
	  printf("Browsing returned file-name: '%s'\n", filename ); 

	void browsetest()	/* Invoke the File Selection Browser. */
	 Otk_Browse_Files( "File to Open:", 999, directory, wildcards, filename, my_file_answer );

	main( int argc, char **argv )
	  OtkInitWindow( 620, 540, argc, argv );	/* Open a window. */
	  OtkMakeButton( OtkOuterWindow, 20.0, 40.0, 60.0, 20.0, "Select File(s)", browsetest, 0 );

To download this example, right-click: fbrowse.c.

To compile: cc -I/usr/X11R6/include -L/usr/X11R6/lib fbrowse.c -lGLU -lGL -lXmu -lXext -lX11 -lm -o fbrowse.exe

For information about the file browser widget, see: File Selection Browser Widget.

Return to Tutorials page.

Back to main page

SourceForge.net Logo