?? flashsplashdemo.dpr
字號:
program FlashSplashDemo;
uses
Forms,
Windows,
Controls,
Messages,
Main in 'Main.pas' {frmMain},
Splash in 'Splash.pas' {frmSplash};
{$R *.res}
var
hMutex: THandle;
FoundWnd: THandle;
ModuleName: string;
function EnumWndProc(hwnd: THandle; Param: Cardinal): Bool; stdcall;
var
ClassName, WinModuleName: string;
WinInstance: THandle;
begin
Result := True;
SetLength(ClassName, 100);
GetClassName (hwnd, PChar (ClassName), Length (ClassName));
ClassName := PChar(ClassName);
if ClassName = TfrmMain.ClassName then
begin
{10 獲取目標窗口的模塊名 }
SetLength(WinModuleName, 200);
WinInstance := GetWindowLong(hwnd, GWL_HINSTANCE);
GetModuleFileName (WinInstance, PChar (WinModuleName),
Length(WinModuleName));
WinModuleName := PChar(WinModuleName); // 調整長度
{20 比較模塊名 }
if WinModuleName = ModuleName then
begin
FoundWnd := Hwnd;
Result := False; // 如果已找到,停止繼續列舉
end;
end;
end;
begin
{10 檢測是否互斥已存在 }
HMutex := CreateMutex(nil, False, 'OneCopyMutex');
if WaitForSingleObject(hMutex, 0) <> WAIT_TIMEOUT then
begin
Application.Initialize;
{10.1 啟動Splash屏幕 }
frmSplash := TfrmSplash.Create(nil);
try
with frmSplash do
begin
BeginLoad;
{10.2 裝載主窗體}
Application.CreateForm(TfrmMain, frmMain);
UpdateLoadStatus('正在載入啟動參數', 10);
{10.3 載入數據1的過程 }
//LoadSomeData1;
UpdateLoadStatus('正在載入數據1', 20);
{10.4 裝載其他數據 }
//LoadSomeData2;
UpdateLoadStatus('載入其他數據2', 40);
//LoadSomeData3;
UpdateLoadStatus('開始裝載數據3', 60);
//LoadSomeData4;
UpdateLoadStatus('開始裝載數據4', 70);
//LoadSomeData5;
UpdateLoadStatus('開始裝載數據5', 80);
//LoadSomeData6;
UpdateLoadStatus('開始裝載數據6', 90);
{// 結束 }
{10.5 裝載完畢 }
frmSplash.EndLoad;
end;
finally
frmSplash.Free;
end;
Application.Run;
end
else
begin
{20 獲取當前模塊名 }
SetLength(ModuleName, 200);
GetModuleFileName (HInstance, PChar(ModuleName), Length (ModuleName));
ModuleName := PChar(ModuleName); // 調整長度
{30 列表最初實例的窗口 }
EnumWindows(@EnumWndProc, 0);
if FoundWnd <> 0 then
begin
{40 最后顯示最初實例的窗口 }
if not IsWindowVisible(FoundWnd) then
PostMessage(FoundWnd, wm_App, 0, 0);
SetForegroundWindow(FoundWnd);
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -