I wanted to create a Word 'corrupter' which actually justs replaces some letters with some ascii alphabet. However, when the 'Generate' button is pressed, the 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 to 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 do not see any link between the generate button and the close command
You're missing a break statement.
The case case IDC_GENERATE
falls directly into:
case IDC_CLOSE:
EndDialog(hwndDlg, TRUE);
return TRUE;
You could use functions to make the code readable, and this error would probably be caught.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments