Hi,
I have implemented a file selector with a combobox. I want to write the selected filename to a log. The problem is that when I select a file from the original directory it goes well but when I choose a file from another directory it won't work. Can anybody help with this? Here is the code for the file selector, it is inside a dialog.
BOOL CALLBACK BateriaFaxDlg(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){
char descripcion[100]="";
char archivo[100]="";
char cad[100];
int i,l;
switch (msg)
{
case WM_INITDIALOG:
InitCombo(hDlg, "*.*");
return TRUE;
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
i = SendDlgItemMessage(hDlg, IDC_ARCH2, CB_GETCURSEL, 0, 0);
if(i >= 0) {
SendDlgItemMessage(hDlg, IDC_ARCH2, CB_GETLBTEXT, (WPARAM)i, (LPARAM)archivo);
}
if (!GetDlgItemText(hDlg, IDC_DESCBATER, descripcion , 100)) {
MessageBox(hDlg, "Ambos campos son obligatorios", "ERROR", MB_ICONEXCLAMATION | MB_OK);
break;
}
actualizarBaterias(GetParent(hDlg), "FAX", archivo, descripcion);
EndDialog(hDlg, FALSE);
break;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
case IDC_ARCH2:
switch(HIWORD(wParam)) {
case CBN_CLOSEUP:
case CBN_KILLFOCUS:
if(DlgDirSelectComboBoxEx(hDlg, cad, 100, IDC_ARCH2)) {
strcat(cad, "*.*");
InitCombo(hDlg, cad);
}
break;
}
break;
default:
break;
return TRUE;
}
}
return FALSE;
}
This is InitCombo:
void IniciarCombo(HWND hwnd, char* p) {
char path[100];
strcpy(path, p);
DlgDirListComboBox(
hwnd,
path,
IDC_ARCH2,
ID_TITULO,
DDL_DIRECTORY | DDL_DRIVES
);
SendDlgItemMessage(hwnd, IDC_ARCH2, CB_SETCURSEL, 0, 1);
}
and finally this is where i write the filename to a file.
void actualizarBaterias(HWND hWnd, char *tipo, char *archivo, char *descripcion) {
FILE *fp;
HWND hctrl;
int i;
HFONT hfont;
fp = fopen("conf\\Baterias.conf", "a" );
if (fp) {
MessageBox(hWnd, "Actuali","error", MB_ICONEXCLAMATION | MB_OK);
fprintf(fp, "\n%s %s %s", tipo, archivo, descripcion);
fclose(fp);
}
}
Thanks in advance.