How to fix the Unbound module Graphics in an ocaml project

This trick comes from a brand-new project I hosted at github : elecrud, more specifically the MainWindow::onFileOpen()
method you can find in the src/editor/MainWindow.cpp file.
The FXFileDialog class reference can be found online here for the 1.6 version of the fox toolkit library.
So, obviously, you could instantiate FXFileDialog but the simplest way to use it is to use Static Public Member Functions, for example getSaveFilename() or getOpenFilename() :
FXString filename = FXFileDialog::getOpenFilename(this, "Open a project...", "~"); // use filename here
The only limitation is that you must have a valid owner as first parameter. If you try nullptr
you may have a silly segmentation fault. The simplest solution is to call it from a class that inherits a Fox class, for example a MainWindow :
class MainWindow : public FXMainWindow { // Macro for class hierarchy declarations FXDECLARE(MainWindow) public: // MainWindow's constructor MainWindow(FXApp* a, const FX::FXString& windowTitle); // Messages for our class enum{ ID_CANVAS=FXMainWindow::ID_LAST, ID_CLEAR, ID_LAST, }; // Initialize virtual void create(); virtual ~MainWindow(); protected: MainWindow(); };
You will also need a valid application object :
int main(int argc,char *argv[]){ FXApp application("Scribble","FoxTest"); application.init(argc,argv); new MainWindow(&application); // Create the application's windows and run app application.create(); return application.run(); }
Even if the public static functions are easier to use for the most common cases, a subclass can offer more customisation. Choose your fate.
Comments
Post a Comment