⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw.cpp

📁 网络入侵检测系统 网络入侵检测系统 网络入侵检测系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        }
        if ( !DB_ISPRESSED1(wStyle) )
        {
            if ( DB_ISFLAT(wStyle) )
            {
                CRect rcBtn (rc.left, (rc.top+rc.bottom)/2/*+rc.Height()%2*/, rc.right, rc.bottom);

                if ( DB_ISENABLED(wStyle) && DB_ISOVER(wStyle) )
                {
                    pen.Color (crBorder);
                    brush.Color (DB_ISPRESSED(wStyle) ? crPressed : crOver);
                    pDC->Rectangle (rcBtn);
                }
                else if ( !DB_ISTRANSPARENT(wStyle) )
                {
                    pen.Color (::GetSysColor (DB_ISBORDER(m_wStyle) ? COLOR_3DSHADOW : COLOR_WINDOW));
                    pDC->Rectangle (rcBtn);
                }
            }
            else
            {
                CRect rcBtn (rc.left, (rc.top+rc.bottom)/2+rc.Height()%2, rc.right, rc.bottom);

                pDC->DrawFrameControl (rcBtn, DFC_BUTTON, DFCS_BUTTONPUSH|(DB_ISPRESSED2(wStyle) ? DFCS_PUSHED : 0));
            }
        }
        if ( DB_ISFLAT(wStyle) )
        {
            crText = DB_ISENABLED(wStyle) && pDC->GetPixel (rc.left+1, rc.top+1) == crOver ? RGB(0,0,0) : ::GetSysColor (COLOR_BTNTEXT);
            pen.Color (DB_ISPRESSED(wStyle) ? RGB(240,240,240) : DB_ISENABLED(wStyle) ? crText : ::GetSysColor (COLOR_GRAYTEXT));
        }
        else
        {
            pen.Color (::GetSysColor (DB_ISENABLED(wStyle) ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
        }
        if ( !DB_ISPRESSED2(wStyle) )
        {
            _DrawTriangle (pDC, (rc.left+rc.right)/2 + ((DB_ISPRESSED1(wStyle)&&!DB_ISFLAT(wStyle)) ? 1 : 0),
                                (rc.top*3+rc.bottom)/4 + ((DB_ISPRESSED1(wStyle)||DB_ISFLAT(wStyle)) ? 1 : 0) - 2, 3, false);
        }
        if ( !DB_ISPRESSED1(wStyle) )
        {
            _DrawTriangle (pDC, (rc.left+rc.right)/2 + ((DB_ISPRESSED2(wStyle)&&!DB_ISFLAT(wStyle)) ? 1 : 0),
                                (rc.top+rc.bottom*3)/4 + ((DB_ISPRESSED2(wStyle)&&!DB_ISFLAT(wStyle)) ? 1 : 0) + 1, 3, true);
        }
    }
    else
    {
        if ( DB_ISFLAT(wStyle) )
        {
            if ( DB_ISENABLED(wStyle) && DB_ISOVER(wStyle) )
            {
                pen.Color (crBorder);
                brush.Color (DB_ISPRESSED(wStyle) ? crPressed : crOver);
                pDC->Rectangle (rc);
            }
            else if ( !DB_ISTRANSPARENT(wStyle) )
            {
                pen.Color (::GetSysColor (DB_ISBORDER(m_wStyle) ? COLOR_3DSHADOW : COLOR_WINDOW));
                pDC->Rectangle (rc);
            }
        }
        else
        {
            pDC->DrawFrameControl (rc, DFC_BUTTON, DFCS_BUTTONPUSH|(DB_ISPRESSED(wStyle) ? DFCS_PUSHED : 0));
        }
        switch ( DB_GETTYPE(wStyle) )
        {
            case DB_3POINTS:
                if ( DB_ISFLAT(wStyle) )
                {
                    crText = DB_ISENABLED(wStyle) && pDC->GetPixel (rc.left+1, rc.top+1) == crOver ? RGB(0,0,0) : ::GetSysColor (COLOR_BTNTEXT);
                    crText = DB_ISPRESSED(wStyle) ? RGB(240,240,240) : DB_ISENABLED(wStyle) ? crText : ::GetSysColor (COLOR_GRAYTEXT);
                }
                else
                {
                    crText = ::GetSysColor (DB_ISENABLED(wStyle) ? COLOR_BTNTEXT : COLOR_GRAYTEXT);
                }
                crText = pDC->SetTextColor (crText);
                pDC->SetBkMode (TRANSPARENT);
                pDC->DrawText (_T("..."), 3, CRect(rc.left + ((DB_ISPRESSED(wStyle)||DB_ISFLAT(wStyle)) ? 2 : 1),
                                                   rc.top, rc.right, rc.bottom + ((DB_ISPRESSED(wStyle)&&!DB_ISFLAT(wStyle)) ? 1 : 0)),
                               DT_LEFT|DT_BOTTOM|DT_SINGLELINE);
                pDC->SetTextColor (crText);
                break;

            case DB_UP:
            case DB_DOWN:
                if ( DB_ISFLAT(wStyle) )
                {
                    crText = DB_ISENABLED(wStyle) && pDC->GetPixel (rc.left+1, rc.top+1) == crOver ? RGB(0,0,0) : ::GetSysColor (COLOR_BTNTEXT);
                    pen.Color (DB_ISPRESSED(wStyle) ? RGB(240,240,240) : DB_ISENABLED(wStyle) ? crText : ::GetSysColor (COLOR_GRAYTEXT));
                }
                else
                {
                    pen.Color (::GetSysColor (DB_ISENABLED(wStyle) ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
                }
                _DrawTriangle (pDC, (rc.left+rc.right)/2 + ((DB_ISPRESSED(wStyle)&&!DB_ISFLAT(wStyle)) ? 1 : 0),
                                    (rc.top+rc.bottom)/2 + ((DB_ISPRESSED(wStyle)||DB_ISFLAT(wStyle)) ? 2 : 1) - ((DB_GETTYPE(wStyle) == DB_UP) ? 3 : 0),
                                    4, DB_GETTYPE(wStyle) == DB_DOWN);
                break;

            case DB_CROSS:
                {
                    int x1 = (rc.left*2+rc.right)/3-1;
                    int x2 = (rc.left+rc.right*2)/3;
                    int y1 = (rc.top*2+rc.bottom)/3-1;
                    int y2 = (rc.top+rc.bottom*2)/3-1;

                    if ( DB_ISFLAT(wStyle) )
                    {
                        x2++; y2++;
                    }
                    else if ( DB_ISPRESSED(wStyle) )
                    {
                        x1++; y1++;
                        x2++; y2++;
                    }
                    if ( DB_ISFLAT(wStyle) )
                    {
                        crText = DB_ISENABLED(wStyle) && pDC->GetPixel (x1, y1+1) == crOver ? RGB(0,0,0) : ::GetSysColor (COLOR_BTNTEXT);
                        pen.Color (DB_ISPRESSED(wStyle) ? RGB(240,240,240) : DB_ISENABLED(wStyle) ? crText : ::GetSysColor (COLOR_GRAYTEXT));
                    }
                    else
                    {
                        pen.Color (::GetSysColor (DB_ISENABLED(wStyle) ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
                    }
                    pDC->MoveTo (x1, y1);
                    pDC->LineTo (x2, y2+1);
                    pDC->MoveTo (x1+1, y1);
                    pDC->LineTo (x2+1, y2+1);
                    pDC->MoveTo (x2-1, y1);
                    pDC->LineTo (x1-1, y2+1);
                    pDC->MoveTo (x2, y1);
                    pDC->LineTo (x1, y2+1);
                }
                break;
        }
    }
}

/////////////////////////////////////////////////////////////////////////////
static WORD s_wNotify = 0;
void CALLBACK EXPORT CDrawButton_TimerProcRepeat (HWND hWnd, UINT, UINT, DWORD)
{
    ::SendMessage (::GetParent (hWnd), WM_COMMAND, MAKELONG (GetDlgCtrlID (hWnd), s_wNotify), (LPARAM)hWnd);
}

/////////////////////////////////////////////////////////////////////////////
DWORD CDrawButton::Click (CWnd* pWnd, CPoint pt, UINT nIDRepeat) const
{
    // don't handle if capture already set
    if ( ::GetCapture() != NULL || !DB_ISENABLED(m_wStyle) )
    {
        return DB_DEFAULT;
    }
    // set capture to the window which received this message
    pWnd->SetCapture();
    ASSERT(pWnd == CWnd::GetCapture());

    bool  bDown = false, bClick = false;
    int   nSpinType = DB_PRESSED;
    CRect rcBtn(m_Rect);

    if ( DB_GETTYPE(m_wStyle) == DB_UPDOWN )
    {
        if ( pt.y >= (rcBtn.top+rcBtn.bottom)/2 )
        {
            nSpinType = DB_PRESSED2;
            rcBtn.top = (rcBtn.top+rcBtn.bottom)/2;
        }
        else
        {
            rcBtn.bottom = (rcBtn.top+rcBtn.bottom)/2;
        }
        if ( nIDRepeat != 0 )
        {
            s_wNotify = (nSpinType == DB_PRESSED) ? LOWORD(nIDRepeat) : HIWORD(nIDRepeat);

            if ( !pWnd->SetTimer (nIDRepeat, 100, &CDrawButton_TimerProcRepeat) )
            {
                nIDRepeat = 0;
            }
        }
    }
    // get messages until capture lost or cancelled/accepted
    while ( true )
    {
        bool bNewDown = ::PtInRect (rcBtn, pt) != 0;

        if ( bNewDown != bDown )
        {
            bDown = bNewDown;

            if ( DB_ISWINDOWDC(m_wStyle) )
            {
                CWindowDC cDC (pWnd);
                Draw (&cDC, m_wStyle|(bDown ? nSpinType : DB_DEFAULT));
            }
            else
            {
                CClientDC cDC (pWnd);
                Draw (&cDC, m_wStyle|(bDown ? nSpinType : DB_DEFAULT));
            }
        }
        MSG msg;
        VERIFY(::GetMessage(&msg, NULL, 0, 0));

        if ( CWnd::GetCapture() != pWnd )
        {
            DispatchMessage (&msg);
            goto ExitLoop;
        }
        switch ( msg.message )
        {
            // handle movement messages
            case WM_MOUSEMOVE:
                pt.x = (short signed)LOWORD(msg.lParam);
                pt.y = (short signed)HIWORD(msg.lParam);

                if ( DB_ISWINDOWDC(m_wStyle) )
                {
                    pWnd->ClientToScreen (&pt);
                    pt -= CWindowRect(pWnd).TopLeft();
                }
                break;

            // handle accept messages
            case WM_LBUTTONUP:
                bClick = bDown;
                goto ExitLoop;

            // handle cancel messages
            case WM_KEYDOWN:
                if ( msg.wParam != VK_ESCAPE )
                {
                    break;
                }
                // continue...

            case WM_CANCELMODE:
            case WM_RBUTTONDOWN:
                goto ExitLoop;

            case WM_TIMER:
                if ( msg.wParam == nIDRepeat && !bDown )
                {
                    break;
                }
                // continue...

            default:
                // just dispatch rest of the messages
                DispatchMessage (&msg);
                break;
        }
    }
ExitLoop:
    ReleaseCapture();
    if ( DB_GETTYPE(m_wStyle) == DB_UPDOWN && nIDRepeat != 0 )
    {
        pWnd->KillTimer (nIDRepeat);
    }
    if ( bDown )
    {
        if ( DB_ISWINDOWDC(m_wStyle) )
        {
            CWindowDC cDC (pWnd);
            Draw (&cDC);
        }
        else
        {
            CClientDC cDC (pWnd);
            Draw (&cDC);
        }
    }
    return bClick ? (DB_GETTYPE(m_wStyle)|nSpinType) : DB_DEFAULT;
}

/////////////////////////////////////////////////////////////////////////////
void CALLBACK EXPORT CDrawButton_TimerProcMouseOver (HWND hWnd, UINT, UINT, DWORD)
{
    CPoint pt;

    ::GetCursorPos (&pt);

    // WM_MOUSEMOVE isn't necessary if pt is over the window !
    
    if ( ::WindowFromPoint (pt) != hWnd )
    {
        ::ScreenToClient (hWnd, &pt);
        ::PostMessage (hWnd, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
    }
}

/////////////////////////////////////////////////////////////////////////////
void CDrawButton::CheckForMouseOver (CWnd* pWnd, CPoint pt)
{
    if ( DB_ISFLAT(m_wStyle) )
    {
        if ( !DB_ISOVER(m_wStyle) && PtInRect (pt) )
        {
            if ( pWnd->SetTimer (54321, 300, &CDrawButton_TimerProcMouseOver) )
            {
                m_wStyle |= DB_OVER;

                CClientDC cDC (pWnd);

                Draw (&cDC);
            }
        }
        else if ( DB_ISOVER(m_wStyle) && !PtInRect (pt) )
        {
            pWnd->KillTimer (54321);

            m_wStyle &= ~DB_OVER;

            pWnd->InvalidateRect (m_Rect);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -