CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    23

    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.

  2. #2
    Join Date
    May 2008
    Posts
    24

    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.

  3. #3
    Join Date
    Oct 2006
    Posts
    23

    Re: MFC DoModal for Loading Pictures

    This worked excellently. Thanks.

  4. #4
    Join Date
    May 2008
    Posts
    24

    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
  •  





Click Here to Expand Forum to Full Width

Featured