CustomGridListControl++Shieory

// HeaderCtrlCl.cpp : 实现文件
//


#include "stdafx.h"
#include "HeaderCtrlCl.h"




// CHeaderCtrlCl


IMPLEMENT_DYNAMIC(CHeaderCtrlCl, CHeaderCtrl)


CHeaderCtrlCl::CHeaderCtrlCl()
: m_R(171)
, m_G(199)
, m_B(235)
, m_Gradient(8)
{
m_Format = "";
m_Height = 1;
m_fontHeight = 15;
m_fontWith = 0;
m_color = RGB(0,0,0);
}


CHeaderCtrlCl::~CHeaderCtrlCl()
{
}




BEGIN_MESSAGE_MAP(CHeaderCtrlCl, CHeaderCtrl)
ON_WM_PAINT()
ON_MESSAGE(HDM_LAYOUT, OnLayout)
END_MESSAGE_MAP()






// CHeaderCtrlCl 消息处理程序






void CHeaderCtrlCl::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CHeaderCtrl::OnPaint()
int nItem; 
nItem = GetItemCount();//得到有几个单元 
CPen pen(PS_SOLID,3,RGB(0,64,64));
dc.SelectObject(&pen);
    
for(int i = 0; i<nItem;i ++) 

CRect tRect;
GetItemRect(i,&tRect);//得到Item的尺寸


dc.Rectangle(&tRect); //填充背
int R = m_R,G = m_G,B = m_B;
CRect nRect(tRect);//拷贝尺寸到新的容器中 
nRect.left;//留出分割线的地方 
//绘制立体背景 




for(int j = tRect.bottom;j>=tRect.top;j--) 

nRect.bottom = nRect.top+1; 
CBrush _brush; 
_brush.CreateSolidBrush(RGB(R,G,B));//创建画刷 
dc.SelectObject(&_brush);
//_brush.CreateSolidBrush(RGB(84,20,10));//创建画刷 

dc.FillRect(&nRect,&_brush); //填充背景 
_brush.DeleteObject(); //释放画刷 
R-=m_Gradient;G-=m_Gradient;B-=m_Gradient;
if (R<0)R = 0;
if (G<0)G = 0;
if (B<0)B= 0;
nRect.top = nRect.bottom; 

dc.SetBkMode(TRANSPARENT);
CFont nFont ,* nOldFont; 
//dc.SetTextColor(RGB(250,50,50)); 
dc.SetTextColor(m_color);
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体 
nOldFont = dc.SelectObject(&nFont);

UINT nFormat = 1;
if (m_Format[i]=='0')
{
nFormat = DT_LEFT;
tRect.left+=3;
}
else if (m_Format[i]=='1')
{
nFormat = DT_CENTER;
}
else if (m_Format[i]=='2')
{
nFormat = DT_RIGHT;
tRect.right-=3;
}
TEXTMETRIC metric;
dc.GetTextMetrics(&metric);
int ofst = 0;
ofst = tRect.Height() - metric.tmHeight;
tRect.OffsetRect(0,ofst/2);
dc.DrawText(m_HChar[i],&tRect,nFormat);
dc.SelectObject(nOldFont); 
nFont.DeleteObject(); //释放字体 

pen.DeleteObject();
//画头部剩余部分
// CRect rtRect;
// CRect clientRect;
// GetItemRect(nItem - 1,rtRect);
// GetClientRect(clientRect);
// rtRect.left = rtRect.right+1;
// rtRect.right = clientRect.right;
// int R = m_R,G = m_G,B = m_B;
// CRect nRect(rtRect);
// //绘制立体背景 
// for(int j = rtRect.top;j<=rtRect.bottom;j++) 
//
// nRect.bottom = nRect.top+1; 
// CBrush brush; 
// _brush.CreateSolidBrush(RGB(R,G,B));//创建画刷 
// dc.FillRect(&nRect,&_brush); //填充背景 
// _brush.DeleteObject(); //释放画刷 
// R-=m_Gradient;G-=m_Gradient;B-=m_Gradient;
// if (R<0)R = 0;
// if (G<0)G = 0;
// if (B<0)B= 0;
// nRect.top = nRect.bottom; 
//
}
LRESULT CHeaderCtrlCl::OnLayout( WPARAM wParam, LPARAM lParam )
{
LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam); 
HD_LAYOUT &hdl = *( HD_LAYOUT * ) lParam; 
RECT *prc = hdl.prc; 
WINDOWPOS *pwpos = hdl.pwpos; 


//表头高度为原来1.5倍,如果要动态修改表头高度的话,将1.5设成一个全局变量 
int nHeight = (int)(pwpos->cy * m_Height);
pwpos->cy = nHeight; 
prc->top = nHeight; 
return lResult; 

}


#pragma once




// CHeaderCtrlCl


class CHeaderCtrlCl : public CHeaderCtrl
{
DECLARE_DYNAMIC(CHeaderCtrlCl)


public:
CHeaderCtrlCl();
virtual ~CHeaderCtrlCl();


protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
CStringArray m_HChar;
CString m_Format; //表示对齐类型的整型数组,0表示左对齐,1表示中间对齐,2表示右对齐
public:
int m_R;
int m_G;
int m_B;
int m_Gradient;// 画立体背景,渐变系数
float m_Height;  //表头高度,这是倍数,
int m_fontHeight; //字体高度
int m_fontWith;   //字体宽度
COLORREF m_color;
LRESULT OnLayout( WPARAM wParam, LPARAM lParam );
};









、、、、、、、、、、、、、、、、、

// ListCtrlCl.cpp : 实现文件
//


#include "stdafx.h"
#include "ListCtrlCl.h"


struct stColor
{
int nRow;
int nCol;
COLORREF rgb;
};
// CListCtrlCl


IMPLEMENT_DYNAMIC(CListCtrlCl, CListCtrl)


CListCtrlCl::CListCtrlCl()
: m_nRowHeight(0)
, m_fontHeight(12)
, m_fontWith(0)
{
m_color = RGB(0,0,0);
}


CListCtrlCl::~CListCtrlCl()
{
}




BEGIN_MESSAGE_MAP(CListCtrlCl, CListCtrl)
ON_WM_MEASUREITEM()
ON_WM_MEASUREITEM_REFLECT()
END_MESSAGE_MAP()






// CListCtrlCl 消息处理程序






void CListCtrlCl::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
ModifyStyle(0,LVS_OWNERDRAWFIXED);
CListCtrl::PreSubclassWindow();
CHeaderCtrl *pHeader = GetHeaderCtrl();
m_Header.SubclassWindow(pHeader->GetSafeHwnd());
}


void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{


// TODO:  添加您的代码以绘制指定项
TCHAR lpBuffer[256];


LV_ITEM lvi;


lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ; 
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));


LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT;


CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rtClient;
GetClientRect(&rtClient);

CPen pen(PS_SOLID,1,RGB(0,64,64));
pDC->SelectObject(&pen);
//
//CPen pen(PS_SOLID,1,RGB(200,200,200));
//CPen* pOldPen = pDC->SelectObject(&pen);


CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
pDC->SelectObject(pBrush);
pDC->Rectangle(&rtClient);
//pDC->MoveTo(lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.bottom-1);
    //pDC->LineTo(lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom-1);
//
    int borderx=0;
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 ) 
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left; 
}


CRect rcItem;   
if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))   
continue;   


::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CRect rcTemp;
rcTemp = rcItem;


//
//for( int i = 0; i < nColumnCount; i++ )
{

borderx += GetColumnWidth( nCol );

if( borderx >= rtClient.right ) break;

// Draw the line.
pDC->MoveTo( borderx-1, rtClient.top);
pDC->LineTo( borderx-1, rtClient.bottom );
}


// First get the height
if( !GetItemRect( 0, &rtClient, LVIR_BOUNDS ))
return;

int height = rtClient.bottom - rtClient.top;

GetClientRect( &rtClient );
int width = rtClient.right;


for( int row = 0; row <= GetCountPerPage(); row++ )
{
pDC->MoveTo( 0, rcTemp.top + m_nRowHeight*row);
pDC->LineTo( width, rcTemp.top + m_nRowHeight*row );
}


//
if (nCol==0)
{
rcTemp.left -=2;
}


