winapi - C Win32: Window Automatically closes -
i wanted create word 'corrupter' justs replaces letters ascii alphabet. however, when 'generate' button pressed, window automatically closes
static handle ghinstance; hwnd hwndedit; int index[10]; static int_ptr callback maindlgproc(hwnd hwnddlg, uint umsg, wparam wparam, lparam lparam) { switch (umsg) { case wm_initdialog: { hwndedit = getwindow(hwnddlg, idc_edit); return true; } case wm_size: /* * todo: add code process resizing, when needed. */ return true; case wm_command: switch (get_wm_command_id(wparam, lparam)) { case idc_generate: { char input[1000]; char output[1000][10]; int i, strlength, m, map; int rnmb; int chance; getwindowtext(hwndedit, input, 1000); srand(time(null)); strlength = strlen(input); for(m=0;m<10;m++) { map = 0; strcpy(output[m], input); for(i=0;i<strlength;i++) { switch(output[m][i]) { case '\0': continue; case '\n': continue; case ' ': continue; } chance = rand() % 100; if(chance < 25) { rnmb = (rand() % 128) + 128; output[m][i] = rnmb; } } index[m] = senddlgitemmessage(hwnddlg , idc_listbox, lb_addstring, 0, (lparam)output[m]); map++; senddlgitemmessage(hwnddlg, idc_listbox, lb_setitemdata, (wparam)index[m], (lparam)map); } } case idc_close: enddialog(hwnddlg, true); return true; } break; case wm_close: enddialog(hwnddlg, 0); return true; /* * todo: add more messages, when needed. */ } return false; }
i not see link between generate button , close command
you're missing break statement.
the case case idc_generate
falls directly into:
case idc_close: enddialog(hwnddlg, true); return true;
you use functions make code readable, , error caught.
Comments
Post a Comment