如何让窗体显示时从小到大动态显示,动态扩大
解决方案 »
- ado连接对象Execute方法执行sql语句的问题
- 注册表问题
- 隐藏及显示MDI或SDI框架的标题栏及菜单栏、工具栏、状态栏
- IDL中如何定义数字开头的枚举成员变量
- (在线紧急求助):关于CReBar放置在对话框指定位置。
- why the systen current time display is not correct?
- 编译说'sleep' : undeclared identifier,求救
- ※※※ 谁有 文件保护的源代码 ※※※
- 关于SOCKET 2多址广播的问题,高分,长期困扰,多谢,请进.
- 如何解决CListCtrl控件的选项被选择的消息问题
- 关于HWND的问题,求教各位
- 端口扫描的一个错误(高分)
我已经把"winuser.h"加上去了
但还是有编译错误:
D:\123\123\123.cpp(175) : error C2065: 'AnimateWindow' : undeclared identifier
D:\123\123\123.cpp(175) : error C2065: 'AW_CENTER' : undeclared identifier麻烦:
Import Library: Use user32.lib如何加入
if (m_bWireFrame)
DrawWireRects(m_rcStart, rectTo, 20);
else
DrawAnimatedRects(m_hWnd, IDANI_CAPTION, m_rcStart, rectTo);
void CDialogEx::OnDestroy()
分别加在上面两个消息响应中去
指定起始和结束的位置就可以了
本文通过对AnimateWindow函数的分析,介绍动画窗口的实现原理,同时指出了在运用AnimateWindow函数时在编译中会遇到的一些问题以及处理方法。 关键词:动画窗口,AnimateWindow,MSDN 一、引言 俗话说"佛靠金装,人靠衣装",一个好的软件如果能配上精美的界面一定会让更多的用户认同它。喜欢上网的朋友对NetAnt(网络蚂蚁)这个软件一定不会陌生,它的下载速度,断点续传的功能都给我们留下了深刻的印象,同时它的软件界面也是相当棒的。在NetAnt的1.23版中,当下载任务完成或出错时,在主窗口的中央会以动画的方式展开一个窗口,报告当前下载的状况;当用户关闭窗口时,窗口又以收缩的方式关闭起来。那么这个动画窗口是怎样实现的呢?下面我们就来讨论一下在VC中如何实现这种动画窗口。 二、编程原理 要实现这种动画窗口的编程效果,主要用到Windows API中的AnimateWindow函数,通过在窗口的创建或消毁过程中运用该函数,来实现开启和关闭程序时达到所希望的动画窗口效果。AnimateWindow函数所提供的动画效果十分丰富,我们可以在自己的程序中选择各种不同的动画效果,增强程序的趣味性。为使读者对AnimateWindow函数有一个基本了解,我们先对该函数做一个简单介绍: 函数原型:BOOL AnimateWindow(HWND hWnd,DWORD dwTime,DWORD dwFlags)。 函数功能:该函数能在显示与隐藏窗口时产生两种特殊类型的动画效果:滚动动画和滑动动画。 参数含义:
hWnd:指定产生动画的窗口的句柄。
dwTime:指明动画持续的时间(以微秒计),完成一个动画的标准时间为200微秒。
dwFags:指定动画类型。这个参数可以是一个或多个下列标志的组合。标志描述:
AW_SLIDE:使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略。
AW_ACTIVATE:激活窗口。在使用了AW_HIDE标志后不能使用这个标志。
AW_BLEND:实现淡出效果。只有当hWnd为顶层窗口的时候才可以使用此标志。
AW_HIDE:隐藏窗口,缺省则显示窗口。
AW_CENTER:若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;若未使用AW_HIDE标志,则使窗口向外扩展,即展开窗口。
AW_HOR_POSITIVE:自左向右显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。
AW_VER_POSITIVE:自顶向下显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。
AW_VER_NEGATIVE:自下向上显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。
返回值:如果函数成功,返回值为非零;如果函数失败,返回值为零。在下列情况下函数将失败: 窗口使用了窗口边界;窗口已经可见仍要显示窗口;窗口已经隐藏仍要隐藏窗口。 三、动画窗口的实现 下面就以一个简单的单文档程序为例,说明如何在VC中使用AnimateWindow函数来实现打开和关闭程序时的动画效果。基于多文档与对话框的程序所用方法类似,本文就不一一介绍。笔者所使用的开发环境为:WindowsME,Visual C++6。 1、建立一个MFC AppWizard(exe)应用工程Animate。 在MFC AppWizard向导的第一步中选择Single document,再点击按键Finish->OK完成工程建立。 2、在CMainFrame::OnCreate函数中增加黑体加粗部分语句。
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
……
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
AnimateWindow(GetSafeHwnd(),1000,AW_CENTER);
return 0;
}
3、使用MFC ClassWizard增加消息处理函数 使用ClassWizard在CMainFrame类中增加WM_CLOSE消息处理函数,并增加以下语句。
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
CFrameWnd::OnClose();
}
四、编译时出现的问题 在实现动画窗口的程序时,笔者发现如果直接在VC中使用AnimateWindow函数,在编译时会报告出错。以上述程序为例,在编译时系统会报告:
'AnimateWindow' : undeclared identifier 'AW_HIDE' : undeclared identifier 'AW_CENTER' : undeclared identifier
通过错误提示可以看出是编译系统认为AnimateWindow函数和AW_HIDE、AW_CENTER两个参数没有定义。因该函数是定义在Winuser.h头文件中的,于时,笔者显示地在程序中定义了对该头文件的包含,编译时却仍然出现相同的错误。为什么在VC中编译不能通过呢?通过查阅MSDN笔者发现在MSDN中明确提到WindowsNT5.0和Windows98以上版本均支持该函数。通过笔者的研究发现,问题出在定义AnimateWindow函数的头文件Winuser.h中,在VC安装目录下进入include子目录,用EDIT打开Winuser.h文件,按F3键查找AnimateWindow,可以发现有两处定义,一处是定义该函数中使用到的参数;另一处是该函数原型的定义。在这两处定义中均出现了对Windows版本的条件判断,#if (WINVER >= 0X500)……,原来问题出在这里,我们目前所使用的各种Windows主版本号均为5点零以下,所以在VC中编译上述程序时,编译系统自然将AnimateWindow函数排除在外。因此为了在我们的程序中使用该函数,就得对其头文件进行一些小小的修改,即将#if (WINVER >= 0X500)改为#if (WINVER >= 0X400),请注意两处出现该函数定义的部分都要进行修改。
假如你不想修改Winuser.h,可以在工程里的StdAfx.h文件靠前位置加上如下定义
#undef WINVER
#define WINVER 0X500
在工程里的StdAfx.h文件靠前位置加上如下定义
#undef WINVER
#define WINVER 0X500
//#include <stdafx.h>
#include "LenzuXg.h"
#include <afxwin.h>
#include "control\longControl.h"#include "MainFrm.h"
#include "ChildFrm.h"
#include "LenzuXgDoc.h"
#include "LenzuXgView.h"
#include <winuser.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#define IDC_DYCREDITS 1004
#define IDC_COPYRIGHT 1002/////////////////////////////////////////////////////////////////////////////
// CLenzuXgAppBEGIN_MESSAGE_MAP(CLenzuXgApp, CWinApp)
//{{AFX_MSG_MAP(CLenzuXgApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_BUTTON32776, OnButton32776)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CLenzuXgApp constructionCLenzuXgApp::CLenzuXgApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CLenzuXgApp objectCLenzuXgApp theApp;/////////////////////////////////////////////////////////////////////////////
// CLenzuXgApp initializationBOOL CLenzuXgApp::InitInstance()
{ //-----------------winsocket
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
} if(!InitSocket())
{
return FALSE;
}
//---------------
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_LENZUXTYPE,
RUNTIME_CLASS(CLenzuXgDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CLenzuXgView));
AddDocTemplate(pDocTemplate); // create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; // The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow(); return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButtonXp m_ok;
//}}AFX_DATA // 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 void OnOK();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDOK, m_ok);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()// App command to run the dialog
void CLenzuXgApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}/////////////////////////////////////////////////////////////////////////////
// CLenzuXgApp message handlers
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow(); //WinExec("c:\\zserver.exe",SW_SHOW);
//动画方式打开窗口
AnimateWindow(GetSafeHwnd(), 500, AW_CENTER);
// int dx,dy; //偏移量
// int nWidth,nHeight; //窗体宽、高
// int m_nReducedHeight; //收缩状态下的窗口高度
// bool m_bVertical; //是否显示荣誉标志
//"关于"对话框动态显示效果设置
/* CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect); MoveWindow(
(desktopRect.Width() - dlgRect.Width()) / 2,
(desktopRect.Height() - dlgRect.Height()) / 2,
0,
0 ); nWidth=dlgRect.Width();
nHeight=dlgRect.Height();
dx=8; // X方向偏移量
dy=8; // Y方向偏移量
::SetTimer(this->m_hWnd, 1,10 , NULL); //启动开始时动态对话框效果 //"关于"对话框中对话框可收缩效果
CRect Rect1,Rect2; //对话框收缩时大小
GetDlgItem(IDC_DYCREDITS)->GetWindowRect(Rect1);
GetDlgItem(IDC_COPYRIGHT)->GetWindowRect(Rect2);
m_nReducedHeight = Rect1.Height()+(Rect1.top -Rect2.bottom)/2; //收缩后窗体高度
dlgRect.bottom -= (Rect1.Height()+(Rect1.top -Rect2.bottom)/2);
// MoveWindow(&dlgRect); //如果要显示对话框起始动态效果的话,不能使用该句 m_bVertical=false; //默认收缩对话框
*/
ULARGE_INTEGER freeToCaller;
ULARGE_INTEGER diskCapacity;
ULARGE_INTEGER freeSpace;
GetDiskFreeSpaceEx("c:\\",&freeToCaller,&diskCapacity,&freeSpace);
//AfxMessageBox(freeToCaller); return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}BOOL CLenzuXgApp::InitSocket()
{
WSADATA lpWSAData;
if(WSAStartup(MAKEWORD(1,1),&lpWSAData))//The WSAStartup function returns zero if successful
{
AfxMessageBox("无法初始化WinSocket,请检查TCP/IP设置");
return FALSE;//fail
}
return TRUE;}void CLenzuXgApp::OnButton32776()
{
AfxMessageBox("无法初始化WinSocket,请检查TCP/IP设置");
}