📄 ebookview.cpp
字号:
RECT rect;
m_tree->GetItemRect(hItem,&rect,TRUE);
CMenu Menu;
Menu.LoadMenu(IDR_MENU_TREE);
pMenu=Menu.GetSubMenu(0);
ASSERT(pMenu!=0);
CPoint p;
p.x=rect.left;
p.y=rect.top;
ClientToScreen(&p);
pMenu->TrackPopupMenu(0,p.x,p.y,this);
}
void CEBookView::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
//focus to new item
m_tree=(CTreeCtrl*)GetDlgItem(IDC_TREE);
CString s;
m_EditItem=m_tree->GetSelectedItem ();
m_edit=m_tree->GetEditControl ();
m_edit->GetWindowText (s);
if(m_pSet->m_title !=s)
{
m_pSet->Edit ();
m_pSet->m_title =s;
if(m_pSet->CanUpdate ())
m_pSet->Update();
m_pSet->Edit();
}
*pResult = TRUE;
}
void CEBookView::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_tree=(CTreeCtrl*)GetDlgItem(IDC_TREE);
m_edit=(CEdit*)GetDlgItem(IDC_CONTENT);
CString s;
if(IsDataOpen)
{
HTREEITEM hItem =m_tree->GetSelectedItem ();
LONG ID;
ID=m_treelist.FindID(hItem);
m_pSet->MoveFirst ();
while(!m_pSet->IsEOF())
{
if(m_pSet->m_BookID==ID)
break;
m_pSet->MoveNext();
}
m_Content=m_pSet->m_Content ;
UpdateData(FALSE);
m_tree->EnsureVisible (hItem);
}
if(IsEditing)
{
m_tree->SetFocus ();
m_tree->SelectItem (m_EditItem);
s=m_tree->GetItemText(m_EditItem);
LONG ID;
ID=m_treelist.FindID(m_EditItem);
ASSERT(ID>0);
m_pSet->MoveFirst ();
while(!m_pSet->IsEOF())
{
if(m_pSet->m_BookID==ID)
break;
m_pSet->MoveNext();
}
CString Content;
int i;
Content=m_pSet->m_Content;
if((s=="新标题")&(Content.GetLength()>5))
{
i=Min(Content.Find ("\r\n"),Content.Find(','),
Content.Find(". "));
i=Min(i,Content.Find("。"),Content.Find(';'));
if(i>99) i=50;
s=Content.Left (i);
m_tree->SetItemText (m_EditItem,s);
}
m_pSet->Edit ();
m_pSet->m_title =s;
if(m_pSet->CanUpdate ())
m_pSet->Update();
m_pSet->Edit();
IsEditing=FALSE; //Complete edit tree item
}
else if(m_bAdding)
{
m_tree->SetFocus ();
m_tree->SelectItem (hNewItem);
m_edit->GetWindowText(s);
AddItemToDataBase(hNewParent,hNewItem,
m_tree->GetItemText(hNewItem), s);
//m_pSet->AddNew ();
//m_pSet->m_
m_bAdding=FALSE;
}
*pResult = 0;
}
void CEBookView::AddItemToDataBase(HTREEITEM hNewParent, HTREEITEM hNewItem, CString title, CString s)
{
LONG ParentID;
ParentID=m_treelist.FindID(hNewParent);
if(ParentID<0)return;
LONG NewBookID;
m_pSet->MoveLast();
NewBookID=m_pSet->m_BookID+1;
m_pSet->AddNew();
m_pSet->m_BookID =NewBookID;
m_pSet->m_ParentID =ParentID;
m_pSet->m_title =title;
m_pSet->m_Content =s;
m_pSet->Update ();
m_pSet->MoveLast();
m_treelist.AddItem (hNewItem,NewBookID);
}
BOOL CEBookView::DeleteItemFromDataBase(HTREEITEM hDeleteItem)
{
LONG ID;
ID=m_treelist.DeleteItem(hDeleteItem);//delete item from tree list
// ASSERT(ID>=0);
if(ID<0)return(FALSE); //if can't delete from list return;
m_pSet->MoveFirst();
while(!m_pSet->IsEOF()) //search item from data base
{
if(m_pSet->m_BookID==ID)
break;
m_pSet->MoveNext();
}
m_pSet->Delete (); //delete item from data base
return(TRUE);
}
BOOL CEBookView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CDaoRecordView::PreTranslateMessage(pMsg);
}
void CEBookView::OnLeftmarginIncrease()
{
// TODO: Add your command handler code here
m_edit=(CEdit*)GetDlgItem(IDC_CONTENT);
DWORD margins;
margins=m_edit->GetMargins ();
m_edit->SetMargins ((WPARAM)margins+10,10);
m_edit->Invalidate ();
}
void CEBookView::OnLeftmarginDecrease()
{
// TODO: Add your command handler code here
m_edit=(CEdit*)GetDlgItem(IDC_CONTENT);
DWORD margins;
margins=m_edit->GetMargins ();
if((WPARAM)margins>15){
m_edit->SetMargins ((WPARAM)margins-10,10);
m_edit->Invalidate ();}
}
void CEBookView::OnAsizeincrease()
{
MessageBox("在后续版本中将增加该功能");
// TODO: Add your command handler code here
/* m_edit=(CEdit*)GetDlgItem(IDC_CONTENT);
// m_edit->GetDe
LOGFONT logFont;
logFont.lfHeight = 8;
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_NORMAL;
logFont.lfItalic = 0;
logFont.lfUnderline = 0;
logFont.lfStrikeOut = 0;
logFont.lfCharSet = ANSI_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = PROOF_QUALITY;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
strcpy(logFont.lfFaceName, "Times New Roman");
// Initialize the position of text in the window.
// Create and display eight example fonts.
// Set the new font's height.
logFont.lfHeight =8*4;
// Create a new font and select it into the DC.
CFont font;
font.CreateFontIndirect(&logFont);
CDC *pDC=m_edit->GetDC ();
CFont* oldFont = pDC->SelectObject(&font);
m_edit->Invalidate ();
*/
}
void CEBookView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
HCURSOR hCursor;
if(b_IsDraging)
{
RECT rect;
if(TempWidth<point.x)
m_treeWidth=point.x-5;
else
m_treeWidth=point.x+4;
GetParent()->GetClientRect(&rect);
OnSize(SIZE_RESTORED , rect.right -rect.left , rect.bottom-rect.top );
TempWidth=m_treeWidth;
}
else if(abs(point.x -m_treeWidth)<=3)
{
hCursor=::LoadCursor (NULL,IDC_SIZEWE);
::SetCursor (hCursor);
}
else if((abs(point.x-m_treeWidth)>3)&(b_IsDraging==FALSE))
{
hCursor=::LoadCursor (NULL,IDC_ARROW);
::SetCursor (hCursor);
}
else if((abs(point.x-m_treeWidth)>3)&(b_IsDraging))
{
hCursor=::LoadCursor (NULL,IDC_ARROW);
::SetCursor (hCursor);
b_IsDraging=FALSE;
}
CDaoRecordView::OnMouseMove(nFlags, point);
}
void CEBookView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(abs(point.x -m_treeWidth)<=2)
{
HCURSOR hCursor;
hCursor=::LoadCursor (NULL,IDC_SIZEWE);
::SetCursor (hCursor);
b_IsDraging=!b_IsDraging;
}
CDaoRecordView::OnLButtonDown(nFlags, point);
}
void CEBookView::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
b_IsDraging=FALSE;
*pResult = 0;
}
int CEBookView::Min(int i1, int i2, int i3)
{
int i=i1;
if(i1==-1)i=30;
if((i>i2)&(i2>0))
i=i2;
if((i>i3)&(i3>0))
i=i3;
return(i);
}
void CEBookView::OnChangeContent()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDaoRecordView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
// if(!m_bAdding)return;
CString Content;
int i;
CString s;
m_tree=(CTreeCtrl*)GetDlgItem(IDC_TREE);
m_EditItem=m_tree->GetSelectedItem ();
s=m_tree->GetItemText (m_EditItem);
m_edit=(CEdit*)GetDlgItem(IDC_CONTENT);
m_edit->GetWindowText (Content);
if((s=="新标题")&(Content.GetLength()>10))
{
i=Min(Content.Find ("\r\n"),Content.Find(','),
Content.Find(". "));
i=Min(i,Content.Find("。"),Content.Find(';'));
i=Min(i,Content.Find ("---"),Content.Find("?"));
if(i>99) i=50;
int j=0;
while(Content.GetAt (j)==' ')
{j++;}
m_ChangeTitle=Content.Left (i);
m_ChangeTitle=m_ChangeTitle.Right(i-j);
m_tree->SetItemText (m_EditItem,m_ChangeTitle);
}
UpdateData(TRUE);
m_pSet->Edit ();
if((m_pSet->m_title =="新标题")&(m_ChangeTitle.GetLength ()>1))
{
if((m_ChangeTitle!=m_pSet->m_title)&(m_ChangeTitle!="新标题"))
m_pSet->m_title=m_ChangeTitle;
}
m_pSet->m_Content =m_Content;
if(m_pSet->CanUpdate ())
m_pSet->Update();
m_pSet->Edit();
}
/*
void CEBookView::OnBegindragTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
m_dragItem = pNMTreeView->itemNew.hItem;
if( m_tree.GetParentItem( m_dragItem ) != NULL )
{
CImageList* pDragImage;
pDragImage = m_tree.CreateDragImage( m_dragItem );
m_tree.SelectItem( m_dragItem );
pDragImage->BeginDrag( 0, CPoint(0,0) );
pDragImage->DragEnter( &m_tree, pNMTreeView->ptDrag );
SetCapture();
m_bIsDragging = TRUE;
delete pDragImage;
}
*pResult = 0;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -