当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>Visual C++教程

一个很COOL的对话框弹出效果

    内容:
    //1.在实现文件中的include之后加入一个辅助函数


    void WINAPI DrawWireRects(LPRECT lprcFrom, LPRECT lprcTo, UINT nMilliSecSpeed)
    {
        const int nNumSteps = 10;

    GdiFlush();
        Sleep(50);  // Let the desktop window sort itself out

    // if hwnd is null - "you have the CON".
    HDC hDC = ::GetDC(NULL);

    // Pen size, urmmm not too thick
        HPEN hPen = ::CreatePen(PS_SOLID, 2, RGB(0,0,0));

    int nMode = ::SetROP2(hDC, R2_NOT);
    HPEN hOldPen = (HPEN) ::SelectObject(hDC, hPen);

    for (int i = 0; i < nNumSteps; i++)
    {
            double dFraction = (double) i / (double) nNumSteps;

            RECT transition;
            transition.left   = lprcFrom->left + (int)((lprcTo->left - lprcFrom->left) * dFraction);
            transition.right  = lprcFrom->right + (int)((lprcTo->right - lprcFrom->right) * dFraction);
            transition.top    = lprcFrom->top + (int)((lprcTo->top - lprcFrom->top) * dFraction);
            transition.bottom = lprcFrom->bottom + (int)((lprcTo->bottom - lprcFrom->bottom) * dFraction);

    POINT pt[5];
    pt[0] = CPoint(transition.left, transition.top);
    pt[1] = CPoint(transition.right,transition.top);
    pt[2] = CPoint(transition.right,transition.bottom);
    pt[3] = CPoint(transition.left, transition.bottom);
    pt[4] = CPoint(transition.left, transition.top);

    // We use Polyline because we can determine our own pen size
    // Draw Sides
    ::Polyline(hDC,pt,5);

    GdiFlush();

    Sleep(nMilliSecSpeed);

    // UnDraw Sides
    ::Polyline(hDC,pt,5);

    GdiFlush();
    }

    ::SetROP2(hDC, nMode);
    ::SelectObject(hDC, hOldPen);

    ::ReleaseDC(NULL,hDC);
    }


    //2.为About对话框加入:
       CRect m_rectFrom;//成员变量


    //3.在About的OnCreaet中加入:
    if (!m_rectFrom.IsRectEmpty())
    {
    CRect rectTo(lpCreateStruct->x,lpCreateStruct->y,
    lpCreateStruct->x + lpCreateStruct->cx,
        lpCreateStruct->y + lpCreateStruct->cy);

       DrawWireRects(m_rectFrom, rectTo, 20);

    //  DrawAnimatedRects(m_hWnd, IDANI_CAPTION, m_rectFrom,rectTo);
      //     不要效果时

    }

      //在About的DestoryWindow上加入:

    if (!m_rectFrom.IsRectEmpty())
    {
    CRect rect;
    GetWindowRect(rect);

              rect.DeflateRect(2,2);
             DrawWireRects(rect, m_rectFrom, 20);

        // DrawAnimatedRects(m_hWnd,IDANI_CAPTION, rect, m_rectFrom);
        //  不要效果时
    }

    //激活时用:
    CAboutDlg about;
    m_btn.GetWindowRect(about.m_rectFrom);
            about.DoModal();
    ______________________________________________________________
    //如果要用于主窗口,则将上OnCreate和DestoryWindow改为主窗口的
    //变量m_rectFrom也改为主窗口的

    //然后在APP类的dlg.DoModal();之前加入:

         CRect rc(0,0,1,1);//变出的位置
         dlg.m_rectFrom=rc;

相关内容
赞助商链接