Raf Vermeulen
Member #7,166
April 2006
|
I've been trying to figure out what's wrong with these... I did the exact same thing as in the code of another project of mine, where it works like a charm, but here, it doesn't. I got a text-field and a button in a dialog. The problem with them, is that they're both static. You can't put a cursor in the text-field, let alone edit the text in it, and the button simply doesn't respond at all either. Doesn't do anything when you click it or so. This's the code:
1 | void compare_score() { | 2 | char name[100] = "Player"; | 3 | int end_score; | 4 | int end_lvl; | 5 | long pos; | 6 | bool done = false; | 7 | int count = 1; | 8 | FILE * file; | 9 | file = fopen("High.txt","r+"); | 10 | if (file == NULL) create_file(); | 11 | file = fopen("High.txt","r+"); | 12 | | 13 | while (!feof(file) && done == false) { | 14 | pos = ftell(file); | 15 | fscanf(file, "%s", name); | 16 | fscanf(file, "%d", &end_score); | 17 | fscanf(file, "%d", &end_lvl); | 18 | if (score > end_score) done = true; | 19 | count++; | 20 | } | 21 | if (done == true) { | 22 | cout << "DONE\n"; | 23 | | 24 | // Naam dialoog ding... | 25 | DIALOG the_dialog[] = { | 26 | { d_agup_edit_proc, 15, 75, 125, 8, 0, 0, 0, 0, 100, 0, name, NULL, name }, | 27 | { d_agup_push_proc, 90, 115, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Done", 0, (void*)edit_high }, | 28 | /* the next two elements don't draw anything */ | 29 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, | 30 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } | 31 | }; | 32 | | 33 | /* Dialog box colour */ | 34 | gui_fg_color = agup_fg_color; | 35 | gui_bg_color = agup_bg_color; | 36 | gui_mg_color = agup_mg_color; | 37 | gui_shadow_box_proc = d_agup_shadow_box_proc; | 38 | gui_button_proc = d_agup_button_proc; | 39 | gui_ctext_proc = d_agup_ctext_proc; | 40 | gui_text_list_proc = d_agup_text_list_proc; | 41 | /* End of dialog box colour */ | 42 | | 43 | | 44 | | 45 | /* set up colors */ | 46 | gui_fg_color = makecol(0, 0, 0); | 47 | gui_mg_color = makecol(128, 128, 128); | 48 | gui_bg_color = makecol(200, 240, 200); | 49 | set_dialog_color (the_dialog, gui_fg_color, gui_bg_color); | 50 | | 51 | /* white color for d_clear_proc and the d_?text_procs */ | 52 | the_dialog[0].bg = makecol(255, 255, 255); | 53 | for (int i = 4; the_dialog<i>.proc; i++) | 54 | if (the_dialog<i>.proc == d_text_proc || | 55 | the_dialog<i>.proc == d_ctext_proc || | 56 | the_dialog<i>.proc == d_rtext_proc) | 57 | the_dialog<i>.bg = the_dialog[0].bg; | 58 | | 59 | position_dialog (the_dialog, 2, 2); | 60 | do_dialog(the_dialog, -1); | 61 | } | 62 | fclose(file); | 63 | } | 64 | | 65 | | 66 | | 67 | void edit_high(long pos, char name[100], int count) { | 68 | int end_score; | 69 | int end_lvl; | 70 | | 71 | | 72 | FILE * file; | 73 | file = fopen("High.txt","r+"); | 74 | | 75 | | 76 | | 77 | fseek(file, pos, SEEK_SET); | 78 | fprintf(file, "NEW\n"); | 79 | fprintf(file,"%d\n", score); | 80 | fprintf(file,"%d\n", lvl_nr+1); | 81 | if (count < 10) { | 82 | fprintf(file, "%s\n", name); | 83 | fprintf(file,"%d\n", end_score); | 84 | fprintf(file,"%d\n", end_lvl); | 85 | } | 86 | | 87 | | 88 | for (int i = (count+1); i <= 10; i++) { | 89 | cout << "I: " << i << "\n"; | 90 | cout << "Count: " << count << "\n"; | 91 | pos = ftell(file); | 92 | fseek(file, pos-1, SEEK_SET); | 93 | cout << "POS before: " << pos << "\n"; | 94 | fscanf(file, "%s", name); | 95 | fscanf(file, "%d", &end_score); | 96 | fscanf(file, "%d", &end_lvl); | 97 | fseek(file, pos, SEEK_SET); | 98 | fprintf(file, "%s\n", name); | 99 | fprintf(file,"%d\n", end_score); | 100 | fprintf(file,"%d\n", end_lvl); | 101 | cout << "POS after: " << pos << "\n"; | 102 | } | 103 | fclose(file); | 104 | } |
|