分享

CGridListCtrlEx使用说明

 紫殿 2016-10-10
将CGridListCtrlEx文件夹放入项目文件内并载入
// stdafx.h 文件
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#pragma once

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0501 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif

#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif

#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0501 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0501 // Change this to the appropriate value to target IE 5.0 or later.
#endif

#if _MSC_VER < 1300
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 // Uncomment this if using VC6 without platform SDK
#endif


#ifndef UNICODE
#define CGRIDLISTCTRLEX_GROUPMODE
#endif

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit

#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

#pragma warning( disable:4514 ) // warning C4514: unreferenced inline function has been remove
#pragma warning( disable:4710 ) // warning C4710: function not inlined
#pragma warning( disable:4711 ) // warning C4711: function selected for automatic inline expansion
#pragma warning( disable:4820 ) // warning C4820: X bytes padding added after data member

#pragma warning( push )
#pragma warning( disable:4548 ) // warning C4548: expression before comma has no effect; expected expression with side-effect
#pragma warning( disable:4812 ) // warning C4812: obsolete declaration style: please use '_CIP<_Interface,_IID>::_CIP' instead
#pragma warning( disable:4996 ) // warning C4996: This function or variable may be unsafe.
#pragma warning( disable:4005 ) // warning C4005: '_WIN32_WINDOWS' : macro redefinition
#pragma warning( disable:4668 ) // warning C4668: '__midl' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
#pragma warning( disable:4820 ) // warning C4820: X bytes padding added after data member
#pragma warning( disable:4619 ) // warning C4619: #pragma warning : there is no warning number
#pragma warning( disable:4625 ) // warning C4625: copy constructor could not be generated because a base class copy constructor is inaccessible
#pragma warning( disable:4626 ) // warning C4626: assignment operator could not be generated because a base class assignment operator is inaccessible
#pragma warning( disable:4365 ) // warning C4365: '=' : conversion from 'int' to 'size_t', signed/unsigned mismatch
#pragma warning( disable:4244 ) // warning C4244: 'return' : conversion from 'const time_t' to 'LONG_PTR', possible loss of data
#pragma warning( disable:4263 ) // warning C4263: member function does not override any base class virtual member function
#pragma warning( disable:4264 ) // warning C4264: no override available for virtual member function from base; function is hidden
#pragma warning( disable:4917 ) // warning C4917: a GUID can only be associated with a class, interface or namespace
#pragma warning( disable:4555 ) // warning C4555: expression has no effect; expected expression with side-effect
#pragma warning( disable:4640 ) // warning C4640: construction of local static object is not thread-safe
#pragma warning( disable:4571 ) // warning C4571: Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught


//MFC文件对话框
#include "CGridListCtrlEx\CGridColumnTraitDateTime.h"
#include "CGridListCtrlEx\CGridColumnTraitEdit.h"
#include "CGridListCtrlEx\CGridColumnTraitCombo.h"
#include "CGridListCtrlEx\CGridColumnTraitHyperLink.h"
#include "CGridListCtrlEx\CGridColumnTrait.h"
#include "CGridListCtrlEx\CGridRowTraitXP.h"
#include "CGridListCtrlEx\ViewConfigSection.h"
#include "CGridListCtrlEx\CGridRowTraitText.h"
#include "CGridListCtrlEx\CGridRowTraitVisitor.h"
#include "CGridListCtrlEx\CGridRowTraitText.h"

BOOL CBender_Auto::OnInitDialog()
{
CDialogEx::OnInitDialog();

// TODO:  Add extra initialization here
CGridColumnTrait* pTrait1;
CGridColumnTrait* pTrait2;
CGridColumnTraitEdit* pTrait3;
CGridColumnTraitEdit* pTrait4;
CGridColumnTraitEdit* pTrait5;
CGridColumnTraitEdit* pTrait6;
CGridColumnTraitEdit* pTrait7;
CGridColumnTrait* pTrait8;
CGridColumnTrait* pTrait9;
CGridRowTraitXP* pRowTrait;

DialogFont.CreatePointFont(130,_T("Arial"));
// Give better margin to editors
m_Order.SetCellMargin(1.2);
pRowTrait = new CGridRowTraitXP;//CGridRowTraitXP,CGridRowTraitText
m_Order.SetDefaultRowTrait(pRowTrait);
m_Order.EnableVisualStyles(true);
m_Order.SetFont(&DialogFont);
// Create Columns
m_Order.InsertHiddenLabelColumn(); // Requires one never uses column 0
CString title;
CString temp;
int GridWidth;

m_ImageList.Create(20, 20, ILC_COLOR16 | ILC_MASK, 1, 0);
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_FLGDEN));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_FLGFRAN));
int nStateImageIdx = CGridColumnTraitImage::AppendStateImages(m_Order, m_ImageList); // Add checkboxes
m_Order.SetImageList(&m_ImageList, LVSIL_SMALL);

