?
Solved

MFC! Insert BMP and JPEG window in dialog and how to resize SDI window?

Posted on 2003-12-05
6
Medium Priority
?
1,121 Views
Last Modified: 2013-11-20
Urgent!!! i need to put bitmap and jpeg into my visual C++ program, into a dialog when i start running my program.
but i don't know how. Can somebody explain step by step to me?

another question is how can i resize my window when I start running my program? which class should I place my code in?(I am working with SDI)

thanx in advance(hope to receive reply asap)



0
Comment
Question by:dixon_lee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 172 total points
ID: 9887590
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 164 total points
ID: 9887639
To put a bitmap (256 colour) onto a dialog you can use the resource editor.

To resize your window, one method would be (eg in the OnInitialUpdate of the view, OnInitDialog for a dialog):
AfxGetMainWnd()->MoveWindow(left, top, width, height);

more flexibility is provided with the SetWindowPos fn.
0
 

Assisted Solution

by:andyinlondon
andyinlondon earned 164 total points
ID: 9892631
1. Edit your dialog.rc file using Visual Studio's dialogue editor (as though you want to add buttons etc.).
2. Add a "Picture Control" from the "toolbox". Make it the size that you want your final image to be.
3. In the "properties" view of the picture control, change its ID to "IDC_PICTURE_PLACEHOLDER".
4. Add the following member variables to your dialog class:
   CRect m_PictureHolderRect;
   CImage m_bmpBitmap;
5. Add ON_WM_PAINT() to your dialogue box message map (it's probably already there).
6. Add the following methods (assuming your dialog is called CMyDlg).

BOOL CMyDlg::OnInitDialog()
{ CDialog::OnInitDialog();

  // get the screen dimensions of the PictureControl - it was only put there for this purpose
  CWnd* pWnd = GetDlgItem(IDC_PICTURE_PLACEHOLDER);
  pWnd->GetWindowRect(&m_PictureHolderRect);
  // convert to client coordinates
  ScreenToClient(&m_PictureHolderRect);
  LoadBitmap("C:\\My Pictures\\Somewhere\\Nice Picture.JPG");
  return TRUE;
}

void CMyDlg::LoadBitmap(CString str)
{ if (str.GetLength() > 0)
  { // Delete the current image
    m_bmpBitmap.Destroy();
    // Load the new image
    m_bmpBitmap.Load(str);
    // Invalidate the dialog
    Invalidate();
  }
}

void CMyDlg::OnPaint()
{ // get the device context
  CPaintDC dc(this);

  // get the rectangle containing the picture place-holder
  CRect rect(m_PictureHolderRect);

  // retain the correct aspect ratio
  int spaceWidth = rect.Width();
  int spaceHeight = rect.Height();
  int bmpWidth = m_bmpBitmap.GetWidth();
  int bmpHeight = m_bmpBitmap.GetHeight();
  if ((double)bmpWidth / bmpHeight > (double)spaceWidth / spaceHeight)
  { spaceHeight = (int)((double)spaceWidth / bmpWidth * bmpHeight);
  }
  else
  { spaceWidth = (int)((double)spaceHeight / bmpHeight * bmpWidth);
  }
  rect.right = rect.left + spaceWidth;
  rect.bottom = rect.top + spaceHeight;

  // re-position to the centre of the place-holder position
  LONG offsetX = (m_PictureHolderRect.right - rect.right) / 2;
  LONG offsetY = (m_PictureHolderRect.bottom - rect.bottom) / 2;
  rect.left += offsetX;   rect.right += offsetX;
  rect.top += offsetY;    rect.bottom += offsetY;

  // resize the picture placeholder
  CWnd* pWnd = GetDlgItem(IDC_PICTURE_POS);
  pWnd->SetWindowPos(NULL,
                     rect.left - 4,
                     rect.top - 4,
                     rect.Width() + 8,
                     rect.Height() + 8,
                     SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER /* | SWP_NOMOVE */);

  // set the bitmap stretch mode to half-tone
  dc.SetStretchBltMode(HALFTONE);

  // display the bitmap
  m_bmpBitmap.Draw(dc.m_hDC, rect);
}

Not only will this display your picture within your dialogue box, it will also retain the correct aspect ratio.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question