Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Nothing gets displayed on the picture control , why:

C++
void CSchInfo::OnBnClickedButton1()
{
	static TCHAR BASED_CODE szFilter[] = _T("Image Files (*.bmp;*.gif;*.jpg;*.png;*.tif)|*.bmp;*.gif;*.jpg;*.png;*.tif||");
	
	CFileDialog FileDialog(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,szFilter,this);
	if(FileDialog.DoModal() == IDOK)
	{
		m_stLogoPath = FileDialog.GetPathName();
		m_stFileName = FileDialog.GetFileName();
		
		CWnd* pPicCtrl = GetDlgItem(IDC_STATIC13);//Picture control
        CRect rc;
        pPicCtrl->GetWindowRect(&rc);

		Graphics  graphics(pPicCtrl->GetDC()->GetSafeHdc());
		Image image(m_stLogoPath);
		 
		graphics.DrawImage(&image,rc.TopLeft().x, rc.TopLeft().y,rc.Width(),rc.Height());
		
	}

}



C++
void CSchInfo::OnPaint()
{
	CPaintDC dc(this);
	if (IsIconic())
	{
		// Gerätekontext zum Zeichnen

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Symbol in Clientrechteck zentrieren
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Symbol zeichnen
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		if(m_stLogoPath.GetLength())
		{

			 CWnd* pPicCtrl = GetDlgItem(IDC_STATIC13);
			 CRect rc;
			 pPicCtrl->GetWindowRect(&rc);

			 Graphics  graphics(pPicCtrl->GetDC()->GetSafeHdc());
			 Image image(m_stLogoPath);
		 
			graphics.DrawImage(&image,rc.TopLeft().x, rc.TopLeft().y,rc.Width(),rc.Height());
		}
		else if(m_stLogoPath1.GetLength())
		{
			CWnd* pPicCtrl = GetDlgItem(IDC_STATIC13);
			 CRect rc;
			 pPicCtrl->GetWindowRect(rc);

			 Graphics  graphics(pPicCtrl->GetDC()->GetSafeHdc());
			 Image image(m_stLogoPath1);
		 
			graphics.DrawImage(&image,rc.TopLeft().x, rc.TopLeft().y,rc.Width(),rc.Height());
		}
        
	    CDialog::OnPaint();

	}
}



C++
BEGIN_MESSAGE_MAP(CSchInfo, CDialogEx)
	ON_COMMAND(IDC_BUTTON1,OnBnClickedButton1)
	ON_COMMAND(IDOK,OnBnClickedOk)
	ON_WM_PAINT()
END_MESSAGE_MAP()
Posted
Comments
Richard MacCutchan 23-Nov-14 5:01am    
There could be many reasons. You need to provide more information about what happens and where any errors occur.
Gbenbam 23-Nov-14 5:35am    
There was no error message, no exception thrown, yet no image was displayed on the picture control. What could be wrong with the code?
Richard MacCutchan 23-Nov-14 5:38am    
Anything could be wrong with the code; you need to use your debugger to trace through the code and find out where it is going wrong.

What values are being returned by the calls to m_stLogoPath.GetLength() and m_stLogoPath1.GetLength()?
Gbenbam 23-Nov-14 5:29am    
There was no error message, no exception thrown, yet no image was displayed on the static control. What could be wrong with the code?

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