YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ Example: splitter control in dialog UpdateWindow GetWindowRect GetDlgItem

By Hung Nguyen

A very simple splitter control for dialogs
 
 
Sample Image

Introduction

I'm a student and very interested in VC++. I often enter this web site to get free source code. I was in need of a splitter in a dialog. I downloaded one but it's very complex and I felt it was difficult to use the control (although it's very powerful) so I made one for myself. Maybe, it's not useful for you, but if there's only one person who thinks it's useful, I will be very happy. Sometimes you don't need good skill, just a good idea, and by this simple way a useful piece of code will be produced. My splitter control is one of this kind.

How to use the CSplitterControl class

First of all, add two files SplitterControl.h and SplitterControl.cpp to the project. Remember to add #include "splittercontrol.h" to the header file of the class which uses it.

Add member varible to the dialog class

Collapse Copy Code
 protected: 
    CSplitterControl     m_wndSplitter1; 

Now, we create the control by calling it's create function. This code would appear in the OnInitDialog or OnCreate function.

Collapse Copy Code
BOOL CSPDemoDlg::OnInitDialog()
{ 
	...
	pWnd = GetDlgItem(IDC_SPLITTER1);
	pWnd->GetWindowRect(rc);
	ScreenToClient(rc);
	m_wndSplitter1.Create(WS_CHILD | WS_VISIBLE, rc, this, IDC_SPLITTER1);
	m_wndSplitter1.SetRange(50, 50, -1);
	...

There is a tip here. Instead of calculating the rect for the splitter, we add a static control on the dialog (by resource editor), give it an ID (IDC_SPLITTER1) and make it invisible. Size it and locate in the resource editor, and then call the function GetWindowRect(rc) to move the m_wndSplitter1 to the rect.

And here is the code for resizing controls on the dialog when the user moves the splitter control.

Collapse Copy Code
//
// LRESULT CSPDemoDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	if (message == WM_NOTIFY)
	{
		if (wParam == IDC_SPLITTER1)
		{	
			SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
			DoResize1(pHdr->delta);
		}
	}
	
	return CDialog::DefWindowProc(message, wParam, lParam);
}
//
void CSPDemoDlg::DoResize1(int delta)
{
	// Change the width for m_wndType, m_lstItem, m_txtContent	
	CSplitterControl::ChangeWidth(&m_wndType, delta);
	CSplitterControl::ChangeWidth(&m_lstItem, -delta, CW_RIGHTALIGN);
	CSplitterControl::ChangeWidth(&m_txtContent, -delta, CW_RIGHTALIGN);
	Invalidate();
	UpdateWindow();
}

About the class CSplitterControl and it's functions

Here's the interface for the class CSplitterControl
Collapse Copy Code
class CSplitterControl : public CStatic
{
	// Construction
public:
	CSplitterControl();

	// Attributes
protected:
	BOOL m_bIsPressed;
	int m_nType;
	int m_nX, m_nY;
	int m_nMin, m_nMax;
	int m_nSavePos; // Save point on the lbutton down

public:
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSplitterControl)
	//}}AFX_VIRTUAL

	// Implementation
public:
	static void ChangePos(CWnd* pWnd, int dx, int dy);
	static void ChangeWidth(CWnd* pWnd, int dx, DWORD dwFlag = CW_LEFTALIGN);
	static void ChangeHeight(CWnd* pWnd, int dy, DWORD dwFlag = CW_TOPALIGN);

public:
	void SetRange(int nMin, int nMax);
	void SetRange(int nSubtraction, int nAddition, int nRoot);
	int GetStyle();
	int SetStyle(int nStyle = SPS_VERTICAL);
	void Create(DWORD dwStyle, const CRect& rect, CWnd* pParent, UINT nID);
	virtual ~CSplitterControl();

	// Generated message map functions
protected:
	virtual void DrawLine(CDC* pDC, int x, int y);
	void MoveWindowTo(CPoint pt);
	//{{AFX_MSG(CSplitterControl)
	afx_msg void OnPaint();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

// this struct is sent as lparam in WM_NOTIFY message 
typedef struct SPC_NMHDR
{
	NMHDR hdr;
	int delta; // delta : the different position of the splitter before and 
                    // after being moved.
} SPC_NMHDR;

Conclusion

Well, that's all about my code. Maybe, the explanation is not very clear, but I hope you'll find it easy to use. No special skill, you see. Very simple. Thanks for reading my article. Please give your ideas as to whether you like or hate it.
 

 

 

 

Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net