In-depth introduction to CChart one lesson per day-Class 1 Fashion plus trends, DirectUI's colorful interface library

Source: Internet
Author: User


Stupid is a regular person who has never caught a cold catch on trendy things. Today, more than a dozen percent has passed in the 21st century, and he is still using VC6 in the 20th century. However, the IT field is a world where the waves go forward and the waves die on the beach. So far, dummies have been rejected by the IT field.

Although stupid is an old saying, it is also possible to catch up with the trend occasionally. In recent years, DirectUI has become quite popular. I also learned a little about it, and I think this programming idea is worth advocating.

Currently, the DirectUI library is an excellent commercial library. The Open Source library DuiLib and the colorful interface library are stupid.

DuiLib is an excellent domestic open source DirectUI library. I am stupid to run the example on VS2010, but the VC6 won't work. I don't have much access to its code, so I feel a little uncomfortable.

The colorful interface library is another outstanding process open source DirectUI library. It's very easy to use this library, not only on VS2010, but also on dear VC6. So she was so stupid that she decided to keep up with the lottery.

After a period of debugging, CChart and the colorful interface library are now perfectly compatible.

It should be noted that. The colorful interface library is based on the windowless idea. There is only one main window in it, and other Windows are self-painted. The CChart is also the original Windows programming idea, and the operations in it are based on Windows. When CChart falls in love with colorful colors, the crystallization of love is a mixed blood. The only problem is that the pop-up dialog box with CChart is different from the pop-up dialog box with colorful colors. If you do not need the interaction function or the dialog box is not displayed, there will be no different styles.

The following is a clumsy demonstration of the entire process of CChart's pursuit of a young girl's colorful girl.

As a preparation, You need to download the latest colorful library from www.xcgui.com.

Now, letsgo!

Step 1: Use VC to create a Win32Application project named Lesson17. Note: In the wizard, select Anemptyproject, that is, an empty project.

Step 2: map the five library files of CChart. h. PlotDll_d.lib, PlotDll_d.dll, and PlotDll. lib, PlotDll. copy the dll to the Lesson17 folder, decompress the colorful compressed package, and find xcgui In the lib directory. h. xcguid. lib, xcguid. dll, xcgui. lib, xcgui. dll files are also copied to the Lesson17 folder.

Step 3: Create a New Lesson17.cpp file in VC, add it to the project, and enter the following content copied from the colorful help document in this file.

// Contains colorful interface library files
#include "xcgui.h"
#ifdef _DEBUG
#pragma comment (lib, "XCGUId.lib")
#else
#pragma comment (lib, "XCGUI.lib")
#endif

// CXEventMsg: C ++ message event interface class
// CMyWnd: my window class
class CMyWnd: public CXEventMsg
{
public:
HWINDOW m_hWindow; // window handle
    
BOOL Create () // Create window and button
{
m_hWindow = XWnd_CreateWindow (0,0,400,300, L "Colorful interface library-window"); // Create window
if (m_hWindow)
{
XWnd_ShowWindow (m_hWindow, SW_SHOW); // Show window
return true;
}
return false;
}
};

int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI (); // Init
Ranch
CMyWnd MyWnd;
if (MyWnd.Create ())
{
XRunXCGUI (); // Run
}
return 0;
}
Compile and run. The effect is as follows.

650) this. width = 650; "src =" http://img.blog.csdn.net/20130920000731765? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>

The colorful window is coming out! Next we will start our work in this window.

Step 4: add the header file and library file of CChart.

#include "Chart.h"
#ifdef _DEBUG
#pragma comment(lib, "PlotDll_d.lib")
#else
#pragma comment(lib, "PlotDll.lib")
#endif
Step 5: add the Math Library header file.
#include <math.h> 
Step 6: Define the CChart variable. In the HWINDOWm_hWindow; line, enter the following code.
CChart m_Chart;
Step 7: Modify the OnCreate function. The change is as follows.
BOOL Create () // Create window and button
{
m_hWindow = XWnd_CreateWindow (0,0,800,600, L "Colorful interface library-window"); // Create window
if (m_hWindow)
{
HWND hWnd = XWnd_GetHWnd (m_hWindow);
Ranch
m_Chart.SetType (kTypeXY, hWnd);
Ranch
const int nLen = 501;
double pX [nLen], pY [nLen];
int i, dataID;
for (i = 0; i <nLen; i ++)
{
pX [i] = 2.0 / (nLen-1.0) * i;
pY [i] = 2 * sin (pX [i] * 8.0 * myPi) + (2.0 * rand () / RAND_MAX-1.0) * 0.3;
}
dataID = m_Chart.AddCurve (pX, pY, nLen);
m_Chart.SetDataTitle ("Test data 1", 0, 0);
Ranch
for (i = 0; i <nLen; i ++)
{
pX [i] = 2.0 / (nLen-1.0) * i;
pY [i] = (i-nLen / 2.0) * (i-nLen / 2.0) /nLen/nLen*20.0 + (2.0 * rand () / RAND_MAX-1.0) * 0.1;
}
dataID = m_Chart.AddCurve (pX, pY, nLen);
m_Chart.SetDataTitle ("Test data 2", 1, 0);
m_Chart.SetTitle ("Draw in the colorful interface library");
Ranch
XCGUI_RegWndMessage (m_hWindow, WM_PAINT, & CMyWnd :: OnWndPaint);
XCGUI_RegWndMessage (m_hWindow, WM_LBUTTONDOWN, & CMyWnd :: OnWndLButtonDown);
XCGUI_RegWndMessage (m_hWindow, WM_LBUTTONUP, & CMyWnd :: OnWndLButtonUp);
XCGUI_RegWndMessage (m_hWindow, XWM_MOUSEDBCLICK, & CMyWnd :: OnWndLButtonDblClk);
XCGUI_RegWndMessage (m_hWindow, WM_MOUSEMOVE, & CMyWnd :: OnWndMouseMove);
XCGUI_RegWndMessage (m_hWindow, WM_KEYDOWN, & CMyWnd :: OnWndKeyDown);
XCGUI_RegWndMessage (m_hWindow, WM_RBUTTONDOWN, & CMyWnd :: OnWndRButtonDown);
Ranch
XWnd_ShowWindow (m_hWindow, SW_SHOW); // Show window
return true;
}
return false;
}
Step 8: Create an OnPaint function to implement the plotting function.
RECT rect;
int dx, dy;
	
