/* * Checkbox * -------- * This program creates a window, two checkboxes and a quit button. * * It uses the checkbox call-back function choose_topping to print * a message saying which checkbox has just been selected. * * The ischecked function tells you whether a checkbox is currently * checked. Notice that each call-back gets passed an object as a * parameter. This object is whichever object called that call-back. * In the case of the quit function this will be the quit button. * In the case of choose_topping this will be whichever checkbox the * user clicked on. */ #include void choose_topping(checkbox c) { if (ischecked(c)) printf("Oh, you want %s do you?\n", gettext(c)); else printf("Don't want %s now, I see.\n", gettext(c)); } void quit(button b) { exitapp(); } void main(void) { window w; checkbox c1, c2; button b; w = newwindow("Pizza", rect(0,0,200,150), StandardWindow); c1 = newcheckbox("Ham", rect(10,10,160,25), choose_topping); c2 = newcheckbox("Mushrooms", rect(10,40,160,25), choose_topping); b = newbutton("Quit", rect(10,80,80,30), quit); show(w); mainloop(); }