E
E
Eugene2015-02-15 16:04:27
C++ / C#
Eugene, 2015-02-15 16:04:27

How to display an image on a form in an MFC application?

Good afternoon.
There is an MFC project in VS6. You can't upgrade to a more recent VS. It is necessary to load an image in png or bmp from the file system and display it on the form. There is no CImage class in VS6. All I could find was loading bmp from program resources, and I have an external file. Please let me know how to do this seemingly simple task.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2015-02-15
@EvgenijDv

Here's a finished crutch on pure WinApi.
in the process, Eugene found a shorter solution:

OnInitDialog() 
{
  CDialog::OnInitDialog();
  HBITMAP hBitMap = (HBITMAP)::LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  CStatic*  m_picture = (CStatic *)GetDlgItem(IDC_QRIMAGE);
  m_picture->ModifyStyle(0xF, SS_BITMAP, SWP_NOSIZE);
  m_picture->SetBitmap(hBitMap);
}

I sympathize. Using VC version 6 and MFC today is a feat.

E
Eugene, 2015-02-16
@EvgenijDv

Armenian Radio Today, with a fresh mind, I found a fairly short and working solution

OnInitDialog() 
{
  CDialog::OnInitDialog();
  HBITMAP hBitMap = (HBITMAP)::LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  CStatic*  m_picture = (CStatic *)GetDlgItem(IDC_QRIMAGE);
  m_picture->ModifyStyle(0xF, SS_BITMAP, SWP_NOSIZE);
  m_picture->SetBitmap(hBitMap);
}

I suggest you edit your answer to include this snippet and I'll mark it as the solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question