Code:
BOOL CALLBACK DlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL,MAKEINTRESOURCE(IDI_ICON1)));
SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1))); break;
case WM_CLOSE:
EndDialog(hDlg, 0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDEXIT:
EndDialog(hDlg, 0);
break;
case ID_FILE_EXIT:
EndDialog(hDlg, 0);
break;
case ID_HELP_ABOUT:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hDlg, AboutDlgProc);
break;
case IDCLEAR:
SendDlgItemMessage(hDlg, IDC_LIST1, LB_RESETCONTENT, 0, 0);
break;
case IDADD:
{
char filename[MAXBUFFER] = "";
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hDlg;
ofn.lpstrFilter = "GameBoy Roms (*.gb)\0*.gb\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = MAXBUFFER;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;
ofn.lpstrDefExt = "gb";
if(GetOpenFileName(&ofn))
{
if(ofn.nFileOffset < lstrlen(ofn.lpstrFile))
{
SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)ofn.lpstrFile);
}
else
{
char *temp = ofn.lpstrFile + ofn.nFileOffset;
while(*temp != '\0')
{
SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)temp);
temp += strlen(temp) + 1;
}
}
}
break;
}
case IDREMOVE:
{
int index = SendMessage(hList, LB_GETCURSEL, 0, 0);
SendMessage(hList, LB_DELETESTRING, (WPARAM)index, 0);
break;
}
case IDGENERATE:
{
int count, position, c, temp = 0, index = 0, fpos = 0;
char romName[16], *buf = "";
FILE *fpBIN, *fpBINhead, *fpROM;
fpBINhead = fopen("tmpBINhead", "wb");
fpBIN = fopen("tmpBIN", "wb");
HWND hList = GetDlgItem(hDlg, IDC_LIST1);
count = SendMessage(hList, LB_GETCOUNT, 0, 0);
while(count >= 0)
{
SendMessage(hList, LB_GETTEXT, (WPARAM)count, (LPARAM)buf); // <--- THIS IS THE PROBLEM. "buf" stays empty and, therefore, the next line produces an error and crashes the program.
fpROM = fopen(buf, "rb");
... continues.
edit: sorry if the code looks a bit sloppy in format, hard to get it to look right. Anyways, It's the single SendMessage call that doesn't do what it's supposed to, every other SendMessage call work perfectly.