有背景图片的对话框在用 AnimateWindow 时遇到的问题?

jeffreyren 2001-07-02 01:37:05
我在对话框的Oninitdialog函数里添加了 AnimateWindow函数,
如:
BOOL AnimateWindow(GetSafeHwnd( ) ,200, AW_CENTER);

效果是出来了,从小变大,但是,我的对话框是有背景图片的,在变化时,
对话框还是原来灰色的,等到完全变到标准形状后才贴上背景图,看起来很难看。
这是怎么回事?如何解决?
谢谢
...全文
525 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxxbird 2001-07-03
  • 打赏
  • 举报
回复

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




xxxbird 2001-07-03
  • 打赏
  • 举报
回复

到 www.bcgsoft.com 上去看看吧,它提供了一组制作高级界面的类,可作为参考,里面就有动画窗口的类。如果要显示菜单的动画效果,也可以考虑AnimatePalette。
jeffreyren 2001-07-03
  • 打赏
  • 举报
回复
to xxxbird:

那用什么方法更好呢?
我发现用 AnimateWindow()产生效果,变化时窗口是最初的背景灰色,等到变化完才贴图,
怎么看都赶不上金山词霸的效果 !
jeffreyren 2001-07-03
  • 打赏
  • 举报
回复
谢谢 xxxbird
xxxbird 2001-07-02
  • 打赏
  • 举报
回复

呵呵,我误会了你的意思。要想达到你需要的效果,只需在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
}
jeffreyren 2001-07-02
  • 打赏
  • 举报
回复
to xxxbird:
谢谢,你的意思我明白。

按你的方法可以实现对话框中控件的动画效果,但是,我想实现对话框的动画效果,并且这个对话框的背景是用LoadImage()贴上的。
jeffreyren 2001-07-02
  • 打赏
  • 举报
回复
to iProgram(赶快去掉这鬼东西): 

金山词霸就作的很好,既显示背景,又有AnimateWindow效果。
xxxbird 2001-07-02
  • 打赏
  • 举报
回复
>>如果按xxxbird所说, 把AnimateWindow加在OnPaint()中代码的最后,背景可以显示,但没有AnimateWindow效果。

按上面的方面创建的Button就可以达到要求。注意在创建要有Animate效果的窗口时,不要指定WS_VISIBLE属性。在这种方法中,背景图的重绘由Dialog本身负责。

>>2.直接在对话框中添加 Picture 控件,这样,在在OninitDialog中加了AnimateWindow(),背景图片可以显示, 有AnimateWindow效果。

这时的背景是由Picture控件重绘的,与Dialog窗口无关。

还有一个函数,AnimatePalette可以产生动画的菜单效果。





xxxbird 2001-07-02
  • 打赏
  • 举报
回复
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);
}
iProgram 2001-07-02
  • 打赏
  • 举报
回复
没有什么好的办法,要么放弃背景,要么放弃AnimateWindow。
在AnimateWindow后执行:
RedrawWindow();
Invalidate();
试试。
jeffreyren 2001-07-02
  • 打赏
  • 举报
回复
please
jeffreyren 2001-07-02
  • 打赏
  • 举报
回复
我用了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分)
xxxbird 2001-07-02
  • 打赏
  • 举报
回复
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.

jeffreyren 2001-07-02
  • 打赏
  • 举报
回复
是不是需要加个bool变量,来控制只有第一次运行Onpaint调用,
还有,我发现AnimateWindow函数只有在窗口显示时才有效,如果再对话框的一个按扭中加该函数,就没有效果。 为什么?
xxxbird 2001-07-02
  • 打赏
  • 举报
回复
在你调用AnimateWindow时,对话框窗口的背景还没有画好。可以在OnPaint()函数的最后调用AnimateWindow.

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