WinSail增加了动画控件CAnimalCtrl,目前只能播放GIF文件.
(1)类定义在头文件"MyFrame.h"中,
(2)文档名是:“界面控件类_CAnimalCtrl动画控件详细设计.doc”。
(3)应用该控件非常简单,一般仅需要三行代码
//分配实例
CAnimalCtrl* pAnimalCtrl1 = new CAnimalCtrl(pDialog);
//建立控件
pAnimalCtrl1->CreateObject(100, 100, 50, 50, NULL);
//装入GIF文件
pAnimalCtrl1->LoadFile("Bmp\\Earth3.Gif");
下载WinSail解压后,运行sail3000里面的Sai2000程序,在桌面右上角可以看到有一个
地球在转动。
建议将WinSail调整到256色或“16位=64K色”,此时动画控件的颜色最逼真。
注意:使用动画控件CAnimalCtrl后,Exe文件增加7K左右的代码量。
7 举例
#include <bios.h>
#include <Stdio.h>
#include <Stdlib.h>
#include <conio.h>
#include <dos.h>
#include <String.h>
#include <math.h>
#include <Symbol.H>
#include <MyFrame.h>
#include <gif.h>
#include <Lzw.h>
int far TransrateKey(CObject *)
{
return(0);
}
unsigned _stklen = 60u * 1024u;
//动画控件演示函数的一个按钮对应的回调函数
void far ClickButton1_DemoAnimalCtrl(CObject *pObj)
{
//得到动画控件对应父窗口的指针
CDialog* pDialog = (CDialog *)pObj->GetParent();
//得到动画控件的指针
CAnimalCtrl* pAnimalCtrl = (CAnimalCtrl *)
pDialog->ObjectFromID(ANIMALBASE + 1 - 1);
//选择新的一个GIF文件
char bufFile;
if (!AfxOpenFileDialog(TRUE, bufFile, NULL))
{
return;
}
//装入新的GIF文件
pAnimalCtrl->LoadFile(bufFile);
//由于每个动画的大小不同,所以必须重刷新窗口
pDialog->ShowWindow();
return;
}
//动画控件演示函数
void far Demo_AnimalCtrl()
{
//分配对话框实例
CDialog* pDialog = new CDialog;
//建立对话框
pDialog->CreateWindow(0,0,640,480,"动画控件演示程序");
//将窗口居中
pDialog->Center();
// 分配动画控件的实例
CAnimalCtrl* pAnimalCtrl = new CAnimalCtrl(pDialog);
// 建立动画控件,该控件的宽度和高度的意义不大。
pAnimalCtrl->CreateObject(5,30,40,100, NULL);
//装入动画GIF文件
pAnimalCtrl->LoadFile("Bmp\\Earth3.gif");
//设置动画控件的ID号
pAnimalCtrl->SetID(ANIMALBASE + 1 - 1);
//分配按钮实例
CButton* pButton1 = new CButton(pDialog);
//建立按钮
pButton1->CreateObject(500, 50, 80, 24, "Load");
//设置控钮对应的回调函数
pButton1->SetFc(ClickButton1_DemoAnimalCtrl);
//显示对话框
pDialog->ShowWindow();
//进入对话框的消息循环
pDialog->DoModal();
//删除对话框实例
delete pDialog;
//函数返回
return;
}
int main(int argc, char** argv)
{
//初始化WinSail系统
if (!::InitSystem(argc, argv))
{
::CloseSystem();
return(0);
}
//调用动画演示程序
::Demo_AnimalCtrl();
//退出WinSail系统
::CloseSystem();
return(1);
}
WinSail的下载地址:
http://www.firstsail.com.cn/Software.html
Last edited by firstsail on 2008-10-5 at 17:53 ]
WinSail has added the animation control CAnimalCtrl, which can currently only play GIF files.
(1) The class definition is in the header file "MyFrame.h".
(2) The document name is: "Interface Control Class _CAnimalCtrl Animation Control Detailed Design.doc".
(3) Applying this control is very simple, generally only three lines of code are needed
// Allocate instance
CAnimalCtrl* pAnimalCtrl1 = new CAnimalCtrl(pDialog);
// Create control
pAnimalCtrl1->CreateObject(100, 100, 50, 50, NULL);
// Load GIF file
pAnimalCtrl1->LoadFile("Bmp\\Earth3.Gif");
After downloading WinSail and extracting it, run the Sai2000 program in sail3000. You can see a
rotating Earth in the upper right corner of the desktop.
It is recommended to adjust WinSail to 256 colors or "16 bits = 64K colors", at this time the color of the animation control is the most realistic.
Note: After using the animation control CAnimalCtrl, the Exe file increases by about 7K of code.
7 Example
#include <bios.h>
#include <Stdio.h>
#include <Stdlib.h>
#include <conio.h>
#include <dos.h>
#include <String.h>
#include <math.h>
#include <Symbol.H>
#include <MyFrame.h>
#include <gif.h>
#include <Lzw.h>
int far TransrateKey(CObject *)
{
return(0);
}
unsigned _stklen = 60u * 1024u;
// A callback function corresponding to a button in the animation control demonstration function
void far ClickButton1_DemoAnimalCtrl(CObject *pObj)
{
// Get the pointer to the parent window corresponding to the animation control
CDialog* pDialog = (CDialog *)pObj->GetParent();
// Get the pointer to the animation control
CAnimalCtrl* pAnimalCtrl = (CAnimalCtrl *)
pDialog->ObjectFromID(ANIMALBASE + 1 - 1);
// Select a new GIF file
char bufFile;
if (!AfxOpenFileDialog(TRUE, bufFile, NULL))
{
return;
}
// Load the new GIF file
pAnimalCtrl->LoadFile(bufFile);
// Since the size of each animation is different, the window must be refreshed again
pDialog->ShowWindow();
return;
}
// Animation control demonstration function
void far Demo_AnimalCtrl()
{
// Allocate dialog instance
CDialog* pDialog = new CDialog;
// Create dialog
pDialog->CreateWindow(0,0,640,480,"Animation Control Demonstration Program");
// Center the window
pDialog->Center();
// Allocate instance of animation control
CAnimalCtrl* pAnimalCtrl = new CAnimalCtrl(pDialog);
// Create animation control, the meaning of the width and height of this control is not significant.
pAnimalCtrl->CreateObject(5,30,40,100, NULL);
// Load animation GIF file
pAnimalCtrl->LoadFile("Bmp\\Earth3.gif");
// Set the ID number of the animation control
pAnimalCtrl->SetID(ANIMALBASE + 1 - 1);
// Allocate button instance
CButton* pButton1 = new CButton(pDialog);
// Create button
pButton1->CreateObject(500, 50, 80, 24, "Load");
// Set the callback function corresponding to the button
pButton1->SetFc(ClickButton1_DemoAnimalCtrl);
// Show dialog
pDialog->ShowWindow();
// Enter the message loop of the dialog
pDialog->DoModal();
// Delete dialog instance
delete pDialog;
// Function return
return;
}
int main(int argc, char** argv)
{
// Initialize WinSail system
if (!::InitSystem(argc, argv))
{
::CloseSystem();
return(0);
}
// Call animation demonstration program
::Demo_AnimalCtrl();
// Exit WinSail system
::CloseSystem();
return(1);
}
Download address of WinSail:
http://www.firstsail.com.cn/Software.html
Last edited by firstsail on 2008-10-5 at 17:53 ]