>_< "As mentioned in the previous section, although the created windows are visible, they appear as" null. This is because the function of the dialog box does not contain code to initialize a single element. The initial values of gadgets, actions caused by them, and interactions between them must be defined in the dialog box. Here, we initialize the small window in the wm_init_dialog message of the process function, and then implement the response to the gadgets in the wm_policy_parent message ~
1 /************************************** * gui_execdialogbox ()) or non-blocking (using gui_createdialogbox () 4. You must first define a resource table to specify all gadgets to be included in the dialog box. The following example illustrates how to create a resource table by using the <widget> _ createindirect () function to create a resource table. 7 */8 Static const gui_widget_create_info _ adialogcreate [] = {9 {framewin_createindirect, "dialog", 0, 10, 10,180,230, framewin_cf_moveable, 0}, 10 {button_createindirect, "OK ", gui_id_ OK, 100, 5, 60, 20}, 11 {button_createindirect, "cancel", gui_id_cancel, 100, 30, 60, 20}, 12 {text_createindirect, "ltext", 0, 10, 55, 48, 15, text_cf_left}, 13 {text_createindirect, "rtext", 0, 10, 80, 48, 15, text_cf_right}, 14 {edit_createindirect, null, gui_id_edit0, 60, 55,100, 15, 0, 50}, 15 {edit_createindirect, null, gui_id_edit1, 60, 80,100, 15, 0, 50}, 16 {text_createindirect, "hex", 0, 10,100, 48, 15, text_cf_right}, 17 {edit_createindirect, null, gui_id_edit2, 60,100,100, 15, 0, 6}, 18 {text_createindirect, "bin", 0, 10,120, 48, 15, text_cf_right}, 19 {edit_createindirect, n Ull, gui_id_edit3, 60,120,100, 15}, 20 {listbox_createindirect, null, gui_id_listbox0, 10, 10, 48, 40}, 21 {checkbox_createindirect, null, gui_id_check0, 10,140, 0, 0}, 22 {checkbox_createindirect, null, gui_id_check1, 30,140, 0, 0}, 23 {slider_createindirect, null, gui_id_slider0, 60,140,100, 20}, 24 {slider_createindirect, null, disabled, 10,170,150, 30} 25}; 26 /************** **************************************** * ************** 27*28 Dialog Box Process function 29 */30 static void _ cbcallback (wm_message * PMSG) {31 int ncode, ID; 32 static const gui_conststring _ aplistbox [] = {// ListBox contant33 "English", "Deutsch", "Fran? AIS "," Japanese "," Italiano ", null34}; 35 wm_hwin hedit0, hedit1, hedit2, hedit3, hlistbox; 36 wm_hwin hwin = PMSG-> hwin; 37 switch (PMSG-> msgid) {38/* initialize the gadgets with their respective initial values. In the dialog box process function, this is the usual practice of responding to the wm_init_dialog39 message */40 case wm_init_dialog: 41/* Get window handles for all widgets */42 hedit0 = wm_getdialogitem (hwin, response); 43 hedit1 = wm_getdialogitem (hwin, login); 44 hedit2 = wm_getdialogitem (hwin, login); 45 hedit3 = login (hwin, login); 46 hlistbox = wm_getdialoem (hwin, gui_id_listbox0); 47/* Initialize all widgets */48 edit_se Ttext (hedit0, "Edit widget 0"); 49 edit_settext (hedit1, "Edit widget 1"); 50 edit_settextalign (hedit1, gui_ta_left); 51 edit_sethexmode (hedit2, 0x1234, 0, 0 xFFFF); 52 edit_setbinmode (hedit3, 0x1234, 0, 0 xFFFF); 53 listbox_settext (hlistbox, _ aplistbox); 54 wm_disablewindow (wm_getdialogitem (hwin, gui_id_check1); 55 checkbox_check (wm_getdialogitem (hwin, gui_id_check0); 56 checkbox_check (wm_getdialogitem (Hwin, gui_id_check1); 57 slider_setwidth (wm_getdialogitem (hwin, counter), 5); 58 slider_setvalue (wm_getdialogitem (hwin, counter), 50); 59 break; 60/* inform the parent window that some changes have occurred in its child window. The above is the initialization of the gadgets, and the following is the process of changes */61 case wm_policy_parent: 62 id = wm_getid (PMSG-> hwinsrc ); /* ID of the widget to obtain the ID of the widget */63 ncode = PMSG-> data. v;/* notification code notification message code */64 switch (ncode) {65 case wm_icationication_released: /* react only if released: the notification message will be sent when the clicked tool is released. */66 If (ID = gui_id_ OK) {/* OK button */67 gui_enddialog (hwin, 0); 68} 69 If (ID = gui_id_cancel) {/* cancel button */70 gui_enddialog (hwin, 1); 71} 72 break; 73 case wm_icationication_sel_changed:/* selection changed this notification message will be sent when the gadgets select changed. */74 framewin_settext (hwin, "dialog-Sel changed"); 75 break; 76 default: 77 framewin_settext (hwin, "dialog-notification received"); 78} 79 break; 80 default: 81 wm_defaultproc (PMSG ); 82} 83} 84 /********************************** * ********************************** 85*86 * maintask87 */88 void fun (void) {89 // for this example, the dialog box displays the following code lines: 90 gui_execdialogbox (_ adialogcreate, gui_countof (_ adialogcreate), & _ cbcallback, 0, 0, 0 ); 91}
[Ucgui] Dialog Box 2 -- small window initialization and message response