MFC DoModal for Loading Pictures
I'm wondering if there is a way to use DoModal boxes for the Jpeg files I'm trying to load onto the Picture Control I have in my application. For instance, CFileDialog has DoModal option for you, so you can browse through the files when trying to open a text file.
Re: MFC DoModal for Loading Pictures
Why not just use a CFileDialog and set the file type filter to *.jpg and then get the file path from the dialog? Then you can load the image file the user has picked into your control (using CImage or another class of your choice).
If you look at http://msdn.microsoft.com/en-us/libr...9d(VS.80).aspx you will find info about the CFileDialog constructor:
Code:
explicit CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0
);
So you could use something along the lines of
Code:
CFileDialog fileDlg(TRUE, _T("*.JPG;"), NULL, NULL, _T("JPG Files (*.JPG)|*.JPG||"), NULL);
fileDlg.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fileDlg.m_ofn.lpstrTitle = _T("Choose an image file");
if(fileDlg.DoModal() == IDOK)
{
...
}
To let the user browse for an image file. You can then use CImage::Load to load the image from the file path ( http://msdn.microsoft.com/en-us/library/tf4bytf8.aspx ).
Good luck :)
Re: MFC DoModal for Loading Pictures
This worked excellently. Thanks.
Re: MFC DoModal for Loading Pictures
No problem :) Glad it helped you out.