User interface
The UI is the connection between the user and the computer
- Command line/console
- Text based
- Graphical User Interface (GUI)
- Visually oriented interface (WYSIWIG)
- User interacts with graphical objects
- More intuitive
- Other UIs: optical, speech-based, etc.
Gooey User Interaction
- Users interact with the GUI via messages
- When a GUI event occurs the OS sends a message to the program
- Programming the functions that respond to these messages is called event-driven programming
- Messages can be generated by user actions, other applications, and the OS
Console vs. event-driven programming
- GUI programs have a fundamentally different structure than console-based programs
- Console-based program:
```
- ask user for some input;
- do some processing;
- print some output;
- ask user for some more input;
- etc. ```
- The application programmer controls when input and output can happen
- GUI program model: the user is in control!
Event Driven Programming
- Structure GUI programs to respond to user events
- Events are: mouse clicks, mouse moves, keystrokes, etc.
- in MFC parlance, usually called messages
- Main control structure is an event loop:
while (1) { wait for next event dispatch event to correct GUI component }
-
this code is always the same, so it’s handled by MFC
- You just write the code to respond to the events.
- functions to do this are called message handlers in MFC
- GUI model is: user should be able to give any input at any time
- Non-Sequential!
What is API
- Program directly using the API (Application Programming Interface)
- An API is a library that provides the functions needed to create Windows and implement their functionality e.g buttons, scrollbars.
- Use libraries that encapsulate the API with better interfaces
- e.g., MFC, FCL, JFC, GTK, Tk (with TCL or Perl), Motif, OpenGL, QT, etc.
- Cross-platform: JFC, wxWindows, or Wind/U
What is MFC
- Microsoft Foundation Class, is a library that wraps portions of the Windows API in C++ classes, and thus allows a more object oriented way of interacting with the API.
- In an MFC program, direct Windows API calls are rarely needed.
- Instead, programs create objects from Microsoft Foundation Class classes and call member functions belonging to those objects.
Advantage of MFC
- Using an Object Oriented language means we can employ class reuse, templates, and polymorphism(adapting based on the data).
- MFC provides more in the framework than some other smaller GUI libraries.
- e.g. “empty” application, get a bunch of menus, and a toolbar MFC provides skeleton code for your application
- richer set of components: color-chooser dialog, file browser, and much more.
When a user drag a button and place it on the window form, the code will be generated for the user automatically.
The look and feel of the button, the coordinate will be created by the system. The only thing that user need to write is code of what should the button does!
// button1
//
this->button1->Location = System::Drawing::Point(191, 31);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"+";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);