Page 1 of 1

Initializare CFileDialog

Posted: 26 Oct 2012, 15:18
by mesajflaviu
Am derivat o clasa din CFileDialog, in care am pus un CStatic unde pun un file preview ... totul merge OK, dar nu reusesc sa initializez acest control static chiar la deschidere ... am incercat in

Code: Select all

BOOL CFileDialogExt::OnInitDialog() 
{
	CFileDialog::OnInitDialog();

	// TODO: Add extra initialization here

	ShowFilePreview();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
nu merge ... am incercat in

Code: Select all

void CFileDialogExt::OnInitDone()
{
	ShowFilePreview();
}
nu merge ... am pus un PostInitDialogMessage:

Code: Select all

BOOL CFileDialogExt::OnInitDialog() 
{
	CFileDialog::OnInitDialog();

	// TODO: Add extra initialization here

	::PostMessage(m_hWnd, WMU_POSTINITDIALOG, 0, 0);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFileDialogExt::OnInitDone()
{
	::PostMessage(m_hWnd, WMU_POSTINITDIALOG, 0, 0);
}

// unde 
LRESULT CFileDialogExt::OnPostInitDialog(WPARAM wParam, LPARAM lParam)
{
	CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_PICTURE);
	CBitmap bmpNoPreview;
	bmpNoPreview.LoadBitmap(IDB_NOPREVIEW);
	pStatic->SetBitmap(bmpNoPreview);

	return 0;
}
unde ar trebui sa pun cod pentru a avea acel file preview chiar la deschiderea CFileDialog ?

Re: Initializare CFileDialog

Posted: 26 Oct 2012, 20:39
by Ovidiu Cucu
Sunt mai multe metode de a customiza un file dialog.
Banui care ai folosit, insa ca sa castig putin timp mi-ar prinde bine o aplicatie demo/test care sa arate ce ai facut/incercat.

Re: Initializare CFileDialog

Posted: 26 Oct 2012, 21:30
by mesajflaviu
Cred ca am derivat CFileDialogExt din CFileDialog cat mai simplu ... atasez proiectul de test aici ... bine, se vad acolo "incercarile" mele: CFileDialogExt::OnInitDialog(), CFileDialogExt::OnInitDone(), care evident sant fara rost amandoua ...

Re: Initializare CFileDialog

Posted: 27 Oct 2012, 11:32
by Ovidiu Cucu
Ah, scuze! Aseara eram obosit si n-am observat ca greseala se observa cu ochiul liber din prima postare. :)
mesajflaviu wrote:

Code: Select all

LRESULT CFileDialogExt::OnPostInitDialog(WPARAM wParam, LPARAM lParam)
{
	CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_PICTURE);
	CBitmap bmpNoPreview; // <-- local defined
	bmpNoPreview.LoadBitmap(IDB_NOPREVIEW);
	pStatic->SetBitmap(bmpNoPreview);

	return 0;
} // <-- here bmpNoPreview is destroyed.
bmpNoPreview este definit local in functia CFileDialogExt::OnPostInitDialog. Cand iese din scopul functiei, se distruge si implicit se distruge si obiectul GDI (HBITMAP) pe care-l contine.
Asa ca pune-l ca membru in clasa CFileDialogExt si-atunci o sa mearga.
BTW, nu cred ca-i nevoie sa postezi acel mesaj custom. Poti face treaba direct in CFileDialogExt::OnInitDialog.