This commit is contained in:
coco
2026-07-03 16:05:30 +08:00
commit df489d5640
1101 changed files with 779140 additions and 0 deletions
+259
View File
@@ -0,0 +1,259 @@
#include "CDragListCtrl.h"
// BEGIN_MESSAGE_MAP(CDragListCtrl, CListCtrl)
// ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST_LOOP_SUB_LIST, &CDragListCtrl::OnLvnBegindragListLoopTaskList)
// ON_MESSAGE(WM_MOUSEMOVE, OnMouseMove)
// ON_MESSAGE(WM_LBUTTONUP, OnLButtonUp)
// END_MESSAGE_MAP()
CDragListCtrl::CDragListCtrl()
{
m_nSelItem = -1;
m_pDragImageList = NULL;
m_bDragging = FALSE;
}
CDragListCtrl::~CDragListCtrl()
{
}
/*void CDragListCtrl::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
int count = GetSelectedCount();
if (1 != count)
return;
POSITION pos = GetFirstSelectedItemPosition();
if (NULL == pos)
return;
m_nSelItem = GetNextSelectedItem(pos);
if (-1 == m_nSelItem)
return;
CPoint pt = pNMLV->ptAction;
m_pDragImageList = CreateDragImage(m_nSelItem, &pt);
if (NULL == m_pDragImageList)
return;
m_bDragging = TRUE;
m_pDragImageList->BeginDrag(0, CPoint(8, 8));
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragEnter(GetParent(), pt);
SetCapture();
}
void CDragListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
ReleaseCapture();
m_bDragging = FALSE;
//m_nSelItem = -1;
m_pDragImageList->DragLeave(GetParent());
m_pDragImageList->EndDrag();
m_pDragImageList->DeleteImageList();
delete m_pDragImageList;
m_pDragImageList = NULL;
}
CListCtrl::OnLButtonUp(nFlags, point);
}
void CDragListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
CPoint pt = point;
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragMove(pt);
}
CListCtrl::OnMouseMove(nFlags, point);
}*/
BEGIN_MESSAGE_MAP(CDragListCtrl, CListCtrl)
ON_NOTIFY_REFLECT(LVN_BEGINDRAG, &CDragListCtrl::OnLvnBegindrag)
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CDragListCtrl::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
int count = GetSelectedCount();
if (1 != count)
return;
POSITION pos = GetFirstSelectedItemPosition();
if (NULL == pos)
return;
m_nSelItem = GetNextSelectedItem(pos);
if (-1 == m_nSelItem)
return;
CPoint pt = pNMLV->ptAction;
m_pDragImageList = CreateDragImage(m_nSelItem, &pt);
if (NULL == m_pDragImageList)
return;
m_bDragging = TRUE;
m_pDragImageList->BeginDrag(0, CPoint(8, 8));
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragEnter(GetParent(), pt);
CDragList::BeginDrag(m_hWnd, pt);
SetCapture();
}
void CDragListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
CPoint pt = point;
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragMove(pt);
}
if (CDragList::m_SelectItem != SELECT_NONE && nFlags&MK_LBUTTON)
{
CDragList::Dragging(m_hWnd, point);
}
CListCtrl::OnMouseMove(nFlags, point);
}
void CDragListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
ReleaseCapture();
m_bDragging = FALSE;
//m_nSelItem = -1;
m_pDragImageList->DragLeave(GetParent());
m_pDragImageList->EndDrag();
m_pDragImageList->DeleteImageList();
delete m_pDragImageList;
m_pDragImageList = NULL;
}
CDragList::EndDrag(m_hWnd, point);
CListCtrl::OnLButtonUp(nFlags, point);
}
/*void CDragListCtrl::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
int count = GetSelectedCount();
if (1 != count)
return;
POSITION pos = GetFirstSelectedItemPosition();
if (NULL == pos)
return;
m_nSelItem = GetNextSelectedItem(pos);
if (-1 == m_nSelItem)
return;
CPoint pt = pNMLV->ptAction;
m_pDragImageList = CreateDragImage(m_nSelItem, &pt);
if (NULL == m_pDragImageList)
return;
m_bDragging = TRUE;
m_pDragImageList->BeginDrag(0, CPoint(8, 8));
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragEnter(GetParent(), pt);
SetCapture();
}
void CDragListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
CPoint pt = point;
ClientToScreen(&pt);
CRect rt;
GetParent()->GetWindowRect(&rt);
pt.x -= rt.left;
pt.y -= rt.top;
m_pDragImageList->DragMove(pt);
}
CListCtrl::OnMouseMove(nFlags, point);
}
void CDragListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bDragging)
{
ReleaseCapture();
m_bDragging = FALSE;
//m_nSelItem = -1;
m_pDragImageList->DragLeave(GetParent());
m_pDragImageList->EndDrag();
m_pDragImageList->DeleteImageList();
delete m_pDragImageList;
m_pDragImageList = NULL;
}
CListCtrl::OnLButtonUp(nFlags, point);
}*/
// void CDragListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
// {
// // TODO: 在此添加消息处理程序代码和/或调用默认值
//
// CListCtrl::OnLButtonDown(nFlags, point);
// CDragList::BeginDrag(m_hWnd, point);
// OutputDebugString(_T("CDragListCtrl::OnLButtonDown()\n"));
// }
+29
View File
@@ -0,0 +1,29 @@
#ifndef CDRAGLISTCTRL_H_INCLUDE_201901150925
#define CDRAGLISTCTRL_H_INCLUDE_201901150925
#pragma once
#include <afxcmn.h>
#include "DragList.h"
class CDragListCtrl :public CListCtrl
{
public:
CDragListCtrl();
~CDragListCtrl();
DECLARE_MESSAGE_MAP()
afx_msg void OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
protected:
// void OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult);
// void OnLButtonUp(UINT nFlags, CPoint point);
// void OnMouseMove(UINT nFlags, CPoint point);
private:
int m_nSelItem;
CImageList* m_pDragImageList;
BOOL m_bDragging;
public:
//afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};
#endif
@@ -0,0 +1,137 @@
// HeaderCtrlCl.cpp : 实现文件
//
#include "stdafx.h"
//#include "DemoList.h"
#include "CListHeaderTextColorCtrl.h"
// CListHeaderTextColorCtrl
IMPLEMENT_DYNAMIC(CListHeaderTextColorCtrl, CHeaderCtrl)
CListHeaderTextColorCtrl::CListHeaderTextColorCtrl()
: 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);
}
CListHeaderTextColorCtrl::~CListHeaderTextColorCtrl()
{
}
BEGIN_MESSAGE_MAP(CListHeaderTextColorCtrl, CHeaderCtrl)
ON_WM_PAINT()
ON_MESSAGE(HDM_LAYOUT, OnLayout)
END_MESSAGE_MAP()
// CListHeaderTextColorCtrl 消息处理程序
void CListHeaderTextColorCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CHeaderCtrl::OnPaint()
int nItem;
nItem = GetItemCount();//得到有几个单元
for(int i = 0; i<nItem;i ++)
{
CRect tRect;
GetItemRect(i,&tRect);//得到Item的尺寸
int R = m_R,G = m_G,B = m_B;
CRect nRect(tRect);//拷贝尺寸到新的容器中
nRect.left++;//留出分割线的地方
//绘制立体背景
for(int j = tRect.top;j<=tRect.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;
}
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(); //释放字体
}
//画头部剩余部分
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 CListHeaderTextColorCtrl::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;
}
@@ -0,0 +1,34 @@
#ifndef CLISTHEADERTEXTCOLORCTRL_H_201902181035
#define CLISTHEADERTEXTCOLORCTRL_H_201902181035
#pragma once
// CListHeaderTextColorCtrl
class CListHeaderTextColorCtrl : public CHeaderCtrl
{
DECLARE_DYNAMIC(CListHeaderTextColorCtrl)
public:
CListHeaderTextColorCtrl();
virtual ~CListHeaderTextColorCtrl();
afx_msg void OnPaint();
CStringArray m_HChar;
CString m_Format; //表示对齐类型的整型数组,0表示左对齐,1表示中间对齐,2表示右对齐
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 );
protected:
DECLARE_MESSAGE_MAP()
};
#endif
@@ -0,0 +1,399 @@
// ListCtrlCl.cpp : 实现文件
//
#include "stdafx.h"
//#include "DemoList.h"
#include "CListTextColorCtrl.h"
struct stColor
{
int nRow;
int nCol;
COLORREF rgb;
};
// CListTextColorCtrl
IMPLEMENT_DYNAMIC(CListTextColorCtrl, CListCtrl)
CListTextColorCtrl::CListTextColorCtrl()
: m_nRowHeight(0)
, m_fontHeight(12)
, m_fontWith(0)
{
m_color = RGB(0,0,0);
}
CListTextColorCtrl::~CListTextColorCtrl()
{
m_ptrListCol.RemoveAll();
m_ptrListItem.RemoveAll();
m_colTextColor.RemoveAll();
m_ItemTextColor.RemoveAll();
}
/*BOOL CListTextColorCtrl::DeleteItem(_In_ int nItem)
{
//m_ItemTextColor.
//return CListCtrl::DeleteItem(nItem);
}*/
// Removes all items from the control.
BOOL CListTextColorCtrl::DeleteAllItems()
{
m_ptrListCol.RemoveAll();
m_ptrListItem.RemoveAll();
m_colTextColor.RemoveAll();
m_ItemTextColor.RemoveAll();
return CListCtrl::DeleteAllItems();
}
BEGIN_MESSAGE_MAP(CListTextColorCtrl, CListCtrl)
ON_WM_MEASUREITEM()
ON_WM_MEASUREITEM_REFLECT()
END_MESSAGE_MAP()
// CListTextColorCtrl 消息处理程序
void CListTextColorCtrl::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
ModifyStyle(0,LVS_OWNERDRAWFIXED);
CListCtrl::PreSubclassWindow();
/*CHeaderCtrl *pHeader = GetHeaderCtrl();
m_Header.SubclassWindow(pHeader->GetSafeHwnd());*/
}
void CListTextColorCtrl::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);
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;
if (nCol==0)
{
rcTemp.left -=2;
}
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
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.CreatePointFont(90, _T("微软雅黑"));
//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) ;
}
}
void CListTextColorCtrl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
void CListTextColorCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (m_nRowHeight>0)
{
lpMeasureItemStruct->itemHeight = m_nRowHeight;
}
}
int CListTextColorCtrl::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 CListTextColorCtrl::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 CListTextColorCtrl::SetHeaderHeight(float Height) //设置表头高度
{
//m_Header.m_Height = Height;
}
bool CListTextColorCtrl::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 CListTextColorCtrl::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 CListTextColorCtrl::SetColColor(int col,COLORREF color) //设置列颜色
{
stColor *pColor = new stColor;
pColor->nCol = col;
pColor->rgb = color;
m_ptrListCol.AddTail(pColor);
}
void CListTextColorCtrl::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 CListTextColorCtrl::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 CListTextColorCtrl::SetHeaderFontHW(int nHeight,int nWith) //设置头部字体宽和高
{
/*m_Header.m_fontHeight = nHeight;
m_Header.m_fontWith = nWith;*/
}
void CListTextColorCtrl::SetHeaderTextColor(COLORREF color) //设置头部字体颜色
{
//m_Header.m_color = color;
}
BOOL CListTextColorCtrl::SetTextColor(COLORREF cr) //设置字体颜色
{
m_color = cr;
return TRUE;
}
void CListTextColorCtrl::SetFontHW(int nHeight,int nWith) //设置字体高和宽
{
m_fontHeight = nHeight;
m_fontWith = nWith;
}
void CListTextColorCtrl::SetColTextColor(int col,COLORREF color)
{
stColor *pColor = new stColor;
pColor->nCol = col;
pColor->rgb = color;
m_colTextColor.AddTail(pColor);
}
bool CListTextColorCtrl::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 CListTextColorCtrl::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;
}
bool CListTextColorCtrl::UpdateItemTextColor(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;
pColor->rgb = color;
break;
}
}
if (1 == flag)
{
return true;
}
return false;
}
void CListTextColorCtrl::SetItemTextColor(int col,int row,COLORREF color)
{
stColor* pColor = new stColor;
if (pColor != NULL)
{
pColor->nCol = col;
pColor->nRow = row;
pColor->rgb = color;
m_ItemTextColor.AddTail(pColor);
}
}
@@ -0,0 +1,63 @@
#ifndef CLISTTEXTCOLORCTRL_H_20190218
#define CLISTTEXTCOLORCTRL_H_20190218
#pragma once
#include "CListHeaderTextColorCtrl.h"
// CListTextColorCtrl
class CListTextColorCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CListTextColorCtrl)
public:
//CListHeaderTextColorCtrl m_Header;
CListTextColorCtrl();
virtual ~CListTextColorCtrl();
BOOL DeleteItem(_In_ int nItem);
// Removes all items from the control.
BOOL DeleteAllItems();
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
// 行高
int m_nRowHeight;
int InsertColumn(int nCol, LPCTSTR lpszColumnHeading,int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1);
// Gradient - 渐变系数,立体背景用,不用渐变设为0
void SetHeaderBKColor(int R, int G, int B, int Gradient);
// 设置表头高度
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);
bool UpdateItemTextColor(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); //设置字体的高和宽
// 字体高度
int m_fontHeight;
// 字体宽度
int m_fontWith;
protected:
DECLARE_MESSAGE_MAP()
virtual void PreSubclassWindow();
};
#endif
+234
View File
@@ -0,0 +1,234 @@
#include "stdafx.h"
#include "DragList.h"
vector <RECT> CDragList::ItemRect;
int CDragList::m_ActiveItem = SELECT_NONE;
bool CDragList::m_IsOut = true;
int CDragList::m_SelectItem = SELECT_NONE;
bool CDragList::m_IsInFilstPart = false;
bool CDragList::m_IsInSecondPart = false;
POINT CDragList::MouseDownPoint = { -10, -10 };
void CDragList::BeginDrag(HWND ListWnd, POINT point)
{
::SetCapture(ListWnd);
//设置焦点
if (::GetFocus() != ListWnd)
::SetFocus(ListWnd);
//enum to find out if select one
int count = (int)::SendMessage(ListWnd, LVM_GETITEMCOUNT, 0, 0);
int state;
CString strLog;
for (int i = 0; i < count; i++)
{
state = (int)::SendMessage(ListWnd, LVM_GETITEMSTATE, i, (LPARAM)LVIS_SELECTED);
if (state | LVIS_SELECTED == 1)
{
m_SelectItem = i;
m_ActiveItem = i;
m_IsOut = true;
MouseDownPoint = point;
strLog.Format(_T("遍历当前选中%d行"), i);
OutputDebugString(strLog);
}
}
}
void CDragList::EndDrag(HWND ListWnd, POINT point)
{
if (m_ActiveItem != SELECT_NONE)
{
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
if (m_ActiveItem != m_SelectItem && m_SelectItem != SELECT_NONE)
{
//最后的Item的处理
//if (m_IsInSecondPart == true)
// m_ActiveItem += 1;
::PostMessage(::GetParent(ListWnd), WM_MOVEITEM, m_SelectItem, m_ActiveItem);
}
}
::ReleaseCapture();
m_SelectItem = SELECT_NONE;
}
void CDragList::Dragging(HWND ListWnd, POINT point)
{
//当鼠标按下后没有移动就弹起时,ClistCtrl会发送一个click消息,
//并且会有一个WM_MOUSEMOVE的消息(却没有WM_LBUTTONDUP的消息)
//我们这里简单的返回
if (point.x == MouseDownPoint.x && point.y == MouseDownPoint.y)
{
::ReleaseCapture();
m_SelectItem = SELECT_NONE;
return;
}
//get the rect of ListCtrl
RECT rect;
::GetWindowRect(ListWnd, &rect);
rect.top += 24; //去掉头表的高度
POINT MousePoint;
::GetCursorPos(&MousePoint);
//mouse is not in the ListCtrl
if (!::PtInRect(&rect, MousePoint))
{
m_IsOut = true;
if (m_ActiveItem != SELECT_NONE)
{
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
m_ActiveItem = SELECT_NONE;
}
//::SetCursor(LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR2)));
//超过窗体上边,向上滚动
if (MousePoint.y<rect.top)
{
::SendMessage(ListWnd, WM_KEYDOWN, VK_UP, 0);
::SendMessage(ListWnd, WM_KEYUP, VK_UP, 0);
}
//超过窗体下边,向下滚动
else if (MousePoint.y>rect.bottom)
{
::SendMessage(ListWnd, WM_KEYDOWN, VK_DOWN, 0);
::SendMessage(ListWnd, WM_KEYUP, VK_DOWN, 0);
}
return;
}
//if is outside the widnow,re receive all the item rect again
if (m_IsOut)
{
m_IsOut = false;
m_IsInFilstPart = false;
m_IsInSecondPart = false;
//get the count of listctrl
int count = (int)::SendMessage(ListWnd, LVM_GETITEMCOUNT, 0, 0);
//initial data
ItemRect.clear();
ItemRect.resize(count);
for (int i = 0; i < count; i++)
{
//save item rect
ItemRect[i].left = LVIR_SELECTBOUNDS;
::SendMessage(ListWnd, LVM_GETITEMRECT, i, (LPARAM)&ItemRect[i]);
}
}
//begin find item
int i;
for (i = 0; i < ItemRect.size() && !::PtInRect(&ItemRect[i], point); i++); //注意这行的分号
CString strLog;
strLog.Format(_T("CDragList::Dragging() 查找当前的点在哪一行,%d行,点x=%d,y=%d , ItemRect[i] left=%d,top=%d,right=%d,bottom=%d\n"), i, point.x, point.y, ItemRect[i].left, ItemRect[i].top, ItemRect[i].right, ItemRect[i].bottom);
OutputDebugString(strLog);
//if found item(即鼠标在List里面)
if (i != ItemRect.size())
{
//改变鼠标形状
//::SetCursor(LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_MOVEITEMCUR)));
//在最后一项移动
if (i == ItemRect.size() - 1)
{
//是否第一次移入此Item
if (m_ActiveItem != i)
{
//假如需要,更新原来的ItemRect
if (m_ActiveItem != SELECT_NONE)
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
//保存当前焦点的按钮索引
m_ActiveItem = i;
}
//在最后一个item的上半部分上移动
if (point.y < (ItemRect[m_ActiveItem].top + ItemRect[m_ActiveItem].bottom) / 2)
{
//第一次进入最后一个item的前半部分
if (m_IsInFilstPart == false)
{
m_IsInFilstPart = true;
m_IsInSecondPart = false;
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
::UpdateWindow(ListWnd);
//DrawLine(ListWnd, ItemRect[m_ActiveItem].left + 2, ItemRect[m_ActiveItem].top + 2,
// ItemRect[m_ActiveItem].right - 2, ItemRect[m_ActiveItem].top + 2);
}
}
//在最后一个item的后半部分上移动
else
{
//第一次进入最后一个item的后半部分
if (m_IsInSecondPart == false)
{
m_IsInSecondPart = true;
m_IsInFilstPart = false;
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
::UpdateWindow(ListWnd);
//DrawLine(ListWnd, ItemRect[m_ActiveItem].left + 2, ItemRect[m_ActiveItem].bottom - 2,
// ItemRect[m_ActiveItem].right - 2, ItemRect[m_ActiveItem].bottom - 2);
}
}
return;
}
//是否第一次移入此Item
if (m_ActiveItem != i)
{
m_IsInFilstPart = false;
//假如需要,更新原来的ItemRect
if (m_ActiveItem != SELECT_NONE)
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
//保存当前焦点的按钮索引
m_ActiveItem = i;
//DrawLine(ListWnd, ItemRect[m_ActiveItem].left + 4, ItemRect[m_ActiveItem].top + 2,
// ItemRect[m_ActiveItem].right - 4, ItemRect[m_ActiveItem].top + 2);
return;
}
}
//if not found item(鼠标不在List里面)
else
{
//假如第一次移出List
if (m_ActiveItem != SELECT_NONE)
{
//重绘原来的按钮
::InvalidateRect(ListWnd, &ItemRect[m_ActiveItem], false);
//表示鼠标在List外
m_ActiveItem = SELECT_NONE;
}
m_IsInFilstPart = false;
m_IsInSecondPart = false;
//改变鼠标形状
//::SetCursor(LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR2)));
}
}
/* void CDragList::DrawLine(HWND hWnd, int BeginX, int BeginY, int EndX, int EndY)
{
HDC hdc = ::GetDC(hWnd);
HPEN Pen = ::CreatePen(PS_SOLID, 4, RGB(0, 0, 0));
HPEN OldPen = (HPEN)SelectObject(hdc, Pen);
HBRUSH OldBrush = (HBRUSH)::SelectObject(hdc, (HBRUSH)GetStockObject(NULL_BRUSH));
MoveToEx(hdc, BeginX, BeginY, NULL);
LineTo(hdc, EndX, EndY);
::SelectObject(hdc, OldBrush);
::SelectObject(hdc, OldPen);
::DeleteObject(Pen);
::ReleaseDC(hWnd, hdc);
}*/
+28
View File
@@ -0,0 +1,28 @@
#ifndef _DRAG_LIST_H_
#define _DRAG_LIST_H_
#include "Resource.h"
#include <vector>
using namespace std;
#define SELECT_NONE -1
#define BUTTON_UP -1
//#define WM_SWAPITEM WM_USER+435
#define WM_MOVEITEM WM_USER+436
class CDragList
{
private:
static vector <RECT> ItemRect;
static int m_ActiveItem;
static bool m_IsOut;
static bool m_IsInFilstPart;
static bool m_IsInSecondPart;
static POINT MouseDownPoint;
public:
static int m_SelectItem;
public:
static void BeginDrag(HWND ListWnd, POINT point);
static void EndDrag(HWND ListWnd, POINT point);
static void Dragging(HWND ListWnd, POINT point);
//static void DrawLine(HWND hWnd, int BeginX, int BeginY, int EndX, int EndY);
};
#endif // #define _DRAG_LIST_H_