日期:2014-05-16 浏览次数:20644 次
void dialog_calendar (GtkEntry *widget, DateTrans *dtEntry){ //DateTrans是我自定义的结构体指针,分别指向一个窗口和输入框 GtkWidget *dlCalendar; GtkWidget *vbCalendar; GtkWidget *calendar; GtkWidget *hbb; gint result; guint year; guint month; guint day; char *calendardate; dlCalendar = gtk_dialog_new_with_buttons ("Calendar", GTK_WINDOW(dtEntry->window), GTK_DIALOG_MODAL, GTK_STOCK_CLEAR, GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_has_separator (GTK_DIALOG (dlCalendar), FALSE); vbCalendar = GTK_DIALOG (dlCalendar)->vbox; gtk_widget_show (vbCalendar); calendar = gtk_calendar_new (); gtk_widget_show (calendar); gtk_box_pack_start (GTK_BOX (vbCalendar), calendar, TRUE, TRUE, 0); hbb = GTK_DIALOG (dlCalendar)->action_area; gtk_widget_show (hbb); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbb), GTK_BUTTONBOX_END); result = gtk_dialog_run(GTK_DIALOG(dlCalendar)); switch (result){ case GTK_RESPONSE_NO: gtk_entry_set_text(GTK_ENTRY(dtEntry->entry), ""); break; case GTK_RESPONSE_OK: gtk_calendar_get_date(GTK_CALENDAR(calendar), &year,&month,&day); g_sprintf(calendardate,"%d-%d-%d",year,month,day); gtk_entry_set_text(GTK_ENTRY(dtEntry->entry), calendardate); break; } //free(calendardate); //加了这句后,第一次执行该函数就会挂调。 gtk_widget_destroy(dlCalendar); }