Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to browse a picture in MFC through a picture element and set the picture into the picture element?
Please help me with an answer.

[EDIT] Added code from comment
C++
void getPhoto()
{
    CFileDialog fOpenDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
                        "Bitmap pic(*.bmp)|*.bmp||",this);
    fOpenDlg.m_pOFN->lpstrInitialDir = "c:";
    m_picture = (CStatic*)GetDlgItem(IDC_STATIC);
    BOOL bWorking = finder.FindFile("*.");
    if (bWorking)
    {
        if (fOpenDlg.DoModal() == IDOK)
        {
            finder.FindNextFile();
            CString path = (LPCTSTR)fOpenDlg.GetPathName();
            HBITMAP hb = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), path, IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
            m_picture->ModifyStyle(0xF, SS_BITMAP, SWP_NOSIZE);
            m_picture->SetBitmap(hb);
            iFileAccount = 0;
            bLastFile = FALSE;
        }
    }
}

this is the code which is not working
Posted
Updated 30-Nov-14 22:42pm
v3
Comments
George Jonsson 30-Nov-14 8:27am    
Why would anyone give you help ASAP? Do you pay well?
At least make an effort to write some code of your own and then come back with a specific question.
Member 11274771 30-Nov-14 23:31pm    
sorry sir......
void getPhoto()
{

CFileDialog fOpenDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, "Bitmap pic(*.bmp)|*.bmp||",this);//(TRUE, "bmp", NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, NULL,this);
fOpenDlg.m_pOFN->lpstrInitialDir="c:";
m_picture = (CStatic *)GetDlgItem(IDC_STATIC);
BOOL bWorking = finder.FindFile("*.");
if (bWorking)
{
if(fOpenDlg.DoModal()==IDOK)
{
finder.FindNextFile();
CString path = (LPCTSTR)fOpenDlg.GetPathName();
HBITMAP hb = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), path, IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
m_picture->ModifyStyle(0xF, SS_BITMAP, SWP_NOSIZE);
m_picture->SetBitmap(hb);
iFileAccount = 0;
bLastFile = FALSE;
}
}
}
this is the code which is not working
George Jonsson 1-Dec-14 4:44am    
Use the Improve question widget when you add code. Don't use the comment.
The code is easier to read if you format it properly.
George Jonsson 1-Dec-14 4:45am    
So which part is not working?
Finding the file or viewing the file?
Member 11274771 3-Dec-14 0:12am    
please give the answer of this question....i didnot get any answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900