Graphics in a dialog based MFC application

Posted on 2003-02-25
Medium Priority
Last Modified: 2013-11-20
I am very new to visual c++ and am having a very difficult time finding out how to add graphics to say a picture box in a dialog based application.  Right now, I would be happy with being able to click a button and have rectangles and circles appear in a picture box I create.  Please help!
Question by:jsano19
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
  • 4
  • 2
LVL 48

Accepted Solution

AlexFM earned 200 total points
ID: 8017314
1) Using MFC Class Wizard create new class derived from CStatic (let's call it CMyStatic)
2) Overwrite it's OnPaint message and put drawing code in it
3) In your dialog create picture box with SS_BITMAP style (in dialog editor right-click it and select Bitmap type)
4) Add member variable of type CStatic for this picture box (use Member Variables tab of MFC Class Wizard) - let's call it m_static_picture
5) Include MyStatic.h to dialog h-file
6) Change manually type of m_static_picture variable from CStatic to CMyStatic.


Author Comment

ID: 8017584
I tried to do your steps, but run into some problems....
Mainly, adding the member variable of type CStatic in the MFC Class Wizard won't work properly because the picture box I made does not show up as a possible member variable.  do you know why this is?

Author Comment

ID: 8017676
Ignore that last comment of mine, I figured that out, just me being stupid.  But, in regards to step 2, the OnPaint message isn't in CMyStatic, I'm trying to figure out how to get it there now, but so far without luck.
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!


Author Comment

ID: 8017734
Ignore that last comment of mine, I figured that out, just me being stupid.  But, in regards to step 2, the OnPaint message isn't in CMyStatic, I'm trying to figure out how to get it there now, but so far without luck.

Author Comment

ID: 8017962
Sorry, I was just being stupid again.  Thanks for your help though, I did get it to work.  Quick question however, does it have to be a bitmap, or can I use frame and things like that instead?
LVL 48

Expert Comment

ID: 8022952
Nice to see that you solved your problems at the time I was off-line. This should be static control with SS_BITMAP style, exactly as you did (picture control in dialog editor).

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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