// if ( lpDrawItemStruct->itemState & ODS_SELECTED )
// {
// pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ;
// pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ;
// pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
// }
// else
// {
// COLORREF color;
// color = GetBkColor();
// pDC->FillSolidRect(rcTemp,color);
// 
// if (FindColColor(nCol,color))
// {
// pDC->FillSolidRect(rcTemp,color);
// }
// if (FindItemColor(nCol,lpDrawItemStruct->itemID,color))
// {
// pDC->FillSolidRect(rcTemp,color);
// }
//
// //pDC->SetTextColor(m_color);
// }


pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));


UINT   uFormat    = DT_CENTER ;
if (m_Header.m_Format[nCol]=='0')
{
uFormat = DT_LEFT;
}
else if (m_Header.m_Format[nCol]=='1')
{
uFormat = DT_CENTER;
}
else if (m_Header.m_Format[nCol]=='2')
{
uFormat = DT_RIGHT;
}
TEXTMETRIC metric;
pDC->GetTextMetrics(&metric);
int ofst;
ofst = rcItem.Height() - metric.tmHeight;
rcItem.OffsetRect(0,ofst/2);
pDC->SetTextColor(m_color);
COLORREF color;
if (FindColTextColor(nCol,color))
{
pDC->SetTextColor(color);
}
if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->SetTextColor(color);
}
CFont nFont ,* nOldFont; 
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体 
nOldFont = pDC->SelectObject(&nFont);
DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), 
&rcItem, uFormat) ;


pDC->SelectStockObject(SYSTEM_FONT) ;
}


pen.DeleteObject();
}


void CListCtrlCl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值


CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
void CListCtrlCl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (m_nRowHeight>0)
{
lpMeasureItemStruct->itemHeight = m_nRowHeight;
}
}
int CListCtrlCl::InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat /* = LVCFMT_LEFT */, int nWidth /* = -1 */, int nSubItem /* = -1 */)
{
m_Header.m_HChar.Add(lpszColumnHeading);
if (nFormat==LVCFMT_LEFT)
{
m_Header.m_Format = m_Header.m_Format + "0";
}
else if (nFormat==LVCFMT_CENTER)
{
m_Header.m_Format = m_Header.m_Format + "1";
}
else if (nFormat==LVCFMT_RIGHT)
{
m_Header.m_Format = m_Header.m_Format + "2";
}
else
{
m_Header.m_Format = m_Header.m_Format + "1";
}
return CListCtrl::InsertColumn(nCol,lpszColumnHeading,nFormat,nWidth,nSubItem);
}
// Gradient - 渐变系数,立体背景用,不用渐变设为0
void CListCtrlCl::SetHeaderBKColor(int R, int G, int B, int Gradient) //设置表头背景色
{
m_Header.m_R = R;
m_Header.m_G = G;
m_Header.m_B = B;
m_Header.m_Gradient = Gradient;
}


// 设置表头高度
void CListCtrlCl::SetHeaderHeight(float Height) //设置表头高度
{
m_Header.m_Height = Height;
}
bool CListCtrlCl::FindColColor(int col,COLORREF &color) //查找列颜色
{
int flag = 0;
for (POSITION pos = m_ptrListCol.GetHeadPosition();pos!=NULL;)
{
stColor *pColor = (stColor*)m_ptrListCol.GetNext(pos);
if (pColor->nCol==col)
{
flag = 1;
color = pColor->rgb;
break;
}
}
if (1==flag)
{
return true;
}
return false;
}
bool CListCtrlCl::FindItemColor(int col,int row,COLORREF &color) //查找颜色
{
int flag = 0;
for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
{
stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
if (pColor->nCol==col&&pColor->nRow==row)
{
flag = 1;
color = pColor->rgb;
break;
}
}
if (1==flag)
{
return true;
}
return false;
}
void CListCtrlCl::SetColColor(int col,COLORREF color) //设置列颜色
{
stColor *pColor  = new stColor;
pColor->nCol = col;
pColor->rgb = color;
m_ptrListCol.AddTail(pColor);
}
void CListCtrlCl::SetItemColor(int col,int row,COLORREF color) //设置格子颜色
{
stColor *pColor  = new stColor;
pColor->nCol = col;
pColor->nRow = row;
pColor->rgb = color;
m_ptrListItem.AddTail(pColor);
}
void CListCtrlCl::SetRowHeigt(int nHeight) //高置行高
{
m_nRowHeight = nHeight;


CRect rcWin;
GetWindowRect(&rcWin);
WINDOWPOS wp;
wp.hwnd = m_hWnd;
wp.cx = rcWin.Width();
wp.cy = rcWin.Height();
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
}
void CListCtrlCl::SetHeaderFontHW(int nHeight,int nWith) //设置头部字体宽和高
{
m_Header.m_fontHeight = nHeight;
m_Header.m_fontWith = nWith;
}
void CListCtrlCl::SetHeaderTextColor(COLORREF color) //设置头部字体颜色
{
m_Header.m_color = color;
}
BOOL CListCtrlCl::SetTextColor(COLORREF cr)  //设置字体颜色
{
m_color = cr;
return TRUE;
}
void CListCtrlCl::SetFontHW(int nHeight,int nWith) //设置字体高和宽
{
m_fontHeight = nHeight;
m_fontWith = nWith;
}
void CListCtrlCl::SetColTextColor(int col,COLORREF color)
{
stColor *pColor = new stColor;
pColor->nCol = col;
pColor->rgb = color;
m_colTextColor.AddTail(pColor);
}
bool CListCtrlCl::FindColTextColor(int col,COLORREF &color)
{
int flag = 0;
for (POSITION pos = m_colTextColor.GetHeadPosition();pos!=NULL;)
{
stColor *pColor = (stColor*)m_colTextColor.GetNext(pos);
if (pColor->nCol==col)
{
flag = 1;
color = pColor->rgb;
break;
}
}
if (1==flag)
{
return true;
}
return false;
}
bool CListCtrlCl::FindItemTextColor(int col,int row,COLORREF &color)
{
int flag = 0;
for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
{
stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
if (pColor->nCol==col&&pColor->nRow==row)
{
flag = 1;
color = pColor->rgb;
break;
}
}
if (1==flag)
{
return true;
}
return false;
}
void CListCtrlCl::SetItemTextColor(int col,int row,COLORREF color)
{
stColor *pColor = new stColor;
pColor->nCol = col;
pColor->nRow = row;
pColor->rgb = color;
m_ItemTextColor.AddTail(pColor);
}


#pragma once
#include "HeaderCtrlCl.h"
// CListCtrlCl


class CListCtrlCl : public CListCtrl
{
DECLARE_DYNAMIC(CListCtrlCl)


public:
CHeaderCtrlCl m_Header;
CListCtrlCl();
virtual ~CListCtrlCl();


protected:
DECLARE_MESSAGE_MAP()
virtual void PreSubclassWindow();
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
public:
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
public:
// 行高
int m_nRowHeight;
int InsertColumn(int nCol, LPCTSTR lpszColumnHeading,
int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1);
public:
// Gradient - 渐变系数,立体背景用,不用渐变设为0
void SetHeaderBKColor(int R, int G, int B, int Gradient);
public:
// 设置表头高度
void SetHeaderHeight(float Height);
CPtrList m_ptrListCol;  //保存列颜色
CPtrList m_ptrListItem; //保存Item颜色表
CPtrList m_colTextColor; //保存列字体颜色
CPtrList m_ItemTextColor; //保存单元格字体颜色
bool FindColColor(int col ,COLORREF &color); //查找列颜色
bool FindItemColor(int col,int row,COLORREF &color);
bool FindColTextColor(int col,COLORREF &color); //查找列字体颜色
bool FindItemTextColor(int col,int row,COLORREF &color);
void SetColColor(int col,COLORREF color);  //设置列颜色
void SetItemColor(int col,int row,COLORREF color); //设置Item颜色
void SetColTextColor(int col,COLORREF color);   //设置列文本颜色
void SetItemTextColor(int col,int row,COLORREF color);
void SetRowHeigt(int nHeight); //设置行高
void SetHeaderFontHW(int nHeight,int nWith); //设置表头字体大小
void SetHeaderTextColor(COLORREF color);
COLORREF m_color;
BOOL SetTextColor(COLORREF cr);
void SetFontHW(int nHeight,int nWith);  //设置字体的高和宽
public:
// 字体高度
int m_fontHeight;
public:
// 字体宽度
int m_fontWith;
};



、、、、、、、、、、、、、、、、、、、、、、、、

// ListCtrlOwnerDraw.cpp : Defines the class behaviors for the application.
//


#include "stdafx.h"
#include "ListCtrlOwnerDraw.h"
#include "ListCtrlOwnerDrawDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/
// CListCtrlOwnerDrawApp


BEGIN_MESSAGE_MAP(CListCtrlOwnerDrawApp, CWinApp)
//{{AFX_MSG_MAP(CListCtrlOwnerDrawApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()


/
// CListCtrlOwnerDrawApp construction


CListCtrlOwnerDrawApp::CListCtrlOwnerDrawApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}


/
// The one and only CListCtrlOwnerDrawApp object


CListCtrlOwnerDrawApp theApp;


/
// CListCtrlOwnerDrawApp initialization


BOOL CListCtrlOwnerDrawApp::InitInstance()
{
AfxEnableControlContainer();


// Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.


#ifdef _AFXDLL
Enable3dControls();// Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();// Call this when linking to MFC statically
#endif


CListCtrlOwnerDrawDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}


// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}




// ListCtrlOwnerDraw.h : main header file for the LISTCTRLOWNERDRAW application
//


#if !defined(AFX_LISTCTRLOWNERDRAW_H__B831C53D_5B53_4A36_9EF4_8A160521D2EA__INCLUDED_)
#define AFX_LISTCTRLOWNERDRAW_H__B831C53D_5B53_4A36_9EF4_8A160521D2EA__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif


#include "resource.h" // main symbols


/
// CListCtrlOwnerDrawApp:
// See ListCtrlOwnerDraw.cpp for the implementation of this class
//


class CListCtrlOwnerDrawApp : public CWinApp
{
public:
CListCtrlOwnerDrawApp();


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListCtrlOwnerDrawApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL


// Implementation


//{{AFX_MSG(CListCtrlOwnerDrawApp)
// NOTE - the ClassWizard will add and remove member functions here.
//    DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};




/


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_LISTCTRLOWNERDRAW_H__B831C53D_5B53_4A36_9EF4_8A160521D2EA__INCLUDED_)


、、、、、、、、、、、、、、、、、、

// ListCtrlOwnerDrawDlg.cpp : implementation file
//


#include "stdafx.h"
#include "ListCtrlOwnerDraw.h"
#include "ListCtrlOwnerDrawDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/
// CAboutDlg dialog used for App About


class CAboutDlg : public CDialog
{
public:
CAboutDlg();


// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA


// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
//}}AFX_VIRTUAL


// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}


void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/
// CListCtrlOwnerDrawDlg dialog


CListCtrlOwnerDrawDlg::CListCtrlOwnerDrawDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListCtrlOwnerDrawDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListCtrlOwnerDrawDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CListCtrlOwnerDrawDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListCtrlOwnerDrawDlg)
DDX_Control(pDX, IDC_LIST_DATA, m_list);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CListCtrlOwnerDrawDlg, CDialog)
//{{AFX_MSG_MAP(CListCtrlOwnerDrawDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
ON_BN_CLICKED(IDC_BTN_GENERATE, OnBtnGenerate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/
// CListCtrlOwnerDrawDlg message handlers


BOOL CListCtrlOwnerDrawDlg::OnInitDialog()
{
CDialog::OnInitDialog();


// Add "About..." menu item to system menu.


// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);


CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}


// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);// Set big icon
SetIcon(m_hIcon, FALSE);// Set small icon

// TODO: Add extra initialization here
m_list.SetBkColor(RGB(10,10,10));        //设置背景色(RGB(50,10,10))
m_list.SetRowHeigt(29);               //设置行高度
m_list.SetHeaderHeight(2.5f);          //设置头部高度
m_list.SetHeaderFontHW(14,0);         //设置头部字体高度,和宽度,0表示缺省,自适应 
m_list.SetHeaderTextColor(RGB(255,200,100)); //设置头部字体颜色
m_list.SetTextColor(RGB(255,128,0));  //设置文本颜色
m_list.SetHeaderBKColor(100,200,100,8); //设置头部背景色
m_list.SetFontHW(15,0);               //设置字体高度,和宽度,0表示缺省宽度
m_list.SetColTextColor(0,RGB(255,255,0)); //设置列文本颜色

m_list.InsertColumn(0,_T(" "),LVCFMT_CENTER,80);
m_list.InsertColumn(1,_T("最大电压"),LVCFMT_CENTER,100);
m_list.InsertColumn(2,_T("最大电流"),LVCFMT_CENTER,100);
m_list.InsertColumn(3,_T("阶梯电压"),LVCFMT_CENTER,100);
m_list.InsertColumn(4,_T("阶梯电流"),LVCFMT_CENTER,100);
m_list.InsertColumn(5,_T(""),LVCFMT_CENTER,92);



m_list.InsertItem(0,"LED1");
m_list.InsertItem(1,"LED2");
m_list.InsertItem(2,"LED3");
m_list.InsertItem(3,"LED4");
m_list.InsertItem(4,"LED5");
m_list.InsertItem(5,"LED6");
m_list.InsertItem(6,"LED7");
m_list.InsertItem(7,"LED8");
m_list.InsertItem(8,"LED9");
m_list.InsertItem(9,"LED10");
m_list.InsertItem(10,"LED11");



SetWindowLong(m_list.m_hWnd ,GWL_EXSTYLE,WS_EX_TRANSPARENT   /*,WS_EX_CLIENTEDGE*/);
//m_list.SetExtendedStyle(LVS_EX_GRIDLINES);                     //设置扩展风格为网格
::SendMessage(m_list.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);

return TRUE;  // return TRUE  unless you set the focus to a control
}


void CListCtrlOwnerDrawDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.


void CListCtrlOwnerDrawDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting


SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);


// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;


// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}


// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CListCtrlOwnerDrawDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}






void CListCtrlOwnerDrawDlg::OnBtnOk() 
{
CDialog::OnOK();

}


void CListCtrlOwnerDrawDlg::OnBtnGenerate() 
{
float data[11][5];


for ( int i=0;i<11;i++)
{
for (int j=0;j<5;j++)
{
data[i][j]=(float)(28+rand()%30/10.0);
}
}

CString datamsg;
for ( i=0;i<11;i++)
{
datamsg.Format("%5.1f",data[i][0]);
m_list.SetItemText(i,1,datamsg);

datamsg.Format("%5.1f",data[i][1]);
m_list.SetItemText(i,2,datamsg);


datamsg.Format("%5.2f",data[i][2]);
m_list.SetItemText(i,3,datamsg);

datamsg.Format("%5.2f",data[i][3]);
m_list.SetItemText(i,4,datamsg);


}
}


// ListCtrlOwnerDrawDlg.h : header file
//


#if !defined(AFX_LISTCTRLOWNERDRAWDLG_H__8863B9CF_E9A9_4D69_8B0C_14B2E2230809__INCLUDED_)
#define AFX_LISTCTRLOWNERDRAWDLG_H__8863B9CF_E9A9_4D69_8B0C_14B2E2230809__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


/
// CListCtrlOwnerDrawDlg dialog
#include "ListCtrlCl.h"


class CListCtrlOwnerDrawDlg : public CDialog
{
// Construction
public:
CListCtrlOwnerDrawDlg(CWnd* pParent = NULL);// standard constructor


// Dialog Data
//{{AFX_DATA(CListCtrlOwnerDrawDlg)
enum { IDD = IDD_LISTCTRLOWNERDRAW_DIALOG };
CListCtrlCl m_list;
//}}AFX_DATA


// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListCtrlOwnerDrawDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support
//}}AFX_VIRTUAL


// Implementation
protected:
HICON m_hIcon;


// Generated message map functions
//{{AFX_MSG(CListCtrlOwnerDrawDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnBtnOk();
afx_msg void OnBtnGenerate();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_LISTCTRLOWNERDRAWDLG_H__8863B9CF_E9A9_4D69_8B0C_14B2E2230809__INCLUDED_)








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值