|
的DLL函数能够及时将控制权交还给PB,不影响应用系统的运转。一、代码与编译选项
在Form上添加一个Standard下的Button控件Button_Cancel,再添加System下的Timer控件Timer1,设置定时Interval时间位
----因为PB应用系统与动画窗体代码分别属于两个线程,不能采用PB线程直接关闭动画窗体线程的窗口,250,较快响应用户的取消请求。 否则会引起系统运行不正常,因此采用PB线程设置关闭标志,而动画线程采用Timer控件定时检查标志, 一旦检测到关闭标志,就关闭窗口,清除线程标志,结束动画线程。----5.下面给出编码及编码原理:----(1)DLL主体代码: /*DLL主体代码
v6.设置编译选项:打开ProjectOptions对话框,清除Linker属性页中的UseDynamicRTL标志,清除Packages属性页中的Buildwithruntimepackages。这样只要单个DLL就可以运行了,而不必安装一些动态连接运行时间库。二、使用动画DLL----1.定义:
*定义DLL公用变量 *g_CommonAVI对Animate控件 动画类型索引 *gi_CanceledButton_Cancel 按钮是否被选择过 *gi_AVIType要显示的动画类型, 由DLL输出函数做为参数输入 *gi_RequestClose请求动画线程关闭标志 *gi_WindowActive动画窗口所处的状态 *lpsWinTitle动画窗体的标题, 由DLL输出函数做为参数输入 */ TCommonAVI g_CommonAVI[]={ aviNone, aviFindFolder, aviFindFile, aviFindComputer, aviCopyFiles, aviCopyFile, aviRecycleFile, aviEmptyRecycle, aviDeleteFile }; int gi_Canceled=0,gi_AVIType=0; int gi_RequestClose=0,gi_WindowActive=0; char lpsWinTitle[256]; HWND hWndParent=NULL; / * 定 义DLL 输 出 函 数 */ extern “C" __declspec(dllexport) int pascal Dll EntryPoint(HINSTANCE hinst, unsigned long reason, void *); extern “C" __declspec(dllexport) int pascal ShowStatus Window (int AVIType,LPSTR WinTitle,long hWnd); extern “C" __declspec(dllexport) int pascal GetStatus(int ai_CloseWin); extern “C" __declspec(dllexport) int pascal CloseStatusWindow(); / * 定 义 线 程TformThread: */ class TFormThread : public TThread{ public: // User declarations __fastcall TFormThread(bool CreateSuspended); void __fastcall Execute(void); }; __fastcall TFormThread:: TFormThread(bool CreateSuspended): TThread(CreateSuspended){ } /*动画线程执行代码, 动画窗体的定时器控件会关闭它, 清除窗体存在标志后结束线程的运行 */ void __fastcall TFormThread::Execute(void){ gi_WindowActive=1; StatusForm=new TStatusForm(NULL); StatusForm ->Caption=lpsWinTitle; StatusForm ->ShowModal(); gi_WindowActive=0; delete StatusForm; gi_RequestClose=0; } /*定义一个线程实例指针*/ TFormThread*FormThread; /*输出函数代码实现部分 *DllEntryPoint32位DLL入口 *ShowStatusWindow显示动画窗口, 它通过创建一个线程来创建窗口, 避免由于窗口的MODAL属性而使 控制权不能及时的返还给调用者 *GetStatus取得“取消”状态, 即用户有没有选择“取消”按钮 *CloseStatusWindow关闭动画窗口, */
__declspec(dllexport) int WINAPI DllEntryPoint
----(2) 窗 体StatusForm 的 代 码:
(HINSTANCE hinst, unsigned long reason, void *) { return 1; } __declspec(dllexport) int pascal ShowStatusWindow (int AVIType,LPSTR WinTitle,long hWnd){ hWndParent=(HWND)hWnd; memset(lpsWinTitle,0,sizeof(lpsWinTitle)); strncpy(lpsWinTitle,WinTitle,sizeof(lpsWin Title) -1); if (AVIType>0 & & AVIType<=8) gi_AVIType="AVIType;" FormThread="new" TFormThread(true); FormThread ->Priority = tpNormal; FormThread ->Resume(); } __declspec(dllexport) int pascal GetStatus (int ai_CloseWin){ if (gi_Canceled) if (gi_WindowActive){ gi_RequestClose=1; while(gi_RequestClose); } return gi_Canceled; } __declspec(dllexport) int pascal CloseStatusWindow(){ if (gi_WindowActive){ gi_RequestClose=1; while(gi_RequestClose); } return gi_Canceled; }
TStatusForm *StatusForm;
extern int gi_Canceled; extern int gi_AVIType; extern TCommonAVI g_CommonAVI[]; __fastcall TStatusForm::TStatusForm (HWND ParentWindow) : TForm(ParentWindow) { gi_Canceled=0; } //取消按钮并不直接关闭窗体,
//Declare -> Global External Functions
FUNCTION Long ShowStatusWindow (Long AVIType,String WinTitle,long hWnd) &LIBRARY “STATWIN.DLL" ALIAS FOR “Show StatusWindow" FUNCTION Long GetCancelStatus (Long CloseWindow) &LIBRARY “STATWIN.DLL" ALIAS FOR “GetStatus" FUNCTION Long CloseStatusWindow() & LIBRARY “STATWIN.DLL" ALIAS FOR “CloseStatusWindow" longll_EndTime
//显示查找文件夹动画 ShowStatusWindow(2) setpointer(HourGlass!) ll_EndTime = Cpu() + 10 * 1000 DO if GetCancelStatus(0)=1 then exit end if // 做想做的事情 LOOP UNTIL cpu() > ll_EndTime CloseStatusWindow() |