📄 barwnd.cpp
字号:
GetForderClientRect(iForder,rcClient);
if(GetForderImageListSize(iForder)>0)
iCount=rcClient.Height()/55;
else
iCount=rcClient.Height()/26;
if(iCount+ivstartItem>iItemCount)
iCount=iItemCount;
else if(iCount!=iItemCount-ivstartItem && iItemCount>0)
downarrow=true;
for(int i=ivstartItem;i<iCount+ivstartItem;i++)
DrawItem(iForder,i,pDC);
DrawArrow(iForder,pDC);
}
void CBarWnd::AddBitmap(CImageList * pImage,UINT nIDResource)
{
CBitmap btmap;
btmap.LoadBitmap(nIDResource);
pImage->Add(&btmap,GetSysColor(COLOR_BACKGROUND));
}
void CBarWnd::AddIcon(CPtrArray *arIcon,UINT nIDResource)
{
HICON m_hIcon;
HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIDResource),
RT_GROUP_ICON);
m_hIcon = (HICON)::LoadImage(hInstResource,
MAKEINTRESOURCE(nIDResource),
IMAGE_ICON,
0,
0,
0);
arIcon->Add(m_hIcon);
}
void CBarWnd::DrawArrow(int iForder,CDC * pDC,DrawStyle nStyle)
{
CRect rcUp,rcDown;
GetArrowRect(iForder,rcUp,rcDown);
if(rcUp.left)
{
CPoint ptUp,ptDown;
ptUp.x=rcUp.left;
ptUp.y=rcUp.top;
ptDown.x=rcDown.left;
ptDown.y=rcDown.top;
if(uparrow)
{
switch(nStyle)
{
case redraw:
arrowIcon.Draw(pDC, 0, ptUp, ILD_NORMAL);
pDC->Draw3dRect(rcUp.left,rcUp.top,rcUp.Width(),rcUp.Height(),GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DSHADOW));
break;
case mouse_on:
if(arrow==pointup)
pDC->Draw3dRect(rcUp.left,rcUp.top,rcUp.Width(),rcUp.Height(),GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
break;
case mouse_down:
if(arrow==pointup)
pDC->Draw3dRect(rcUp.left,rcUp.top,rcUp.Width(),rcUp.Height(),GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DHILIGHT));
break;
case normal:
if(arrow==pointup)
pDC->Draw3dRect(rcUp.left,rcUp.top,rcUp.Width(),rcUp.Height(),GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DSHADOW));
break;
}
}
if(downarrow)
{
switch(nStyle)
{
case redraw:
arrowIcon.Draw(pDC, 2, ptDown, ILD_NORMAL);
pDC->Draw3dRect(rcDown.left,rcDown.top,rcDown.Width(),rcDown.Height(),GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DSHADOW));
break;
case mouse_on:
if(arrow==pointdown)
pDC->Draw3dRect(rcDown.left,rcDown.top,rcDown.Width(),rcDown.Height(),GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
break;
case mouse_down:
if(arrow==pointdown)
pDC->Draw3dRect(rcDown.left,rcDown.top,rcDown.Width(),rcDown.Height(),GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DHILIGHT));
break;
case normal:
if(arrow==pointdown)
pDC->Draw3dRect(rcDown.left,rcDown.top,rcDown.Width(),rcDown.Height(),GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
break;
}
}
}
}
void CBarWnd::GetArrowRect(int iForder,CRect &rcUp,CRect &rcDown)
{
CRect rcClient;
GetForderClientRect(iForder,rcClient);
if(rcClient.Width()>36&&rcClient.Height()>56)
{
rcUp=CRect(rcClient.right-26,rcClient.top+10,rcClient.right-9,rcClient.top+29);
rcDown=CRect(rcClient.right-26,rcClient.bottom-29,rcClient.right-9,rcClient.bottom-10);
}
else
{
rcUp=CRect(0,0,0,0);
rcDown=CRect(0,0,0,0);
}
}
void CBarWnd::OnUpArrow(int iForder)
{
CClientDC dc(this);
CForderBar * pForder=(CForderBar *) arForderbar.GetAt(iForder);
int mustredraw=0,iCount,iItemCount=pForder->GetItemCount();
CRect rcClient;
GetForderClientRect(iForder,rcClient);
CBrush brush(GetSysColor(COLOR_3DSHADOW));
if(ivstartItem>0)
{
ivstartItem--;
mustredraw=1;
}
if(ivstartItem<1)
uparrow=false;
if(GetForderImageListSize(iForder)>0)
iCount=rcClient.Height()/55;
else
iCount=rcClient.Height()/26;
if(iCount+ivstartItem<iItemCount)
downarrow=true;
else
downarrow=false;
if(mustredraw)
{
dc.FillRect(&rcClient,&brush);
DrawForderItem(iForder,&dc);
}
}
void CBarWnd::OnDownArrow(int iForder)
{
CClientDC dc(this);
CForderBar * pForder=(CForderBar *) arForderbar.GetAt(iForder);
int iCount,mustredraw=0,iItemCount=pForder->GetItemCount();
CRect rcClient;
GetForderClientRect(iForder,rcClient);
CBrush brush(GetSysColor(COLOR_3DSHADOW));
if(GetForderImageListSize(iForder)>0)
iCount=rcClient.Height()/55;
else
iCount=rcClient.Height()/26;
if(iCount+ivstartItem<iItemCount)
{
ivstartItem++;
mustredraw=1;
}
if(iCount>=iItemCount-ivstartItem)
downarrow=false;
if(ivstartItem>0)
uparrow=true;
else
uparrow=false;
if(mustredraw)
{
dc.FillRect(&rcClient,&brush);
DrawForderItem(iForder,&dc);
}
}
void CBarWnd::OnTimer(UINT nIDEvent)
{
KillTimer(1);
CForderBar *pForder;
int iCount,ivisible=-1;
iCount=arForderbar.GetSize();
for(int index=0;index<iCount;index++)
{
pForder=(CForderBar *)arForderbar.GetAt(index);
if(pForder->visible==true)
{
ivisible=index;
}
}
if(arrow==pointup && uparrow)
OnUpArrow(ivisible);
else if(arrow==pointdown && downarrow)
OnDownArrow(ivisible);
SetTimer(1,150,0);
CWnd::OnTimer(nIDEvent);
}
// 设置抽屉框的子条件图标为大或小图标
void CBarWnd::SelectForderImageStyle(bool nStyle)
{
CForderBar *pForder;
int iCount,ivisible=-1;
iCount=arForderbar.GetSize();
CRect rcClient;
CClientDC dc(this);
for(int index=0;index<iCount;index++)
{
pForder=(CForderBar *)arForderbar.GetAt(index);
if(pForder->visible==true)
{
ivisible=index;
}
}
if(ivisible>=0)
{
pForder=(CForderBar *)arForderbar.GetAt(ivisible);
if(pForder->pSon==NULL)
{
ivstartItem=0;
uparrow=false;
downarrow=false;
GetForderClientRect(ivisible,rcClient);
CBrush brush(GetSysColor(COLOR_3DSHADOW));
dc.FillRect(rcClient,&brush);
if(nStyle)
SetForderImageList(ivisible,&nrIcon,1);
else
SetForderImageList(ivisible,&smallIcon,0);
DrawForderItem(ivisible,&dc);
}
}
}
void CBarWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
/*CMenu cMenu;
cMenu.CreatePopupMenu();
cMenu.AppendMenu(MF_STRING, ID_BT_SMALL,"小图标");
cMenu.AppendMenu(MF_STRING, ID_BT_BIG,"大图标");
cMenu.AppendMenu(MF_SEPARATOR);
cMenu.AppendMenu(MF_STRING, ID_INSERT_ITEM,"插入一个项目");
// CBitmap bt;
// bt.LoadBitmap(IDB_BITMAP_SMALL);
// cMenu.SetMenuItemBitmaps(ID_SMALL,0,&bt,&bt);
// cMenu.SetMenuItemBitmaps(ID_BIG,0,&bt,&bt);
CPoint pt(point);
ClientToScreen(&pt);
cMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this);
cMenu.DestroyMenu();*/
int iForder,iItem;
BarItemMsg barItem;
HitOnPosEx(point.x,point.y,iForder,iItem);
if(iForder>=0&&iItem>=0)
{
barItem.iFolder = iForder;
barItem.iItem = iItem;
barItem.point = point;
GetParent()->SendMessage( WM_BARITEM_RBDOWN, (WPARAM)&barItem, iItem );
}
CWnd::OnRButtonDown(nFlags, point);
}
void CBarWnd::OnDestroy()
{
CWnd::OnDestroy();
KillTimer(1);
}
void CBarWnd::InsertForderItem(int iForder,const char *name,int iImage,DWORD ExData)
{
if(iForder>=0 && iForder<=arForderbar.GetSize())
{
CForderBar *pForder=(CForderBar *)arForderbar.GetAt(iForder);
pForder->AddItem(name,iImage,ExData);
}
}
// 设置一个子抽屉为打开状态
void CBarWnd::SetForderVisible(int iForder)
{
if(iForder>=0 && iForder<=arForderbar.GetSize() && arForderbar.GetSize()>0)
{
for(int i=0;i<arForderbar.GetSize();i++)
{
CForderBar *pForder=(CForderBar *)arForderbar.GetAt(i);
pForder->visible=false;
}
CForderBar *pForder=(CForderBar *)arForderbar.GetAt(iForder);
pForder->visible=true;
}
}
int CBarWnd::GetVisibleForderID()
{
CForderBar *pForder;
for(int i=0;i<arForderbar.GetSize();i++)
{
pForder=(CForderBar *)arForderbar.GetAt(i);
if(pForder->visible)
return i;
}
return -1;
}
void CBarWnd::GetForderItemText(int iForder,int iItem,CString &str)
{
CForderBar *pForder;
pForder=(CForderBar *)arForderbar.GetAt(iForder);
CBarItem *pItem=(CBarItem *)pForder->arItem.GetAt(iItem);
str.Format(pItem->itemName);
}
int CBarWnd::GetForderItemCount(int iForder)
{
if(iForder<arForderbar.GetSize())
{
CForderBar *pForder=(CForderBar *)arForderbar.GetAt(iForder);
return pForder->GetItemCount();
}
return 0;
}
void CBarWnd::OnItem(int iForder,int iItem,CPoint point)
{
//GetParent()->SendMessage( WM_BARWND_NOTIFY, iForder, iItem );
//AfxGetApp()->GetMainWnd()->SendMessage(ID_INVOICE,iForder,iItem);
CForderBar *pForder = (CForderBar *)arForderbar.GetAt( iForder );
CBarItem * pItem = (CBarItem *)pForder->arItem.GetAt( iItem );
BarItemMsg barItem;
barItem.iFolder = iForder;
barItem.iItem = iItem;
barItem.point = point;
GetParent()->SendMessage( WM_BARITEM_LBCLICK, (WPARAM)&barItem, pItem->exData );
}
void CBarWnd::OnSmall()
{
SelectForderImageStyle(false);
}
void CBarWnd::OnBig()
{
SelectForderImageStyle(true);
}
bool CBarWnd::OnInsertItem()
{
int iVisible=GetVisibleForderID();
/*CProjectNameDlg dlg;
if(iVisible>=0)
{
dlg.DoModal();
if(!dlg.result)
return false;
InsertForderItem(iVisible,dlg.m_prjName,11);
CClientDC dc(this);
DrawForderItem(iVisible,&dc);
}
int iItem=GetForderItemCount(iVisible);
CString str,st,stImage;
str.Format("%d",GetForderCount());
::WritePrivateProfileString("CWmanager","foldercount",str,".\\CWManager.ini");
str.Format("%d",GetForderItemCount(iVisible));
st.Format("folder%ditemcount",iVisible);
::WritePrivateProfileString("CWmanager",st,str,".\\CWManager.ini");
str.Format("folder%ditem%d",iVisible,iItem-1);
::WritePrivateProfileString("CWmanager",str,dlg.m_prjName,".\\CWManager.ini");
str.Format("folder%ditem%dimage",iVisible,iItem-1);
stImage.Format("%d",11);
::WritePrivateProfileString("CWmanager",str,stImage,".\\CWManager.ini");*/
return true;
}
void CBarWnd::AutoAddItemFromFileini(LPCTSTR lpAppName,LPCTSTR fileini)
{
int iItemCount;
CString str,strImage,st;
int iImage=0;
for(int i=0;i<GetForderCount();i++)
{
st.Format("folder%ditemcount",i);
iItemCount=::GetPrivateProfileInt(lpAppName,st,0,fileini);;
for(int j=0;j<iItemCount;j++)
{
str.Format("folder%ditem%d",i,j);
::GetPrivateProfileString(lpAppName,str,NULL,st.GetBuffer(128),128,fileini);
strImage.Format("folder%ditem%dimage",i,j);
iImage=::GetPrivateProfileInt(lpAppName,strImage,0,fileini);
InsertForderItem(i,st,iImage);
}
}
}
bool CBarWnd::NewItem()
{
if(OnInsertItem())
return true;
return false;
}
DWORD CBarWnd::GetItemData(int iFolder, int iItem)
{
CForderBar *pForder;
pForder=(CForderBar *)arForderbar.GetAt(iFolder);
CBarItem *pItem=(CBarItem *)pForder->arItem.GetAt(iItem);
return pItem->exData;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -