📄 sheetwnd.cpp
字号:
//{
// m_GripperRect.OffsetRect(nW-50,0);
//}
m_wndHScrollBar.MoveWindow
(m_GripperRect.right+1,rcClient.bottom-18,rcClient.right-16,rcClient.bottom);
}
else*
{
CRect rcStart(0,0,0,0);
if(size>0)
rcStart = m_lItems[size-1]->m_nRect;
CRect rcGrip(rcStart.right+5,cy-16,rcStart.right+7,cy-2);
m_wndHScrollBar.MoveWindow(rcGrip.right+2,cy-18,cx-18,cy-2);
}
*/
}
void CSheetWnd::DrawTabBtn(CDC* pDC, SHEETITEM *pItem)
{
int x1 = pItem->m_nRect.left;
int x2 = pItem->m_nRect.right;
int y1 = pItem->m_nRect.top;
int y2 = pItem->m_nRect.bottom;
// create and select a thick, black pen
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
//left line
pDC->MoveTo(x1,y1);
pDC->LineTo(x1,y2-2);
//draw left corner with this diagonal
pDC->SetPixel(x1+1,y2-2,RGB(0,0,0));
pDC->SetPixel(x1+2,y2-1,RGB(0,0,0));
pDC->SetPixel(x1+3,y2,RGB(0,0,0));
//rigt line
pDC->MoveTo(x2,y1);
pDC->LineTo(x2,y2-2);
//draw right corner with this diagonal
pDC->SetPixel(x2-1,y2-2,RGB(0,0,0));
pDC->SetPixel(x2-2,y2-1,RGB(0,0,0));
pDC->SetPixel(x2-3,y2,RGB(0,0,0));
//bottom line
pDC->MoveTo(x1+3,y2-1);
pDC->LineTo(x2-3,y2-1);
// put back the old objects
pDC->SelectObject(pOldPen);
}
void CSheetWnd::DrawSelection(CDC *pDC, SHEETITEM *pItem)
{
//create and select a solid blue brush
CBrush brush(RGB(255,255,255));
CBrush* pOldBrush = pDC->SelectObject(&brush);
CRect rc(pItem->m_nRect);
rc.DeflateRect(3,0,3,3);
pDC->FillRect(&rc,&brush);
pDC->SelectObject(pOldBrush);
CRect rc1;
GetClientRect(&rc1);
CPen penBlack;
penBlack.CreatePen(PS_SOLID,1, RGB(0,0,0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
//draw to the left
pDC->MoveTo(CPoint(rc1.left,rc1.top));
pDC->LineTo(rc.left-4,rc1.top);
//draw to the right
pDC->MoveTo(rc.right+4,rc1.top);
pDC->LineTo(m_GripperRect.left,rc1.top);
pDC->SelectObject(pOldPen);
}
void CSheetWnd::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_bTracking)
ResizePane(point);
CWnd::OnMouseMove(nFlags, point);
}
void CSheetWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_bTracking)
ReleaseCapture();
m_bTracking = FALSE;
CWnd::OnLButtonUp(nFlags, point);
}
BOOL CSheetWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CPoint pCursor;
if(GetCursorPos(&pCursor))
{
ScreenToClient(&pCursor);
if (m_GripperRect.PtInRect(pCursor))
{
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_MOVE));
return TRUE;
}
}
return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
void CSheetWnd::ResizePane(CPoint pt)
{
CRect rt;
GetClientRect(&rt);
CRect sr;
m_wndHScrollBar.GetClientRect(&sr);
if(pt.x>=rt.left+32&&pt.x<=rt.right-60)
{
m_GripperRect.OffsetRect(pt.x-m_GripperRect.left,0);
CRect sRt(m_GripperRect.right+1,rt.bottom-18,rt.right-18,rt.bottom);
m_wndHScrollBar.MoveWindow(sRt);
m_wndHScrollBar.UpdateWindow();
Invalidate();
UpdateWindow();
m_bScrolled = TRUE;
}
}
void CSheetWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CSheetWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// Get the minimum and maximum scroll-bar positions.
int minpos;
int maxpos;
m_wndHScrollBar.GetScrollRange(&minpos, &maxpos);
maxpos = m_wndHScrollBar.GetScrollLimit();
// Get the current position of scroll box.
int curpos = pScrollBar->GetScrollPos();
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_LEFT: // Scroll to far left.
curpos = minpos;
break;
case SB_RIGHT: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINELEFT: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINERIGHT: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGELEFT: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
m_wndHScrollBar.GetScrollInfo(&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGERIGHT: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
m_wndHScrollBar.GetScrollInfo(&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
m_wndHScrollBar.SetScrollPos(curpos);
CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CSheetWnd::ResizeItems(CRect rc)
{
for(int pos =0;pos< m_lItems.GetSize(); pos++)
{
SHEETITEM *pItem = m_lItems[pos];
pItem->m_pwndItem->MoveWindow(0,0,rc.right,rc.bottom);
}
}
void CSheetWnd::OnNcCalcSize(BOOL bCalcValidRects,NCCALCSIZE_PARAMS* lpncsp)
{
CRect rc(lpncsp->rgrc[0]); // save the window rect
rc.DeflateRect(1,1,1,0);
lpncsp->rgrc[0] = rc;
}
void CSheetWnd::DrawBorders(CDC *pDC, CRect rc)
{
}
void CSheetWnd::DrawVcppStyle(CDC *pDC,SHEETITEM *pItem)
{
int x1 = pItem->m_nRect.left;
int x2 = pItem->m_nRect.right;
int y1 = pItem->m_nRect.top;
int y2 = pItem->m_nRect.bottom;
// create and select a thick, black pen
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
//left line
pDC->MoveTo(x1-5,y1);
//draw a diagonal line downwards
pDC->LineTo(x1+3,y2-2);
//right line
pDC->MoveTo(x2+5,y1);
pDC->LineTo(x2-3,y2-2);
//bottom line
pDC->MoveTo(x1+3,y2-2);
pDC->LineTo(x2-2,y2-2);
// put back the old objects
pDC->SelectObject(pOldPen);
int nwidth = x2+4;
int nheight = y2-2;
x1 = x1-4;
for(int y =y1;y<nheight;y++)
{
for(int x=x1;x<nwidth;x++)
{
CPoint pt(x,y);
if(pItem != m_pCurItem)
pDC->SetPixel(pt,GuiDrawLayer::GetRGBColorXP());
else
pDC->SetPixel(pt,GuiDrawLayer::GetRGBPressBXP());
}
if(y%2 == 0)
{
++x1;--nwidth;
}
}
}
void CSheetWnd::DrawVcpp3DStyle(CDC *pDC,SHEETITEM *pItem)
{
}
void CSheetWnd::TabSelChanged(int nSel)
{
SHEETITEM* pitem = m_lItems[nSel];
if(pitem->m_nScrollBar != -1)
{
if(pitem->m_nScrollBar & BOTH_SB)
{
m_wndHScrollBar.ShowWindow(SW_SHOW);
m_wndVScrollBar.ShowWindow(SW_SHOW);
}
else
if(pitem->m_nScrollBar & HORZ_SB)
{
m_wndHScrollBar.ShowWindow(SW_SHOW);
m_wndVScrollBar.ShowWindow(SW_HIDE);
}
else
{
m_wndHScrollBar.ShowWindow(SW_HIDE);
m_wndVScrollBar.ShowWindow(SW_SHOW);
}
}
}
void CSheetWnd::DrawSelVCppStype(CDC* pDC, SHEETITEM *pItem)
{
int x1 = pItem->m_nRect.left;
int x2 = pItem->m_nRect.right;
int y1 = pItem->m_nRect.top;
int y2 = pItem->m_nRect.bottom;
int nwidth = x2+5;
int nheight = y2-2;
x1 = x1-4;
for(int y =y1;y<nheight;y++)
{
for(int x=x1;x<nwidth;x++)
{
CPoint pt(x,y);
pDC->SetPixel(pt,RGB(255,255,255));
}
if(y%2 == 0)
{
++x1;--nwidth;
}
}
CPen blackPen;
blackPen.CreatePen(PS_SOLID,2, RGB(0,0,0));
CPen* pOldPen = pDC->SelectObject(&blackPen);
CRect rc1;
GetClientRect(&rc1);
CRect rc(pItem->m_nRect);rc.DeflateRect(3,0,3,3);
//draw to the left
pDC->MoveTo(rc1.left,rc1.top);
pDC->LineTo(rc.left-6,rc1.top);
//draw to the right
pDC->MoveTo(rc.right+7,rc1.top);
pDC->LineTo(m_GripperRect.left,rc1.top);
pDC->SelectObject(pOldPen);
}
void CSheetWnd::DrawSelVCppStype3d(CDC* pDC, SHEETITEM *pItem)
{
CRect rc(pItem->m_nRect);
rc.DeflateRect(3,0,3,3);
int x1 = rc.left;
int x2 = rc.right;
int y1 = rc.top;
int y2 = rc.bottom;
int nwidth = x2+5;
int nheight = y2-2;
int xx1 = x1-4;
for(int y =y1;y<nheight;y++)
{
for(int x=xx1;x<nwidth;x++)
{
CPoint pt(x,y);
pDC->SetPixel(pt,RGB(255,255,255));
}
if(y%2 == 0)
{
++xx1;--nwidth;}
}
// create and select a thick, black pen
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
//left line
pDC->MoveTo(x1-3,y1);
//draw a diagonal line downwards
pDC->LineTo(x1+3,y2-2);
//right line
pDC->MoveTo(x2+3,y1);
//draw a diagonal line downwards
pDC->LineTo(x2-3,y2-2);
//bottom line
pDC->MoveTo(x1+3,y2-2);
pDC->LineTo(x2-2,y2-2);
// put back the old objects
pDC->SelectObject(pOldPen);
CPen blackPen;
blackPen.CreatePen(PS_SOLID,2, RGB(0,0,0));
pOldPen = pDC->SelectObject(&blackPen);
CRect rc1;
GetClientRect(&rc1);
CRect rx(pItem->m_nRect);rx.DeflateRect(3,0,3,3);
//draw to the left
pDC->MoveTo(rc1.left,rc1.top);
pDC->LineTo(rx.left-6,rc1.top);
//draw to the right
pDC->MoveTo(rx.right+7,rc1.top);
pDC->LineTo(m_GripperRect.left,rc1.top);
pDC->SelectObject(pOldPen);
}
void CSheetWnd::DrawArrow(CDC* pDC,CRect rcSrc/*this must have odd dimensions*/
,COLORREF cfColor,UINT nAlign)
{
switch(nAlign)
{
case ALIGN_LEFT:
{
CPen taPen(PS_SOLID,1,cfColor);
CPen* pOldPen = pDC->SelectObject(&taPen);
int nStartPexil = (rcSrc.Height()/2);
int y = rcSrc.top+nStartPexil;
for(int x = rcSrc.left+1; x<rcSrc.right-2; x++)
{
pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
--y;
}
y = rcSrc.bottom-nStartPexil;
for(x = rcSrc.left+1; x<rcSrc.right-2; x++)
{
pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
++y;
}
int ty = rcSrc.top+nStartPexil;
int by = rcSrc.bottom-nStartPexil;
for(x = rcSrc.left+1; x<rcSrc.right-2; x++)
{
for(y =ty; y<by; y++)
pDC->SetPixel(x,y,cfColor);
++by;
--ty;
}
//very peek of triangle
//pDC->SetPixel(rcSrc.left,rcSrc.top+nStartPexil,cfColor);
pDC->SelectObject(pOldPen);
taPen.DeleteObject();
return;
}
case ALIGN_RIGHT:
{
CPen taPen(PS_SOLID,1,cfColor);
CPen* pOldPen = pDC->SelectObject(&taPen);
int nStartPexil = (rcSrc.Height()/2);
int y = rcSrc.top+nStartPexil;
for(int x = rcSrc.right-2; x>rcSrc.left+1; x--)
{
pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
--y;
}
y = rcSrc.bottom-nStartPexil;
for(x = rcSrc.right-2; x>rcSrc.left+1; x--)
{
pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
++y;
}
int ty = rcSrc.top+nStartPexil;
int by = rcSrc.bottom-nStartPexil;
for(x = rcSrc.right-2; x>rcSrc.left+1; x--)
{
for(y =ty; y<by; y++)
pDC->SetPixel(x,y,cfColor);
++by;
--ty;
}
//very peek of triangle
//pDC->SetPixel(rcSrc.right,rcSrc.top+nStartPexil,cfColor);
pDC->SelectObject(pOldPen);
taPen.DeleteObject();
return;
}
case ALIGN_UP:
{
}
case ALIGN_DOWN:
{
}
}
}
void CSheetWnd::AdjustTabs()
{
}
void CSheetWnd::RecalcLayout()
{
CRect rcClient;
GetClientRect(&rcClient);
int size = m_lItems.GetSize();
if(size>0)
{
for(int i=0; i<size; i++)
{
m_lItems[i]->m_pwndItem->MoveWindow(0,0,rcClient.Width(),rcClient.Height()-18);
m_lItems[i]->m_nRect.top = rcClient.bottom-TAB_HEIGHT;
m_lItems[i]->m_nRect.bottom = rcClient.bottom;
}
}
m_GripperRect.top = (rcClient.bottom-TAB_HEIGHT);
m_GripperRect.bottom = rcClient.bottom;
CRect rcScrll(m_GripperRect.right+1,rcClient.bottom -TAB_HEIGHT,
rcClient.right-TAB_HEIGHT,rcClient.bottom);
m_wndHScrollBar.MoveWindow(&rcScrll);
}
BOOL CSheetWnd::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -