I am new to C++ and I'm using MFC by Visual Studio 2012 How can I display an Image in a picture control from browse button? On browse button click, I set the path to an edit control like that
void CSimilarityOfImagesDlg::OnBnClickedButton1()
{
CFileDialog dlg(TRUE);
int iRet = dlg.DoModal();
CString path = dlg.GetPathName();
SetWindowText (path);
CEdit* cedit;
cedit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDIT1));
cedit->SetWindowTextW(path);
cedit->GetWindowTextW(path);
}
MFC/ATL framework comes with
CImage
class that allows you to load images (PNG, JPEG, BMP, GIF and other formats are supported). In order to display the target image in your picture control you need to use theCStatic::SetBitmap()
method. TheCImage
class implementsDetach()
method that allows you to get direct access toHBITMAP
object. Here is an example:The
m_PictureCtrl
is defined in your dialog window header file like this:It is mapped to
IDC_PIC_STATIC
control ID using standard MFC Data Exchange mechanism.The Browse Button handler looks like this: