在你调用AnimateWindow时,对话框窗口的背景还没有画好。可以在OnPaint()函数的最后调用AnimateWindow.

解决方案 »

  1.   

    是不是需要加个bool变量,来控制只有第一次运行Onpaint调用,
    还有,我发现AnimateWindow函数只有在窗口显示时才有效,如果再对话框的一个按扭中加该函数,就没有效果。 为什么?
      

  2.   

    AnimateWindow will fail in the following situations:(1) The window uses the window region. 
    (2) The window is already visible and you are trying to show the window. 
    (3) The window is already hidden and you are trying to hide the window. So, it's need not to use a boolean variable to indicate the first running of AnimateWindow. But if you use it, it will be OK.
      

  3.   

    我用了2中方法加对话框背景。1.在对话框的OnPaint()中加代码:
    void CAaaDlg::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting
        
        CString strPath;
        strPath += "c:\\aaa\\res\\111.bmp";
        CDC tempDC;
        CRect rect;
        HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
        CBitmap m_BackBmp;
        BITMAP bitmap;    
        m_BackBmp.Attach(hBitmap);    
        m_BackBmp.GetBitmap (&bitmap);
        int nHeight=bitmap.bmHeight;
        int nWidth =bitmap.bmWidth ;
        GetClientRect(rect);
        tempDC.CreateCompatibleDC(&dc);
        tempDC.SelectObject(&m_BackBmp);
        dc.BitBlt(0,0, nWidth, nHeight, &tempDC, 0, 0, SRCCOPY );
        tempDC.DeleteDC();}
    不加AnimateWindow()时,可以显示背景图片aaa.bmp,一旦在OninitDialog中加了AnimateWindow(),背景就不显示了。 有AnimateWindow效果。如果按xxxbird所说, 把AnimateWindow加在OnPaint()中代码的最后,背景可以显示,但没有AnimateWindow效果。2.直接在对话框中添加 Picture 控件,这样,在在OninitDialog中加了AnimateWindow(),背景图片可以显示, 有AnimateWindow效果。这是为什么?        (再加30分)
      

  4.   

    没有什么好的办法,要么放弃背景,要么放弃AnimateWindow。
    在AnimateWindow后执行:
    RedrawWindow();
    Invalidate();
    试试。
      

  5.   

    extern "C" WINUSERAPI BOOL WINAPI AnimateWindow (HWND hWnd, DWORD dwTime, DWORD dwFlags);class CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA
    CButton * m_pButton; // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CT1App message handlers
    BOOL CAboutDlg::OnInitDialog() 
    {
        CDialog::OnInitDialog();    m_pButton = new CButton();
        m_pButton->Create ("Test", WS_CHILD | WS_BORDER, CRect(10, 10, 200, 200), this, 100);

        // TODO: Add extra initialization here

        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
    }void CAboutDlg::OnPaint() 
    {
        CPaintDC dc(this); // device context for painting

        CString strPath;
        strPath += "c:\\test.bmp";
        CDC tempDC;
        CRect rect;
        HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
        CBitmap m_BackBmp;
        BITMAP bitmap;    
        m_BackBmp.Attach(hBitmap);    
        m_BackBmp.GetBitmap (&bitmap);
        int nHeight=bitmap.bmHeight;
        int nWidth =bitmap.bmWidth ;
        GetClientRect(rect);
        tempDC.CreateCompatibleDC(&dc);
        tempDC.SelectObject(&m_BackBmp);
        dc.BitBlt(0,0, nWidth, nHeight, &tempDC, 0, 0, SRCCOPY );
        tempDC.DeleteDC();
        AnimateWindow (m_pButton->GetSafeHwnd(), 200, 10);
    }
      

  6.   

    >>如果按xxxbird所说, 把AnimateWindow加在OnPaint()中代码的最后,背景可以显示,但没有AnimateWindow效果。按上面的方面创建的Button就可以达到要求。注意在创建要有Animate效果的窗口时,不要指定WS_VISIBLE属性。在这种方法中,背景图的重绘由Dialog本身负责。>>2.直接在对话框中添加 Picture 控件,这样,在在OninitDialog中加了AnimateWindow(),背景图片可以显示, 有AnimateWindow效果。这时的背景是由Picture控件重绘的,与Dialog窗口无关。还有一个函数,AnimatePalette可以产生动画的菜单效果。
      

  7.   

    to iProgram(赶快去掉这鬼东西): 金山词霸就作的很好,既显示背景,又有AnimateWindow效果。
      

  8.   

    to  xxxbird:
    谢谢,你的意思我明白。按你的方法可以实现对话框中控件的动画效果,但是,我想实现对话框的动画效果,并且这个对话框的背景是用LoadImage()贴上的。
      

  9.   


    呵呵,我误会了你的意思。要想达到你需要的效果,只需在AnimateWindow后调用InvalidateRect就行了。BOOL CAboutDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog(); AnimateWindow (GetSafeHwnd(), 200, AW_CENTER); InvalidateRect (NULL, TRUE);

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
      

  10.   


    不过用AnimateWindow方法效果不是很好。
     
      

  11.   

    to  xxxbird:那用什么方法更好呢? 
    我发现用 AnimateWindow()产生效果,变化时窗口是最初的背景灰色,等到变化完才贴图,
    怎么看都赶不上金山词霸的效果 !
      

  12.   


    到 www.bcgsoft.com 上去看看吧,它提供了一组制作高级界面的类,可作为参考,里面就有动画窗口的类。如果要显示菜单的动画效果,也可以考虑AnimatePalette。