Task

Create a window that has:

   a label that says   "There have been no clicks yet" 
   a button that says   "click me"


Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.




include c:\cxpl\stdlib;         \standard library provides mouse routines, etc.
def Ww=40, Wh=12, Wx=(80-Ww)/2, Wy=(25-Wh)/2;           \window width, etc.
def Bw=11, Bh=4, Bx=Wx+(Ww-Bw)/2, By=Wy+3*(Wh-Bh)/4;    \button size & position
int Clicks, Mx, My;             \number of clicks and mouse coordinates
 
[ShowCursor(false);                             \turn off flashing cursor
Attrib($1F);                                    \bright white characters on blue
SetWind(Wx, Wy, Wx+Ww, Wy+Wh, 2, true);         \blue window with no scroll
DrawBox(Wx, Wy, Wx+Ww, Wy+Wh, 3);               \draw borders
Cursor(Wx+5, Wy+3);  Text(6, "There have been no clicks yet.");
DrawBox(Bx, By, Bx+Bw, By+Bh, 0);               \draw button
Cursor(Bx+2, By+2);  Text(6, "Click me");
 
OpenMouse;
ShowMouse(true);
Clicks:= 0;
repeat  if GetMouseButton(0) then               \left button down
                [while GetMouseButton(0) do []; \wait for release
                Mx:= GetMousePosition(0) / 8;   \character coordinates
                My:= GetMousePosition(1) / 8;
                if Mx>=Bx & Mx<=Bx+Bw & My>=By & My<=By+Bh then
                        [Clicks:= Clicks+1;     \mouse pointer is on the button
                        Cursor(Wx+4, Wy+3);
                        Text(6, "Times button has been clicked: ");
                        IntOut(6, Clicks);
                        ];
                ];
until   ChkKey;         \keystroke terminates program
SetVid(3);              \turn off mouse and turn on flashing cursor
]