【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-CustomGrid.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// CustomGrid.cpp : implementation file
//
#include "stdafx.h"
#include "aaa.h"
#include "CustomGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomGrid
CCustomGrid::CCustomGrid()
{
showedit= true;
row = -1;
col = -1;
}
CCustomGrid::~CCustomGrid()
{
}
BEGIN_MESSAGE_MAP(CCustomGrid, CListCtrl)
//{{AFX_MSG_MAP(CCustomGrid)
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_VSCROLL()
ON_WM_MOUSEWHEEL()
ON_WM_MOUSEMOVE()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomGrid message handlers
void CCustomGrid::PreSubclassWindow()
{
ModifyStyle(LVS_EDITLABELS,0);
ModifyStyle(0,LVS_REPORT);
ModifyStyle(0,LVS_SHOWSELALWAYS);
SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_GRIDLINES|LVS_EX_ONECLICKACTIVATE|LVS_EX_FLATSB);
edit.Create(WS_CHILD|WS_CLIPSIBLINGS|WS_EX_TOOLWINDOW|WS_BORDER,CRect(0,40,10,50),this,1001);
CListCtrl::PreSubclassWindow();
}
void CCustomGrid::OnLButtonDblClk(UINT nFlags, CPoint point)
{
/* LVHITTESTINFO info;
info.pt = point;
info.flags = LVHT_ONITEMLABEL;
if (editing ==false)
if (SubItemHitTest(&info)>=0)
{
row = info.iItem;
col = info.iSubItem;
ShowEdit();
}
else
{
row = -1;
col = -1;
}*/
CListCtrl::OnLButtonDblClk(nFlags, point);
}
void CCustomGrid::DisposeEdit(bool drawed)
{
if (drawed)
{
CString str;
edit.GetWindowText(str);
SetItemText(row,col,str);
}
edit.ShowWindow(SW_HIDE);
//showedit = false;
Invalidate();
}
void CCustomGrid::OnLButtonDown(UINT nFlags, CPoint point)
{
CListCtrl::OnLButtonDown(nFlags, point);
LVHITTESTINFO info;
info.pt = point;
info.flags = LVHT_ONITEMLABEL;
if (SubItemHitTest(&info)>=0)
{
row = info.iItem;
col = info.iSubItem;
ShowEdit();
}
}
void CCustomGrid::ShowEdit()
{
CRect rect; //记录当前单元格的坐标
GetSubItemRect(row,col,LVIR_LABEL,rect);
CString str;
str = GetItemText(row,col);
edit.MoveWindow(rect);
edit.SetWindowText(str);
edit.ShowWindow(SW_SHOW);
edit.SetSel(0,100);
edit.SetFocus();
edit.SetReadOnly(!showedit);
UpdateWindow();
}
void CCustomGrid::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
//if (nChar == VK_DOWN)
//;//InsertItem(1,"");
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CCustomGrid::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
UpdateWindow();
CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}
BOOL CCustomGrid::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
Invalidate();
return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
}
void CCustomGrid::OnMouseMove(UINT nFlags, CPoint point)
{
CListCtrl::OnMouseMove(nFlags, point);
}
void CCustomGrid::OnSetFocus(CWnd* pOldWnd)
{
CListCtrl::OnSetFocus(pOldWnd);
}
上一篇:
CustomException.cpp
下一篇:
青青子衿,悠悠我心