MFC图表VS2019 - VS2013教程C++语言。

point 1
symbol 2
symbol
shape
shape
point
shape
symbol

MFC CHARTING LIBRARY VS2022 - VS2019 C++ Walk Through

ProEssentials DLL interfaces are used when creating stand-alone Desktop or Embedded EXEs to be distributed royalty-free and ran on an end-users machine. This VS2022 - VS2019 MFC C++ Charting Walk-through includes instructions for Visual Studio using MFC. If you prefer an absolutely minimal Win32 Hello World type project without use of MFC, see Win32 C++ Charting Library. The product eval also installs a large MFC example project.

查看演示
Best WPF Chart to download, evaluate, and choose for your Financial Scientific Charting.
Best .NET Chart download for Scientific Charting, Engineering Charting.
Hello World - Walk Through - Tutorial

IMPORTANT: For help finding DLL specific features in our help system, click the Contents Tab at the top-left location, then near the bottom click ProEssentials Reference, and then see the Alphabetic Listing. The .Net Reference section is the best source for researching properties and still shows DLL specific syntax.

When installing ProEssentials, the setup program installs the ProEssentials DLL into the System32 directory, SysWow64 on 64 bit systems. It also installs a header file and import library into the C:\ProEssentials9\VC directory. The relevant files are:

  • PEGRP32G.DLL : ProEssentials Pro DLL
  • PEGRP32G.LIB : ProEssentials Pro LIB File
  • PEGRPAPI.H : ProEssentials Header File
  • PEGRPSG.DLL : ProEssentials Standard DLL
  • PEGRPSG.LIB : ProEssentials Standard LIB File

Creating a new project...

1) Start Visual Studio.NET and create a new project targeting [C++] [Windows] [Desktop] and [MFC App]. Enter a project name as name of [MyFirstMfc].

.Net charting new project C# 2019

2) After entering the name of your project, the App Wizard will ask for other settings.

MFC Charting App Settings...

3) Select your project settings to match the settings shown.

The items selected were...

  • Multiple Documents
  • Tabbed Documents
  • Document View Architecture
  • MFC Standard
  • Office 2007 Black Theme
  • Use MFC in a Shared DLL
MFC Chart control in Visual Studio vs2019

The items selected were...

  • Use a Ribbon
MFC Chart control in Visual Studio vs2019

The items selected were...

  • Printing and Print Preview
  • Common Control Manifest
MFC Chart control in Visual Studio vs2019
MFC Charting Project, Adding Existing Items...

4) First manually copy 'PEGRPAPI.H' and 'PEGRP32G.LIB' from the C:\ProEssentials9\VC demo directory to where the [MyFirstMfc] project files are located.

Note, if using the Standard version instead of Pro version, use 'PEGRPSG.LIB'.

From the top level Visual Studio menus, use [Project / Add Exiting Item...] menu to add 'PEGRPAPI.H' and 'PEGRP32G.LIB' to the [MyFirstMfc] project.

The image shows the existing files being added to your project.

C#.Net Chart property Window in VS2019
MFC Charting Project, Adding Header File...

5) Open the file 'myfirstmfcview.cpp' and near the top add the line:

#include “Pegrpapi.h“

The include statement adds the ProEssentials header file which contains constants and function declarations.

MFC Chart Component adding header file VS2019
MFC Charting Project, Adding a Window Handle for the Chart...

6) Open the file 'myfirstmfcview.h' and add the line:

HWND hPE;

The variable hPE is used to store the Window's handle for the ProEssentials chart control. The chart we create will be a standard Window; as if we called the CreateWindow API call.

Each instance of MyFirstMfcView will have its own copy of this handle.

Then within file 'myfirstmfcview.cpp', find constructor and initialize hPE to NULL.

hPE = NULL;

MFC Chart Component initialize handle to null
MFC Chart Component adding windows handle
MFC Charting Project, Adding Message handlers and Virtual Functions...

7) From the top level Visual Studio menus, use [Project / Class Wizard...] menu to open the Class Wizard dialog.

Select Class Name CMyFirstMfcView.

Select the Messages tab and double click messages...

  • WM_CREATE
  • WM_DESTROY
  • WM_ERASEBKGND
  • WM_SIZE

The image shows the message handlers added to your project. Now our view class (parent window to our chart) will look to respond to these messages.

MFC Chart adding message handlers VS2019

Select the Virtual Functions tab and double click function...

  • OnCommand

The image shows the virtual function OnCommand added to your project. Now our view class (parent window to our chart) will look to respond to WM_COMMAND messages.

MFC Chart adding virtual functions VS2019
MFC Charting Project, Adding the example code...

8) Within the recently added OnCreate, OnDestroy, OnSize, and OnCommand sections of MyFirstMfcView.cpp, add the following code that initializes an example chart. See images below for further reference.

OnCreate: creates and initialzes a chart after parent creates it's window

RECT r;
int s, p, dwColor;
float f[] = {10, 30, 20, 40, 30, 50, 15, 63, 74, 54, 25, 34};

GetClientRect(&r);

// PEcreate is similar to CreateWindow API call, returns a Window Handle //
hPE = PEcreate(PECONTROL_GRAPH, 0, &r, this->m_hWnd, 1000);
PEszset(hPE, PEP_szMAINTITLE, TEXT("Hello World"));
PEszset(hPE, PEP_szSUBTITLE, TEXT(""));
PEnset(hPE, PEP_nSUBSETS, 2); // Subsets = Rows //
PEnset(hPE, PEP_nPOINTS, 6);  // Points = Columns //