BOOL OnWndPaint(HWINDOW hWindow, HDRAW hDraw)
{
	XWnd_GetDrawRect(hWindow, &rect);
	HDC hDC = XDraw_GetHDC_(hDraw);

	XDraw_GetOffset_(hDraw, &dx, &dy);
	rect.left += dx;
	rect.top += dy;
	rect.right -= dx;
	rect.bottom -= dx;
	m_Chart.OnDraw(hDC, rect);
	return FALSE;
}


Note that several variables are defined before OnWndPaint. These variables are useful in the OnWndPaint function. The purpose of defining them outside the function is to be used by the subsequent message response function.

In the colorful interface library, you cannot draw directly on the customer area of the main window in the colorful, and an offset must be added. Because the entire colorful main window is the customer area, and its title bar and other elements are drawn in the customer area, the drawing directly in the main window will overlap with the title bar, border and other elements.

The above code shows how to obtain the customer zone HDC from the colorful display and add the offset.

Step 9: Implement Message Processing for interactive functions. The Code is as follows.

BOOL OnWndLButtonDown(HWINDOW hWindow,UINT flags,POINT *pPt)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	POINT point = *pPt;
	point.x += dx;
	point.y += dy;
	
	if(m_Chart.OnLButtonDown(hWnd, point))
	{
		XWnd_RedrawWnd(hWindow);
	}
	return FALSE;
}
BOOL OnWndLButtonUp(HWINDOW hWindow,UINT flags,POINT *pPt)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	POINT point = *pPt;
	point.x += dx;
	point.y += dy;
	
	if(m_Chart.OnLButtonUp(hWnd, point))
	{
		XWnd_RedrawWnd(hWindow);
	}
	return FALSE;
}
BOOL OnWndLButtonDblClk(HWINDOW hWindow,POINT *pPt)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	POINT point = *pPt;
	point.x += dx;
	point.y += dy;
	
	if(GetCapture())
	{
		ReleaseCapture();
	}
	
	if(m_Chart.OnLButtonDblClk(hWnd, point))
	{
		XWnd_RedrawWnd(hWindow);
	}
		
	return FALSE;
}
BOOL OnWndMouseMove(HWINDOW hWindow,UINT flags,POINT *pPt)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	POINT point = *pPt;
	point.x += dx;
	point.y += dy;
	
	if(m_Chart.OnMouseMove(hWnd, point))
	{
		XWnd_RedrawWnd(hWindow);
	}
	return FALSE;
}
BOOL OnWndKeyDown(HWINDOW hWindow,WPARAM wParam,LPARAM lParam)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	UINT	key = wParam;
	
	if(m_Chart.OnKeyDown(hWnd, key))
	{
		XWnd_RedrawWnd(hWindow);
	}
	return FALSE;
}
BOOL OnWndRButtonDown(HWINDOW hWindow,UINT flags,POINT *pPt)
{
	HWND hWnd = XWnd_GetHWnd(hWindow);
	POINT point = *pPt;
	point.x += dx;
	point.y += dy;
	ClientToScreen(hWnd, &point);
	
	if(m_Chart.OnContextMenu(NULL, hWnd, point))
	{
		XWnd_RedrawWnd(hWindow);
	}
	return FALSE;
}
 


The above Code uses the message processing function of CChart to process various messages based on the actual colorful conditions.

OK. You are ready to close the ticket. Let's look at our labor results.

Haha, it's really good.

Next let's take a look at the right-click menu of CChart ,.

It is not changed.

Let's see the CChart dialog box.

It is a mixed-race model.


The code in this lesson seems to be many and can be copied. The actual amount of code is not large, and the meaning of the code is very easy to understand.

So far, our handsome guy CChart has finally succeeded in holding on to the colorful lover in his dream. Yeah!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.