【VC开源代码栏目提醒】:本文主要为网学会员提供BaseList.cpp,希望对需要BaseList.cpp网友有所帮助,学习一下!
// BaseList.cpp : implementation file
//
#include "stdafx.h"
#include "BaseList.h"
#include "a1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ID_MYEDITPH 134
/////////////////////////////////////////////////////////////////////////////
// CBaseList
CBaseList::CBaseList()
{
m_poplist=NULL;
m_iStopDestroy=0;
m_bSetValue=false;
m_iEditedIndex=-2;
m_Next=false;
m_bWaitPopList=false;
m_iEditedIndex=0;
this->m_nItem=0;
this->m_nSubItem=0;
}
CBaseList::~CBaseList()
{
m_poplist->DestroyWindow();
delete this->m_poplist;
this->m_poplist=NULL;
}
BEGIN_MESSAGE_MAP(CBaseList, CListCtrl)
//{{AFX_MSG_MAP(CBaseList)
ON_WM_LBUTTONDOWN()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
ON_MESSAGE(SETNEXTITEMPHFOCUS,SetNextItemFocus)
ON_MESSAGE(MYMESSAGE_EDIT_MOVED,OnParentMoved)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaseList message handlers
/////////////////////////////////////////////////////////////////////////////
// CBaseEdit
CBaseEdit::CBaseEdit()
{
m_bInputValid = TRUE;
this->m_breturn=false;
this->m_besc=false;
this->kc_number=0;
this->m_dSetFocusValue=0;
}
CBaseEdit::~CBaseEdit()
{
}
BEGIN_MESSAGE_MAP(CBaseEdit, CEdit)
//{{AFX_MSG_MAP(CBaseEdit)
ON_WM_CREATE()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaseEdit message handlers
void CBaseList::PreSubclassWindow()
{
ModifyStyle(LVS_EDITLABELS, 0L); //禁止标题编辑
ModifyStyle(0L, LVS_REPORT); //设为Report类型
ModifyStyle(0L, LVS_SHOWSELALWAYS); //始终高亮度被选中的表项
SetBkColor(RGB(0,200,200));
SetTextBkColor(RGB(0,200,200));
ModifyStyle(LVS_OWNERDRAWFIXED ,0L);
SetExtendedStyle( LVS_EX_FULLROWSELECT | //允许整行选中
LVS_EX_HEADERDRAGDROP | //允许整列拖动
LVS_EX_GRIDLINES | //画出网格线
LVS_EX_FLATSB //扁平风格的滚动条
);
CListCtrl::PreSubclassWindow();
}
void CBaseList::OnLButtonDown(UINT nFlags, CPoint point)
{
POSITION pos;
bool flag=false;
int i;
int nItem,nSubItem;
BOOL bSelected = FALSE;
int mark=this->GetSelectionMark();
// if(mark<0) goto defalt_session;
// 检查是否有Item被选中,没有时不进入编辑
pos = GetFirstSelectedItemPosition();
if( pos )
{
// 得到被点击的Item
LVHITTESTINFO testinfo;
testinfo.pt.x = point.x;
testinfo.pt.y = point.y; //点击时的鼠标位置
testinfo.flags = LVHT_ONITEMLABEL; //点击的必须是标题
if( SubItemHitTest(&testinfo)<0 )
goto defalt_session; //没有点在有效区域,不进入编辑
nItem = testinfo.iItem; //被点击表项的行号
nSubItem = testinfo.iSubItem; //被点击表项的列号
if(nItem!=mark)goto defalt_session;
// 判断得到的单元格是否允许被编辑,同时,记录被编辑的编号
for(i=0;i<this->m_iColumnEdited.GetCount();i++)
{
if(nSubItem==m_iColumnEdited.GetAt(m_iColumnEdited.FindIndex(i)))
{
flag=true;
this->m_iEditedIndex=i;
}
}
if(!flag)
goto defalt_session;
// 开始编辑
m_nItem=nItem;
m_nSubItem=nSubItem;
BeginEdit();
return;
}
defalt_session:
CListCtrl::OnLButtonDown(nFlags, point);
}
BOOL CBaseList::BeginEdit()
{
m_edit.ShowWindow(SW_SHOW);
TRACE("BOOL CBaseList::MyBeginEdit()\n");
// 得到被编辑表项的区域
CRect rect;
if( GetSubItemRect(m_nItem, m_nSubItem, LVIR_LABEL, rect)==FALSE )
return FALSE;
rect.right-=1;
rect.left+=1;
rect.top+=1;
rect.bottom-=1;
SetValueUnChange("");
m_edit.MoveWindow(&rect);
CString txtItem;
txtItem=this->GetItemText(m_nItem,m_nSubItem);
// 取出的文字填写到编辑控件
SetValueUnChange(txtItem);
this->OnEditSetFocus(m_nItem,m_nSubItem);
m_edit.SetFocus();
m_edit.SetSel( 0, -1 );
m_edit.Invalidate();
m_edit.ShowWindow(SW_SHOW);
return TRUE;
}
void CBaseList::EndEdit( BOOL bValidate )
{
CString txtItem;
m_edit.GetWindowText(txtItem);
if(bValidate)
SetItemText(m_nItem, m_nSubItem, txtItem);
m_edit.ShowWindow(SW_HIDE);
SetValueUnChange("");
if(this->m_poplist!=NULL)
m_poplist->ShowWindow(SW_HIDE);
}
int CBaseEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
// 改变字体
LOGFONT logfont;
logfont.lfHeight = -12;
logfont.lfWidth = 0;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfWeight = 400;
logfont.lfItalic = 0;
logfont.lfUnderline = 0;
logfont.lfStrikeOut = 0;
logfont.lfCharSet = 134;
logfont.lfOutPrecision = 0;
logfont.lfClipPrecision = 0;
logfont.lfQuality = 0;
logfont.lfPitchAndFamily = 2;
strcpy( logfont.lfFaceName, "宋体" );
m_font.DeleteObject();
if( m_font.CreateFontIndirect(&logfont) )
SetFont( &m_font );
return 0;
}
void CBaseEdit::OnSetFocus(CWnd* pOldWnd)
{
m_bInputValid=true;
CBaseList *parent = (CBaseList *)GetParent();
parent->OnEditSetFocus(parent->m_nItem,parent->m_nSubItem);
CEdit::OnSetFocus(pOldWnd);
}
void CBaseEdit::OnChange()
{
CBaseList *parent = (CBaseList *)GetParent();
if(parent->m_bSetValue)return;
parent->OnNewEditChange(parent->m_nItem,parent->m_nSubItem);
}
void CBaseEdit::OnKillFocus(CWnd* pNewWnd)
{
TRACE("void CBaseEdit::OnKillFocus(CWnd* pNewWnd) \n");
// 得到父窗口,并通知父窗口结束编辑过程
CBaseList *parent = (CBaseList *)GetParent();
HWND hwnd=pNewWnd->GetSafeHwnd();
if(pNewWnd!=NULL)
{
if(hwnd==parent->m_poplist->GetSafeHwnd()||
hwnd==parent->m_poplist->GetDlgItem(ID_POP_LISTCTRL)->GetSafeHwnd())
afxDump<<"\n ID_POP_LISTCTRL CBaseEdit::OnKillFocus";
else
{
// parent->OnEditKillFocus(
// parent->m_nItem,parent->m_nSubItem);
if(this->m_bInputValid)
parent->OnEditReturn(parent->m_nItem,parent->m_nSubItem);
else
parent->EndEdit(false);
}
}
CEdit::OnKillFocus(pNewWnd);
}
BOOL CBaseEdit::PreTranslateMessage(MSG* pMsg)
{
//拦截ESC键解释为WM_KILLFOCUS消息
if( pMsg->message==WM_KEYDOWN )
{
if(pMsg->wParam==27) //ESC键
{
pMsg->message=MYMESSAGE_EDIT_ESC;
}
}
else if(pMsg->message==WM_CHAR)
{
CBaseList *parent = (CBaseList *)GetParent();
parent->PreOnEditChar(parent->m_nItem,parent->m_nSubItem,pMsg->wParam);
}
return CEdit::PreTranslateMessage(pMsg);
}
void CBaseList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
this->EndEdit(true);
m_edit.ShowWindow(SW_HIDE);
if(m_poplist!=NULL)m_pop
上一篇:
BaseKeyDemoView.cpp
下一篇:
个人简历编写四大原则