-
June 12th, 2008, 11:21 PM
#1
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.
-
June 13th, 2008, 02:24 AM
#2
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
Last edited by nik_lin; June 13th, 2008 at 02:26 AM.
-
June 14th, 2008, 04:58 AM
#3
Re: MFC DoModal for Loading Pictures
This worked excellently. Thanks.
-
June 16th, 2008, 03:53 AM
#4
Re: MFC DoModal for Loading Pictures
No problem Glad it helped you out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|