Initializare CFileDialog

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 688
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Initializare CFileDialog

Post by mesajflaviu » 26 Oct 2012, 15:18

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 ?



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Initializare CFileDialog

Post by Ovidiu Cucu » 26 Oct 2012, 20:39

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.

mesajflaviu
Membru++
Membru++
Posts: 688
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: Initializare CFileDialog

Post by mesajflaviu » 26 Oct 2012, 21:30

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 ...
Attachments
TestDraw7.zip
(192.35 KiB) Downloaded 147 times

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Initializare CFileDialog

Post by Ovidiu Cucu » 27 Oct 2012, 11:32

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.

Post Reply