国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

用C++ Builder開發動畫DLL

2019-09-06 23:33:54
字體:
來源:轉載
供稿:網友

                     
 我 們 在Windows98 環 境 下 執 行 拷 貝 文 件、 查 找 文 件 等 計 算 機 耗 時 較 長 的 操 作 時,Windows 會 顯 示 一 個 小 小 的 動 畫, 指 示 正 在 進 行 的 操 作, 與 死 板 的 靜 止 圖 像 相 比 增 色 不 少。 那 么 我 們 自 己 開 發 軟 件 時, 能 否 也 顯 示 一 個 這 樣 的 動 畫 提 示 呢 ? 筆 者 開 發 了 一 個 能 夠 在CB 下 調 用 的 動 畫DLL, 由 于 采 用 多 線 程 編 程,CB 調 用 的DLL 函 數 能 夠 及 時 將 控 制 權 交 還 給CB, 不 影 響 應 用 系 統 的 運 轉。

一、 代 碼 與 編 譯 選 項
在C + +Builder 中 創 建 一 個 空 白 的DLL 項 目。
創 建 一 個 空 白 的Form, 修 改 它 的 屬 性 為:
BorderStyle=bsDialog
BorderIcons 的 子 屬 性 均 為False
FormStyle=fsStayOnTop
Position= poScreenCenter
Name=StatusForm

在Form 上 添 加 一 個Win32 下 的Animate 控 件Animate1, 修 改 它 的 屬 性 為
Align=alTop

在Form 上 添 加 一 個Standard 下 的Button 控 件Button_Cancel, 再 添 加System 下 的Timer 控 件Timer1, 設 置 定 時Interval 時 間 位250, 較 快 響 應 用 戶 的 取 消 請 求。
----因 為PB 應 用 系 統 與 動 畫 窗 體 代 碼 分 別 屬 于 兩 個 線 程, 不 能 采 用PB 線 程 直 接 關 閉 動 畫 窗 體 線 程 的 窗 口, 否 則 會 引 起 系 統 運 行 不 正 常, 因 此 采 用PB 線 程 設 置 關 閉 標 志, 而 動 畫 線 程 采 用Timer 控 件 定 時 檢 查 標 志, 一 旦 檢 測 到 關 閉 標 志, 就 關 閉 窗 口, 清 除 線 程 標 志, 結 束 動 畫 線 程。

----5. 下 面 給 出 編 碼 及 編 碼 原 理:

----(1)DLL 主 體 代 碼:

/ *DLL 主 體 代 碼
  * 定 義DLL 公 用 變 量
*g_CommonAVI 對Animate 控 件
動 畫 類 型 索 引
 *gi_Canceled Button_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;
    / * 輸 出 函 數 代 碼 實 現 部 分
    * DllEntryPoint 32 位DLL 入 口
    * ShowStatusWindow 顯 示 動 畫 窗 口,
它 通 過 創 建 一 個 線 程 來 創 建 窗 口,
避 免 由 于 窗 口 的MODAL 屬 性 而 使
控 制 權 不 能 及 時 的 返 還 給 調 用 者
    * GetStatus 取 得“ 取 消” 狀 態,
即 用 戶 有 沒 有 選 擇“ 取 消” 按 鈕
    * CloseStatusWindow 關 閉 動 畫 窗 口,
    */
   __declspec(dllexport) int WINAPI DllEntryPoint
(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;
   }


----(2) 窗 體StatusForm 的 代 碼:

   TStatusForm *StatusForm;
   extern int gi_Canceled;
   extern int gi_AVIType;
   extern TCommonAVI g_CommonAVI[];
   __fastcall TStatusForm::TStatusForm
(HWND ParentWindow)
    : TForm(ParentWindow)
   {
    gi_Canceled=0;
   }
   // 取 消 按 鈕 并 不 直 接 關 閉 窗 體,
而 指 示 設 置 取 消 標 志, 供 調 用 者 查 看
   void __fastcall TStatusForm::Button_CancelClick
(TObject *Sender)
   {
   gi_Canceled=1;
   // ModalResult=mrCancel;
   }
     // 激 活 動 畫, 在FORMCREATE 事 件 中
   void __fastcall TStatusForm::FormCreate
(TObject *Sender)
   {
    Animate1 ->CommonAVI=g_CommonAVI[gi_AVI
Type];
    Animate1 ->Active = true;
   }
 
 extern int gi_RequestClose;
 // 定 時 器 事 件 檢 測 到 結 束 標 志 關 閉 窗 體
 void __fastcall TStatusForm::Timer1Timer
(TObject *Sender)
   {
    if (gi_RequestClose){
    ModalResult=mrOk;
    }
   }

v6. 設 置 編 譯 選 項: 打 開Project Options 對 話 框, 清 除Linker 屬 性 頁 中 的 Use Dynamic RTL 標 志, 清 除Packages 屬 性 頁 中 的Build with runtime packages。 這 樣 只 要 單 個DLL 就 可 以 運 行 了, 而 不 必 安 裝 一 些 動 態 連 接 運 行 時 間 庫。

二、 使 用 動 畫DLL
----1. 定 義:

   //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"

----2. 調 用:

   long ll_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()
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 龙海市| 肇源县| 饶平县| 巩留县| 太保市| 黔西| 炉霍县| 宝清县| 宜宾市| 资兴市| 巴青县| 乐清市| 石渠县| 叙永县| 赣州市| 抚松县| 霍山县| 新民市| 濉溪县| 邯郸县| 新蔡县| 兴城市| 澳门| 孟州市| 珠海市| 方城县| 木兰县| 祥云县| 东宁县| 和龙市| 商南县| 时尚| 昌都县| 东方市| 龙岩市| 本溪| 永靖县| 历史| 长春市| 宁国市| 威海市|