Solved

Plotting...

Posted on 1998-09-29
4
321 Views
Last Modified: 2010-04-01
Me again...
I have a MFC dialog based application. It has a button on it. When I press the button, another dialog box opens. I want to place the x-y axes on this dialog and do plotting of variables that will be read by the program (real time plotting). Sunj gave me a push in the right direction but I am lost again. I decided to see what happens if I do the following. In the OnInitDialog of this second box I have placed the code...

CClientDC* pDC;
pDC = new CClientDC(this);
pDC->TextOut(50,50,"Hello",50)
pDC->LineTo(50,50)

And nothing happened... what am I doing wrong?
Thanks
0
Comment
Question by:rose3377
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 0 total points
ID: 1173978
The dialog window has not been displayed at the time of OnInitDialog.  The DC you create will have no display area, so the text is not displayed.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173979
>> what am I doing wrong?
1. CClientDC * is never deleted

2. In WM_INITDIALOG the dialog is not yet visible.  When it does become visible, WM_PAINT handles painting and will overwrite anything you have painted.

3. In life time of a dialog WM_PAINT may be called many times


TO FIX:
1. Override WM_PAINT
2. Make sure base classs etc.. are called so dialog is still painted.  
3. After the call to base class - add

ClientDC cdc(this);
cdc.TextOut(50,50,"Hello",50) ;
cdc.LineTo(50,50)  ;



0
 
LVL 22

Expert Comment

by:nietod
ID: 1173980
Displaying should occur in the onPaint() member procedure.  However, a dialog will take care of displaying itself (if you let it, and you probably should let it do so.)  If you want to display "custom" images on a dialog, create a control (window) on the dialog of your own class and display your images in it on the onPaint() procedure.  Or don't use a dialog and create your own window class and display the image in the client area of the window your create.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173981
>> a dialog will take care of displaying itself
It will, but you can add your own additional painting too.  Check Petzold book for an SDK style sample
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

740 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