problem with GetOpenFileName win32 c + +

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span class="x_hps Hello <span class="x_hps to all,<br/>
<br/>
<span class="x_hps I have a <span class="x_hps big problem with <span class="x_hps
this function,<br/>
<br/>
<span class="x_hps Im trying to <span class="x_hps get information from
<span class="x_hps a window with <span class="x_hps many options.

<span class="x_hps with this method
<pre class="prettyprint case IDC_BUTTON3:
cont++;
ndi << cont << " di";

SendDlgItemMessage(hDlg,IDC_STATIC8,WM_SETTEXT,0,(LPARAM)ndi.str().c_str());
if (cont == (SendDlgItemMessage(hDlg,IDC_COMBO1,CB_GETCURSEL,2,0) + 1))
SendDlgItemMessage(hDlg,IDC_BUTTON3,WM_SETTEXT,0,(LPARAM)"Fine");


fgModes = ::GetDlgItem(hDlg, IDC_EDIT2);
lunghezzaignora = GetWindowTextLength(fgModes) + 1;
ignora = (LPSTR)GlobalAlloc(GPTR, lunghezzaignora*sizeof(LPSTR));
GetWindowText(fgModes,ignora,lunghezzaignora);
tmpsettaggi[cont-1] << ignora << " X 0 ; " << endl;
//HERE PUT FILENAME, FILENAME is a global variable. //<span class="x_hps is filled <span class="x_hps with <span class="x_hps the function int ChooseProgram (PCHAR FileName) tmpsettaggi[cont-1] << FileName << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK1,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK2,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK3,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;
fgModes = ::GetDlgItem(hDlg, IDC_EDIT3);
lunghezzaignora = GetWindowTextLength(fgModes) + 1;
ignora = (LPSTR)GlobalAlloc(GPTR, lunghezzaignora*sizeof(LPSTR));
GetWindowText(fgModes,ignora,lunghezzaignora);
tmpsettaggi[cont-1] << ignora << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK4,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK5,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK8,BM_GETCHECK,0,0);
if(lunghezzaignora == 0) {tmpsettaggi[cont-1] << 1000 << " ; " << endl;}
else {
fgModes = ::GetDlgItem(hDlg, IDC_EDIT4);
lunghezzaignora = GetWindowTextLength(fgModes) + 1;
ignora = (LPSTR)GlobalAlloc(GPTR, lunghezzaignora*sizeof(LPSTR));
GetWindowText(fgModes,ignora,lunghezzaignora);
tmpsettaggi[cont-1] << ignora << " ; " << endl;
}
lunghezzaignora = SendDlgItemMessage(hDlg,IDC_CHECK9,BM_GETCHECK,0,0);
tmpsettaggi[cont-1] << lunghezzaignora << " ; " << endl;

if (cont > (SendDlgItemMessage(hDlg,IDC_COMBO1,CB_GETCURSEL,2,0) + 1))
{
settaggi << (SendDlgItemMessage(hDlg,IDC_COMBO1,CB_GETCURSEL,2,0) + 1) << " ; ";
fgModes = ::GetDlgItem(hDlg, IDC_EDIT1);
lunghezzaignora = GetWindowTextLength(fgModes) + 1;
ignora = (LPSTR)GlobalAlloc(GPTR, lunghezzaignora*sizeof(LPSTR));
GetWindowText(fgModes,ignora,lunghezzaignora);
settaggi << ignora << " ; " << endl;
for(int i = 1; i < cont+1;i++)
{
settaggi << tmpsettaggi.str().c_str();
}
ofstream scrivifile("Setasti/settaggi",ios_base::out);
scrivifile << settaggi.str().c_str();
scrivifile.close();
settaggi.str("");
EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; break;
}
break; [/code]
this is a function <span style="font-size:small <span style="font-size:small ChooseProgram(PCHAR FileName)

<pre class="prettyprint CHAR FileName[MAX_PATH];
int ChooseProgram(PCHAR FileName)
{
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.hInstance = hInst;
ofn.lpstrFilter = "Icona*.BMPTutti file*.*";
ofn.lpstrFile = FileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Seleziona Licona:";
ofn.Flags = OFN_NONETWORKBUTTON | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
GetOpenFileName(&ofn);

return 1;
}[/code]
<span class="x_hps so good.. in debug mode the stringstream rapresent corectly patch of icon, that i select.
but in <span style="font-size:small <span style="font-size:small ofstream scrivifile(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Setasti/settaggi"<span style="font-size:small <span style="font-size:small ,ios_base::out);
not change, <span class="x_hps the file is not <span class="x_hps rewritten.

if i not use ChooseProgram(PCHAR FileName) function, the file <span class="x_hps
is written <span class="x_hps correctly <span class="x_hps obviously
<span class="x_hps without <span class="x_hps the patch
<span class="x_hps if i use ChooseProgram(PCHAR FileName) function but cancel operation of select a icon, the file
<span class="x_hps is written <span class="x_hps correctly <span class="x_hps obviously
<span class="x_hps without <span class="x_hps the patch
<span style="font-size:small <span style="font-size:small
anyone know <span class="x_hps what happens? xD <span class="x_hps makes me mad.. thanks all ^^<br/>


View the full article
 
Back
Top