FDOSTUI
FreeDOS Text User Interface
|
This section shows how to code a simple "Hello World" application. It will display a window with a clickable button. Clicking on the button will exit the application. In addition, the user can click on the system menu and click on close or press the ESCAPE key to exit.
For debugging data, add '-d3' on the command line.
The steps are as follows:
The first step is to initialize the FDOSTUI subsystem. This will change the display and register a mouse handler. When the application is finished running, it is important that the system is restored back to default settings.
Following the call to wm_init the code checks for an error. If an error has occurred, the library can not be used. In the example above an error message is displayed and control returned to the operating system.
The second step is to create the application window. A window is a container, which can hold other widgets. Following, it is registered to the window manager. The window manager will then take both ownership and control of the widget.
The window must not be deleted after it has been registered. To do that, unregister the window wm_unregister_window. Following, it is safe to be disposed of.
The third step is to create controls that are added to the widget. In this example, a button widget is created and added to the window. The button widget adds a signal that will be called when the user clicks on the button.
The signal sends a signal indicating that the window manager should exit. Internally, a flag is set and during the next ieteration of the run loop, the flag will be checked. If it is not zero, the window manager will cleanup and then exit.
The forth step is to draw (show) the widget to the screen. The run loop will not do this. Following, the run loop is called. At this point the application will spin in a loop collecting and dispatching events. However, it will capture the EScAPE key and exit the loop if it was pressed.
The fith and final step is critical. The initialization step had registered a mouse handler, which if not turned off will crash the system after the application exits. In addition, it may have altered the display. wm_deinit will restore the system back to default settings. After this point, the library is no longer in a usable state.