// Passing data one piece at a time //
for (s=0; s<2; s++)
{
    for (p=0; p<6; p++)
    {   // (s*6)+p or (SubsetIndex * NumberPoints) + PointIndex //
        PEvsetcellEx(hPE, PEP_faYDATA, s, p, &f[(s*6)+p]);
    }
}
// or Passing data in one call is much faster: PEvset(hPE, PEP_faYDATA, f, 12); //

PEvsetcell(hPE, PEP_szaPOINTLABELS, 0, TEXT("Jan"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 1, TEXT("Feb"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 2, TEXT("Mar"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 3, TEXT("Apr"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 4, TEXT("May"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 5, TEXT("June"));
PEvsetcell(hPE, PEP_szaSUBSETLABELS, 0, TEXT("For .Net Framework"));
PEvsetcell(hPE, PEP_szaSUBSETLABELS, 1, TEXT("or MFC, ActiveX, VCL"));
PEszset(hPE, PEP_szYAXISLABEL, TEXT("Simple Quality Rendering"));
PEszset(hPE, PEP_szXAXISLABEL, TEXT(""));
dwColor = PERGB(60, 0, 180, 0); PEvsetcell(hPE, PEP_dwaSUBSETCOLORS, 0, &dwColor);
dwColor = PERGB(180, 0, 0, 130); PEvsetcell(hPE, PEP_dwaSUBSETCOLORS, 1, &dwColor);

// Quick way to set many colors via QuickStyle property //
PEnset(hPE, PEP_bBITMAPGRADIENTMODE, FALSE);
PEnset(hPE, PEP_nQUICKSTYLE, PEQS_LIGHT_SHADOW);

PEnset(hPE, PEP_nGRAPHPLUSTABLE, PEGPT_BOTH);
PEnset(hPE, PEP_nDATAPRECISION, 0);
PEnset(hPE, PEP_bLABELBOLD, TRUE);
PEnset(hPE, PEP_nPLOTTINGMETHOD, PEGPM_BAR);
PEnset(hPE, PEP_nGRADIENTBARS, 8);
PEnset(hPE, PEP_bBARGLASSEFFECT, TRUE);
PEnset(hPE, PEP_nLEGENDLOCATION, PELL_LEFT);
PEnset(hPE, PEP_nDATASHADOWS, PEDS_3D);
PEnset(hPE, PEP_bFIXEDFONTS, TRUE);
PEnset(hPE, PEP_nFONTSIZE, PEFS_LARGE);

// You will likely set these for all charts //
PEnset(hPE, PEP_bPREPAREIMAGES, TRUE);
PEnset(hPE, PEP_bCACHEBMP, TRUE);
PEnset(hPE, PEP_nRENDERENGINE, PERE_DIRECT2D);
PEnset(hPE, PEP_bANTIALIASGRAPHICS, TRUE);
PEnset(hPE, PEP_bANTIALIASTEXT, TRUE);

// Setting this TRUE will enable Data HotSpots, //
// but we need to add code to respond to hot spot message //

PEnset(hPE, PEP_bALLOWDATAHOTSPOTS, TRUE);

// Always finish your property settings with these function calls //
PEreinitialize(hPE);
PEresetimage(hPE, 0, 0);

OnDestroy: clean up chart resource at same time parent is cleaned up

if (hPE) { PEdestroy(hPE); hPE = 0; }

OnSize: this causes chart to always fill client rect of parent

if (hPE)
{
    RECT r; GetClientRect(&r);
    ::MoveWindow(hPE, 0, 0, r.right, r.bottom, FALSE);
}

OnCommand: listen for notification message to handle hot spot

int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (wmEvent)
{
case PEWN_CLICKED:
    HOTSPOTDATA hsd; TCHAR buffer[128]; float yvalue;
    PEvget(hPE, PEP_structHOTSPOTDATA, &hsd);
    if (hsd.nHotSpotType == PEHS_DATAPOINT)
    {
        PEvgetcellEx(hPE, PEP_faYDATA, hsd.w1, hsd.w2, &yvalue);
        swprintf_s(buffer, TEXT(“DataPoint %d value %.2f“), hsd.w2, yvalue);
        ::MessageBox(this->m_hWnd, buffer, TEXT(“Hello World“), 0);
    }
    break;
}

Your project code should look similar to...

MFC Chart code window for OnCreate VS2019


MFC Chart code window for OnCreate VS2019

Success!!!

8) Save and run the project. Your project will show an image as follows. Move the mouse over a bar and click to trigger the DataHotSpot event.

This completes this walkthrough.

Please read the remaining sections within Chapter 5 and review the demo code and documentation that's installed with the eval/product.

Once installed, the demo program can be accessed via shortcut...

Start / ProEssentials v9 / PeDemo

Note that our main charting demo is replicated in WPF and Winform C#.NET,  VB.NET, VC++ MFC, Delphi, Builder all accessible from where you installed ProEssentials.   These are great for modifying an existing demo to test potential modifications before implementing within your applications.

MFC Chart Component within your visual studio software!


Thank you for researching. Please contact our engineers if you have a question.

MFC Charting Library C++ Tutorial Scientific Financial 2D Contour 3D Surface Scatter

我们的任务

我们的首要目标是通过为您的机构和终端用户提供最简单、最专业的服务,达成您的成功。

我们是工程师

ProEssentials是由需要自定义图表组件的专业电气工程师创立的。加入使用ProEssentials的顶级工程公司名单。

谢谢

感谢您成为ProEssentials的客户,也感谢您研究ProEssentials图表引擎。