Answered by:
Dialog box with a graphics window

Question
-
Hi,
I am using VS2012 pro, and have created a native c++ app in Windows 8 pro Desktop. I have a dialog box and I would like to add a graphics window to the dialog such that I can use my mouse to change stuff in the graphics window data in the dialog box can be updated.
Any help would be gratefully appreciated.
Wednesday, July 31, 2013 4:43 PM
Answers
-
Thanks Scott, that is working for me now!
- Marked as answer by rockmate Friday, August 2, 2013 10:38 AM
Thursday, August 1, 2013 4:27 PM
All replies
-
Ok. Let's give you a technique that matches what you're already doing.
What API did you use to create and show the dialog?
Wednesday, July 31, 2013 4:46 PM -
CDialogWednesday, July 31, 2013 4:53 PM
-
Put some edit control or static control on your dialog and handle WM_LBUTTONDOWN and and WM_LBUTTONUP message handle . Look on google or MSDN there are lots of sample to develop a paint app etc in MFC . You can start with those sample atleast you will get some idea how to proceed .
ThanksRupesh Shukla
Wednesday, July 31, 2013 5:03 PM -
There is nothing in the tool box which will allow me to add a graphics window. I should have said it is a mfc app.
Thanks
Wednesday, July 31, 2013 5:09 PM -
Seems you are using MFC, can you a bit more detailed what you want in your graphics window. Is it suppsed to display your data as bar or pie chart...?
Only as an idea, did you searched CodeProject.com for a control that maches your reequirements?
http://www.codeproject.com/Articles/14075/High-speed-Charting-Control
http://www.codeproject.com/Articles/317712/An-MFC-Chart-Control-with-Enhanced-User-Interface
http://www.codeproject.com/Articles/1993/Scientific-charting-control
Best regards
Bordon
Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.Wednesday, July 31, 2013 5:12 PM -
Thanks Bordon,
It is a 2D drawing. I just want a part of the screen where I can do some moveto and Lineto's and have some mouse control.
Wednesday, July 31, 2013 5:20 PM -
So one half of the dialog will have text boxes etc and the other will have the graphics screen.Wednesday, July 31, 2013 5:26 PM
-
Do I add a picture control?Wednesday, July 31, 2013 5:34 PM
-
Create a Custom Control and add it to your dialog.
Create a custom class that handles all the interaction that you want to do, including paint and mouse.
See this example. The example draws a bitmap, but if all you want is MoveTo, LineTo, then great...even easier. Just do so in the Paint function.
Wednesday, July 31, 2013 5:47 PM -
Do I add a picture control?
That will work fine. Create a class derived from CStatic, and add a control member variable for it in the dialog. Change its class from CStatic to your derived class. Then your derived class can add message handlers for the mouse and paint messages.Wednesday, July 31, 2013 9:46 PM -
Thanks,
I added the picture control and added a CStatic variable.
I created a new CView Class - CDrawdesign. I changed the variable from a CStatic variable to a CDrawedesign variable but then got the following error:
'CDrawDesgin' : cannot instantiate abstract class
5> due to following members:
5> 'void CView::OnDraw(CDC *)' : is abstract
I do not know how to fix this?
Thursday, August 1, 2013 10:57 AM -
I have added
public virtual void OnDraw(CDC* pDC);
to CDrawDesgin
and now I am getting new errors:
1>DrawDesgin.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CDrawDesgin::GetRuntimeClass(void)const " (?GetRuntimeClass@CDrawDesgin@@UBEPAUCRuntimeClass@@XZ)
1>DrawDesgin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CDrawDesgin::OnDraw(class CDC *)" (?OnDraw@CDrawDesgin@@UAEXPAVCDC@@@Z)
Thursday, August 1, 2013 11:52 AM -
I have added
public virtual void OnDraw(CDC* pDC);
to CDrawDesgin
and now I am getting new errors:
1>DrawDesgin.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CDrawDesgin::GetRuntimeClass(void)const " (?GetRuntimeClass@CDrawDesgin@@UBEPAUCRuntimeClass@@XZ)
1>DrawDesgin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CDrawDesgin::OnDraw(class CDC *)" (?OnDraw@CDrawDesgin@@UAEXPAVCDC@@@Z)
You have added the declaration of OnDraw() to the class definition in the .h file, but you have not added the implementation in the .cpp file.
This would not have happened if you had added this virtual function using the IDE.
David Wilkinson | Visual C++ MVP
Thursday, August 1, 2013 12:10 PM -
Thanks Dave, got rid of one of the errors, left with:
DrawDesgin.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CDrawDesgin::GetRuntimeClass(void)const " (?GetRuntimeClass@CDrawDesgin@@UBEPAUCRuntimeClass@@XZ)
Thursday, August 1, 2013 12:29 PM -
You apparentlyy derived CDrawdesign from CView. It must be derived from CStatic if you are associating it with a static control.
You probably did that because you wanted the OnDraw function. CStatic does not have an OnDraw function. Instead, add a message handler for WM_PAINT. Start your OnPaint function like this and you're good to go:
void CDrawdesign::OnPaint() { CPaintDC dc(this); // device context for painting ... paint here }
- Proposed as answer by Anna Cc Friday, August 2, 2013 8:20 AM
Thursday, August 1, 2013 1:13 PM -
Thanks Scott, that is working for me now!
- Marked as answer by rockmate Friday, August 2, 2013 10:38 AM
Thursday, August 1, 2013 4:27 PM