The last class was dumb to introduce the application of CChart in the Microsoft MFC framework. The content of this lesson is still related to Microsoft, but the main character is changed to WTL.
If you are not familiar with WTL, you can check with du Niang. Du Niang is at heart, what is this life. Lang Jun, are you panic? If you are panic, tell me ten mothers, I am sorry for you. Oh, I'm sorry. I am so stupid. I thought of DU Niang as du shiniang.
Oh, by the way, if you are a female student, you can contact Gu Ge to learn from each other.
To use CChart in WTL, you must first install WTL. Because VC6 is used, WTL8.0 is used for download, and WTL7.1 is used for auxiliary installation, you need to find the specific method.
If you use a later version of VC, you can download WTL8.5.
Now let's start.
Step 1: Use VC to create a program based on the ATL/WTLWizard wizard named Lesson16. Select the default value in the remaining wizard steps without any modification.
650) this. width = 650; "src =" http://img.blog.csdn.net/20130919235710000? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>
Step 2: copy the five library files to the Lesson16 folder.
Step 3: Open the Lesson16View. h file in VC and add the following code in its header.
#include "Chart.h"#ifdef _DEBUG#pragma comment(lib, "PlotDll_d.lib")#else#pragma comment(lib, "PlotDll.lib")#endif
Step 4: Add a member variable of the CChartWnd type to the CLesson16View class in the Lesson16View. h file.
CChartWndm_ChartWnd;
Step 5: Find the following code in Lesson16View. h.
BEGIN_MSG_MAP(CLesson16View)MESSAGE_HANDLER(WM_PAINT, OnPaint)END_MSG_MAP()
Modify it to the following.
BEGIN_MSG_MAP(CLesson16View)//MESSAGE_HANDLER(WM_PAINT, OnPaint)MESSAGE_HANDLER(WM_CREATE, OnCreate)MESSAGE_HANDLER(WM_DESTROY, OnDestroy)END_MSG_MAP()
This is the message response of WTL.
Step 6: Find the following code in Lesson16View. h and delete or block it.
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/){CPaintDC dc(m_hWnd);//TODO: Add your drawing code herereturn 0;}
Step 7: Add the following code to Lesson16View. h.
LRESULT OnCreate (UINT/* uMsg */, WPARAM/* wParam */, LPARAM/* lParam */, BOOL &/* bHandled */) {double * pX, * pY; int I; if (m_ChartWnd.Attach (m_hWnd, kTypeXY) {pX = new double [200]; pY = new double [200]; for (I = 0; I <200; I ++) {pX [I] = (i-100.0)/100.0; pY [I] = pX [I] * pX [I];} m_ChartWnd.GetChart () -> AddCurve (pX, pY, 200); delete [] pY; delete [] pX; m_ChartWnd.GetChart () -> SetTitle (_ TEXT ("test CChart in WTL framework");} return 0;} LRESULT OnDestroy (UINT/* uMsg */, WPARAM/* wParam */, LPARAM/* lParam */, BOOL &/* bHandled */) {m_ChartWnd.Detach (); return 0 ;}
Finished! Compile and run the program.
650) this. width = 650; "src =" http://img.blog.csdn.net/20130920000101218? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>
The general feeling of programming in WTL is similar to that in the Win32Application wizard. What do students think?
The above stupid uses the CChartWnd class programming. Students can try to use the CChart class instead.