在你调用AnimateWindow时,对话框窗口的背景还没有画好。可以在OnPaint()函数的最后调用AnimateWindow.
解决方案 »
- 8086的计时器8255的能力很低,那么高精度的计时,VC的api是通过什么实现的?
- 强制结束进程?
- 关于VC 中的double类型。
- Dword和CTypePtrArray的转换
- 在一个循环里,我想获得编辑框中的值,怎么做?
- HSTMT 是什么?
- 索取简单的三层应用中COM组件的源程序
- 谢谢先. 我需要将文件保存为PDF格式.用Adobe Reader可以打开的. 望大家给点相关的资料. 小弟刚学.没有高低要求.只要是关于这个方面的都可
- LIFEForSoft!请给我visual c++mfc编程实例极其扩展编程实例的!
- MFC无法向文本输出数据
- 请教高手?
- 要将语音,传真等保存到MS SQL Server数据库中,如何做?有什么好的方法或建议?用VC++开发
还有,我发现AnimateWindow函数只有在窗口显示时才有效,如果再对话框的一个按扭中加该函数,就没有效果。 为什么?
(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.
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分)
在AnimateWindow后执行:
RedrawWindow();
Invalidate();
试试。
{
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);
}
谢谢,你的意思我明白。按你的方法可以实现对话框中控件的动画效果,但是,我想实现对话框的动画效果,并且这个对话框的背景是用LoadImage()贴上的。
呵呵,我误会了你的意思。要想达到你需要的效果,只需在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
}
不过用AnimateWindow方法效果不是很好。
我发现用 AnimateWindow()产生效果,变化时窗口是最初的背景灰色,等到变化完才贴图,
怎么看都赶不上金山词霸的效果 !
到 www.bcgsoft.com 上去看看吧,它提供了一组制作高级界面的类,可作为参考,里面就有动画窗口的类。如果要显示菜单的动画效果,也可以考虑AnimatePalette。