编程实用篇—C++Builder开发动画DLL

编程实用篇—C++Builder开发动画DLL,第1张

编程实用篇—C++Builder开发动画DLL,第2张

当我们在Windows98环境下进行需要较长时间的计算机操作时,如复制文件、搜索文件等,Windows会显示一个小动画来表示正在进行的操作,比死板的静止图像要丰富多彩得多。那么,我们在开发自己的软件时,是不是也可以显示一个类似这样的动画提示呢?作者开发了一个在PB下可以调用的动画DLL。因为多线程编程,PB调用的DLL函数可以在不影响应用系统运行的情况下,及时将控制权交还给PB。
I .代码和编译选项

在C++Builder中创建一个空白色DLL项目。

创建一个空白色表单,并将其属性修改为:

Borderstyle = bsdialog
边框图标全部为false
form style = fsstayontop
position = posscreencer
name = status form


在窗体上的Win32下添加一个Animate控件Animate1,并将其属性修改为Align=alTop。

在表单上的Standard下添加一个按钮控件Button_Cancel,然后在System下添加一个定时器控件Timer1,设置定时间隔时间位250,快速响应用户的取消请求。

因为PB应用系统和动画表单代码分别属于两个线程,所以不能用PB线程直接关闭动画表单线程的窗口,否则会导致系统运行异常。所以用PB线程设置关闭标志,动画线程用定时器控制定时检查标志。一旦检测到关闭标志,它将关闭窗口,清除线程标志并结束动画线程。

给出了以下编码和编码原则:

(1)DLL体代码:

/* DLL主体代码
*定义DLL公共变量
* G _ commonavi引用动画控件
动画类型
*是否选择了GI _ Cancel Button _ Cancel
按钮
* *gi_AVIType要显示的动画类型,
DLL的输入输出函数作为参数输入
* gi _ requestclose, 请找到画图过程的结束标记
* gi _ window活动画图窗口的打开状态
* lpswintille画图窗口的标题,
DLL的输出函数作为参数输入
*/
tcommonavi g _ common avi[]= {
avinone,avifindfolder,
avifindfile,avifindrouter,
aviCopyFiles,aviCopyFile,[]
int gi_Canceled=0,gi _ AVIType = 0;
int gi_RequestClose=0,gi _ window active = 0;
char LPS wintitle[256];
HWND HWND parent = NULL;
/*定义DLL的输出函数*/
extern " c " _ _ declspec(DLL export)int Pascal DLL
entry point(提示,无符号
long reason,void *);
extern " C " _ _ declspec(dll export)int Pascal
show status Window
(int AVIType,LPSTR WinTitle,long hWnd);
extern " C " _ _ declspec(dll export)
int Pascal get status(int ai _ CloseWin);
extern " C " _ _ declspec(dll export)
int Pascal CloseStatusWindow();
/*定义线程tform线程:*/
类tform线程:public t线程{
public://user声明
_ _ fastcalltform线程(bool create suspended);
void _ _ fastcall Execute(void);
};
_ _ fast call tform thread::
tform thread(Bool Create Suspended):
tThread(Create Suspended){
}
/*行生成代码绘制完成,
移动窗口的定时器控件会将其关闭,
窗口会在标记
*/
void _ _ fast call tform thread::execute(void){
gi _ window active之后被清空。
status form = new TStatusForm(NULL);
status form-> Caption = LPS wintitle;
status form-> show modal();
gi _ window active = 0;
删除状态表单;
gi _ request close = 0;
}
/*定义一个线程实例来引用一个针*/
t form thread * form thread;
/* output函数的世代代码实现
* DLL入口点32位DLL入口
* Show Status Window显示窗口打开,
它通过创建一行来创建窗口打开,
避免将
控制权返回给调用者由于窗口打开的模态属性
* getstatus取“取消”的状态,
即用户是否选择了“取消”按钮
* close
}
_ _ declspec(dllexport)int Pascal ShowStatusWindow
(int AVIType,LPSTR WinTitle,long hWnd){
hWnd parent =(hWnd)hWnd;
memset(lpsWinTitle,0,sizeof(LPS wintitle));
strncpy(lpsWinTitle,WinTitle,sizeof(LPS win Title)-1);
if(AVIType > 0 & & AVIType form thread = " new " t form thread(true);
form thread-> Priority = TP normal;
form thread-> Resume();
}
_ _ declspec(dllexport)int Pascal get status
(int ai _ CloseWin){
if(gi _ Canceled)
if(gi _ window active){
gi _ request close = 1;
while(gi _ request close);
}
return gi _ cancelled;
}
_ _ declspec(dllexport)int Pascal CloseStatusWindow(){
if(gi _ window active){
gi _ request close = 1;
while(gi _ request close);
}
return gi _ cancelled;
}

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 编程实用篇—C++Builder开发动画DLL

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情