for(int col = 0; col < 9 ; ++col)
{
CGridColumnTrait* pTrait = NULL;

if (col == 0) // Country
{
pTrait1 = new CGridColumnTrait;
title = _T("序号");
GridWidth = 50;
pTrait = pTrait1;
}
else if(col == 1)
{
title = _T("状态");
pTrait2 = new CGridColumnTraitText;
GridWidth = 70;
pTrait = pTrait2;
}
else if (col == 2) // City
{
title = _T("订单号");
pTrait3 = new CGridColumnTraitEdit;
GridWidth = 100;
pTrait = pTrait3;
}
else if (col == 3) // Year won
{
title = _T("板型");
pTrait4 = new CGridColumnTraitEdit;
GridWidth = 100;
pTrait = pTrait4;
}
else if (col==4) // Year won
{
title = _T("长度(mm)");
pTrait5 = new CGridColumnTraitEdit;
pTrait5->SetSortFormatNumber(true);
GridWidth = 90;
pTrait = pTrait5;
}
else if (col==5) // Year won
{
title = _T("片数");
pTrait6 = new CGridColumnTraitEdit;
GridWidth = 90;
pTrait = pTrait6;
}
else if (col==6) // Year won
{
title = _T("打包");
// Creates an image column, that can switch between the 2 images
pTrait7 = new CGridColumnTraitEdit;//CGridColumnTraitImage(nStateImageIdx, 0);
pTrait7->AddImageIndex(nStateImageIdx, _T(""), false);
pTrait7->AddImageIndex(nStateImageIdx + 1, _T(""), true);
GridWidth = 50;
pTrait = pTrait7;
}
else if (col==7) // Year won
{
title = _T("开始时间");
pTrait8 = new CGridColumnTrait;
GridWidth = 100;
pTrait = pTrait8;
}
else if (col==8) // Year won
{
title = _T("结束时间");
pTrait9 = new CGridColumnTrait;
GridWidth = 100;
pTrait = pTrait9;
}

m_Order.InsertColumnTrait(col + 1, title, LVCFMT_CENTER, GridWidth, col, pTrait);
}

//插入内容
int nItem = 0;

for(size_t rowId = 0; rowId < 1000 ; ++rowId)
{
nItem = m_Order.InsertItem(++nItem, _T("GXW"));
m_Order.SetItemData(nItem, rowId);

for(int col = 0; col < 9 ; ++col)
{
int nCellCol = col+1; // +1 because of hidden column
//const CString& strCellText = m_DataModel.GetCellText(rowId, col);
switch(col)
{
case 0:
temp .Format(_T("%d"), rowId + 1);
m_Order.SetItemText(nItem, nCellCol, temp);

break;
case 1:
temp = _T("等待中");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 2:
temp = _T("2012121201");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 3:
temp = _T("1.2mm,冷轧板");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 4:
temp = _T("1500");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 5:
temp = _T("1000");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 6:
m_Order.SetItemText(nItem, nCellCol, _T(""));
m_Order.SetCellImage(nItem, nCellCol, nStateImageIdx + 1); // check item
break;
case 7:
temp = _T("2016/10/09 24:00:00");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
case 8:
temp = _T("2016/10/10 24:04:02");
m_Order.SetItemText(nItem, nCellCol, temp);
break;
break;
default:
m_Order.SetItemText(nItem, nCellCol, _T("出错"));
break;
}
}

//m_Order.SetCellImage(nItem, 1, nItem); // Assign flag-images
}

return TRUE;  // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}


BOOL CBender_Auto::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_ImageList.Detach();
DialogFont.DeleteObject();

return CDialogEx::DestroyWindow();
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多