/* * Checkbox 2 * ---------- * This program creates a window, four checkboxes and a button. * * Unlike checkbox.c, this program makes the checkboxes global * variables, and uses ischecked to decide which ones have been * switched on by the user. * * Notice the checkboxes have no callbacks. The work is done * inside the button's call-back place_order, which also exits * the program using exitapp. */ #include checkbox ham, mushrooms, olives, capsicum; void place_order(button b) { printf("Toppings:\n"); if (ischecked(ham)) printf(" Ham\n"); if (ischecked(mushrooms)) printf(" Mushrooms\n"); if (ischecked(olives)) printf(" Olives\n"); if (ischecked(capsicum)) printf(" Capsicum\n"); exitapp(); } void main(void) { window w; rect r; w = newwindow("Pizza", rect(0,0,200,230), StandardWindow); r = rect(10,10,120,30); ham = newcheckbox("Ham", r, NULL); r.y += 35; mushrooms = newcheckbox("Mushrooms", r, NULL); r.y += 35; olives = newcheckbox("Olives", r, NULL); r.y += 35; capsicum = newcheckbox("Capsicum", r, NULL); r.y += 35; newbutton("Order Pizza", r, place_order); show(w); mainloop(); }