📄 h20000127-27.htm
字号:
<html><head><script language="JavaScript"> function reset(){ for ( var i=0; i < document.Form1.elements.length; i++ ) { document.Form1.elements[i].options[0].selected=true }}function going(url){ parent.location=url; reset();}</script><style><!--A:link {text-decoration: none; color: #000000; font-family: 宋体}A:visited {text-decoration: none; color: #000000; font-family: 宋体}A:active {text-decoration: none; font-family: 宋体}A:hover {text-decoration: underline:#ffffff; color: #ff0000}body,table {font-size: 9pt; font-family: 宋体}.H1 {font-size: 9pt ; line-height:9pt; align=center}.ourfont {font-size: 9pt ; line-height:9pt; }.ourfont1 {font-size: 9pt ; line-height:9pt; }--></style><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>利用C++ Builder开发动画DLL</title></head><body topmargin="0" leftmargin="0"><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td><p class="content4"><span class="font"><img border="0" height="3" src="../../soft/pix.gif" width="700"></span></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td bgColor="#3399ff" width="658"><p class="content4"><span class="font"> </span><a style="text-decoration: none; color: rgb(255,255,255)" href="../os/H00705-2.htm">操作系统</a><font color="#FFFFFF"><span class="font"><span> |</span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../image/H00705-14.htm">图像处理</a><font color="#FFFFFF"><span>|<span class="font"> </span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../autoCAD/H00705-19.htm">辅助设计</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="../data/H00705-18.htm">数 据 库</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="H00706-1.htm">高级编程</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="../netuse/H00705-20.htm">网络应用</a><font color="#FFFFFF"><span><span class="font"> | </span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../webpage/H00705-21.htm">网页制作</a><font color="#FFFFFF"><span><span class="font"> |</span></span></font> <a style="color: rgb(255,255,255); text-decoration: none" href="../technic/H00706-3.htm">技术交流</a> <font color="#000000"><strong> <a style="COLOR: rgb(255,255,255); TEXT-DECORATION: none" href="http://202.100.13.77/clslyb/default.asp?clsid=jiaoc">过客留言</a></strong></font></td> <td bgColor="#3399ff" width="32"><p align="center" class="content4"><a href="http://202.100.13.77/clslyb/default.asp?clsid=jiaoc"><img src="../../soft/email.gif" alt="email.gif (493 字节)" border="0" WIDTH="20" HEIGHT="19"></a></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td align="middle" bgColor="#3399ff" vAlign="top" width="130"></td> <td vAlign="top" width="20"><p class="content4"><img src="../../soft/jiao2.gif" alt="jiao2.gif (176 字节)" WIDTH="14" HEIGHT="14"></td> <td vAlign="top" width="550"><p class="content4" align="center"><span class="font"></span></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td bgColor="#000000" height="1" width="130"><p class="content4"><span class="font"></span></td> <td height="1" width="20"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="200"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="200"><p class="content4"><span class="font"></span></td> <td height="1" width="10"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="140"><p class="content4"><span class="font"></span></td> </tr> <tr> <td align="middle" bgColor="#3399FF" vAlign="top" width="130"><p class="content4" align="center"><span class="font"><br> </span></p> <p class="content4" align="center"><strong><a style="text-decoration: none; color: rgb(255,255,255)" href="../os/H00705-2.htm">操作系统</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../image/H00705-14.htm">图像处理</a></strong><br> <font color="#ff0000"><b><br> </b></font><strong><a style="color: rgb(255,255,255); text-decoration: none" href="../autoCAD/H00705-19.htm">辅助设计</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../data/H00705-18.htm">数 据 库</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="H00706-1.htm">高级编程</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../netuse/H00705-20.htm">网络应用</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../webpage/H00705-21.htm">网页制作</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../technic/H00706-3.htm">技术交流</a></strong></p> <div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tbody></tbody> </table> </center></div><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tbody></tbody> </table> </td> <td align="middle" vAlign="top" width="20"><p align="left" class="content4"><span class="font"><span><br> </span></span></td> <td colSpan="2" vAlign="top" width="400"> <font SIZE="2"><p align="center">利用C++ Builder开发动画DLL </p> <p>厦门前沿科技开发有限公司 刘学平</p> <p>---- 我们在Windows98环境下执行拷贝文件、查找文件或计算机等耗时比较长的操作时,Windows会显示一个小小的动画,指示正在进行的操作,与死板的静止图像相比增色不少。那么我们自己开发软件时,能否也显示一个这样的动画提示呢?我在开发一个外贸应用软件系统时,遇到的数据量很大,当通过复合条件查找时,因为不是数据库表的每个项目都有索引,所以很费时,系统也会表现出长时间停顿,用户感觉极为不爽。我经过一段时间的探索,开发了一个能够在采用的开发环境PowerBuilder下调用的动画DLL,由于采用多线程编程,PB调用的DLL函数能够及时将控制权交还为PB,不影响应用系统的运转。用户能够看到一个东西在动,也就不会想到系统是不是停止响应了,感觉时间也似乎没那么久了。 </p> <p>---- 代码与编译选项 </p> <p>---- (1) 在C++Builder的File菜单下选择New,在New Item对话框的New属性中选择DLL,C++Builder就会创建一个空白的DLL项目。 </p> <p>---- (2) 在File菜单下选择New Form,C++Builder创建一个空白的Form,修改它的属性为 </p> <p>BorderStyle=bsDialog</p> <p>BorderIcons的子属性均为False</p> <p>FormStyle=fsStayOnTop</p> <p>Position= poScreenCenter</p> <p>Name=StatusForm</p> <p>---- (3) 在Form上添加一个Win32下的Animate控件Animate1,修改它的属性为 </p> <p>Align=alTop</p> <p>---- (4) 在Form上添加一个Standard下的Button控件Button_Cancel,再添加System下的Timer控件Timer1,设置定时Interval时间位250,以较快的响应用户的取消请求。 </p> <p>---- 因为PB应用系统与动画窗体代码分别属于两个线程,不能采用PB线程直接关闭动画窗体线程的窗口,否则会引起系统运行不正常,因此采用PB线程设置关闭标志,而动画线程采用Timer控件定时检查标志,一旦检测到关闭标志,就关闭窗口,清除线程标志,结束动画线程。 </p> <p>---- 下面给出编码及编码原理: </p> <p>---- 1.DLL DLL主体代码: </p> <p>/**********************************</p> <p>* DLL主体代码</p> <p>* 定义DLL公用变量</p> <p>* g_CommonAVI</p> <p>对Animate控件动画类型索引</p> <p>* gi_Canceled</p> <p>Button_Cancel按钮是否被选择过</p> <p>* gi_AVIType </p> <p>要显示的动画类型,由DLL输出函数做为参数输入</p> <p>* gi_RequestClose </p> <p>请求动画线程关闭标志</p> <p>* gi_WindowActive </p> <p>动画窗口所处的状态</p> <p>* lpsWinTitle </p> <p>动画窗体的标题,由DLL输出函数做为参数输入</p> <p>*/</p> <p>TCommonAVI g_CommonAVI[]={</p> <p>aviNone, aviFindFolder,</p> <p>aviFindFile, aviFindComputer,</p> <p>aviCopyFiles, aviCopyFile,</p> <p>aviRecycleFile, aviEmptyRecycle,</p> <p>aviDeleteFile</p> <p>};</p> <p>int gi_Canceled=0,gi_AVIType=0;</p> <p>int gi_RequestClose=0,gi_WindowActive=0;</p> <p>char lpsWinTitle[256];</p> <p>HWND hWndParent=NULL;</p> <p>/* 定义DLL 输出函数 */</p> <p>extern "C" __declspec(dllexport) </p> <p>int pascal DllEntryPoint(HINSTANCE hinst,</p> <p>unsigned long reason, void*);</p> <p>extern "C" __declspec(dllexport) int </p> <p>pascal ShowStatusWindow(int AVIType,</p> <p>LPSTR WinTitle,long hWnd);</p> <p>extern "C" __declspec(dllexport) int </p> <p>pascal GetStatus(int ai_CloseWin);</p> <p>extern "C" __declspec(dllexport) int </p> <p>pascal CloseStatusWindow();</p> <p>/*定义线程TformThread:*/</p> <p>class TFormThread : public TThread{</p> <p>public:// User declarations</p> <p>__fastcall TFormThread(bool CreateSuspended);</p> <p>void __fastcall Execute(void);</p> <p>};</p> <p>__fastcall TFormThread::</p> <p>TFormThread(bool CreateSuspended):</p> <p>TThread(CreateSuspended){</p> <p>}</p> <p>/* 动画线程执行代码,</p> <p>动画窗体的定时器控件会关闭它,</p> <p>清除窗体存在标志后结束线程的运行</p> <p>*/</p> <p>void __fastcall TFormThread::Execute(void){</p> <p>gi_WindowActive=1;</p> <p>StatusForm=new TStatusForm(NULL);</p> <p>StatusForm- >Caption=lpsWinTitle;</p> <p>StatusForm- >ShowModal();</p> <p>gi_WindowActive=0;</p> <p>delete StatusForm;</p> <p>gi_RequestClose=0;</p> <p>}</p> <p>/* 定义一个线程实例指针 */</p> <p>TFormThread *FormThread;</p> <p>/**********************************************</p> <p>* 输出函数代码实现部分</p> <p>* DllEntryPoint 32位DLL入口</p> <p>* ShowStatusWindow 显示动画窗口,</p> <p>它通过创建一个线程来创建窗口,避免由于窗口</p> <p>的MODAL属性而使控制权不能及时的返还给调用者</p> <p>* GetStatus</p> <p>取得撊∠麛状态,即用户有没有选择撊∠麛按钮</p> <p>* CloseStatusWindow 关闭动画窗口,</p> <p>*/</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -