This example adds to XT Example 1 by adding a Mouse Pushbutton event handler.
Pressing on any mouse button will display a message on the xterm window where you invoked this program. Pressing the right mouse button (Button 3) will also exit the program.
New concepts include:
Create a file named "demo_xt2.cpp" with the contents shown in the
box (the changes from demo_xt1.cpp are highlighted):
#include <X11/IntrinsicP.h> // IntrinsicP.h has some faster macros than Intrinsic.h #include <X11/ShellP.h> // Needed for Widget class definitions #include <stdio.h> //fprintf, stderr #include < stdlib.h > // exit //------------------------------------------------ // This function is called by a ButtonPress event in the main widget // Button 1 is the left mouse button, Button 3 is the right button, // Button 2 is the middle button (or the left & right button pressed together) // Button 3 quits the program, Buttons 2 & 3 change the main widget's size void EvProc(Widget w, XtPointer client_data, XEvent *event, char* CTmp) { } //------------------------------------------------ void main (int argc, char **argv) { //--- Create and initialize the top-level widget //--- Make it the desired size //--- Realize the main widget //--- Add Mouse Button Event Handler //----- } |
Create a file named "Makefile" with the contents shown in the
box :
cc=g++ cflags=-I/usr/X11R6/include lflags=-L/usr/X11R6/lib # # Linking # demo_xt2: <tab> demo_xt2.o # # Compiling # demo_xt2.o: <tab> demo_xt2.cpp # # clean # clean: |