{"id":506,"date":"2023-05-19T15:14:59","date_gmt":"2023-05-19T07:14:59","guid":{"rendered":"https:\/\/www.cuishaofeng.com\/?p=506"},"modified":"2024-10-22T14:40:59","modified_gmt":"2024-10-22T06:40:59","slug":"delphi%e8%ae%be%e8%ae%a1%e4%b8%80%e4%b8%aa%e8%bd%af%e4%bb%b6%e5%90%af%e5%8a%a8%e7%94%bb%e9%9d%a2%e7%94%9f%e6%88%90%e5%8a%a0%e8%bd%bd%e7%94%bb%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/www.cuishaofeng.com\/?p=506","title":{"rendered":"Delphi\u8bbe\u8ba1\u4e00\u4e2a\u8f6f\u4ef6\u542f\u52a8\u753b\u9762\u751f\u6210\u52a0\u8f7d\u753b\u9762"},"content":{"rendered":"<div id=\"core-ai-summary-tool\"><\/div>\n<p>Delphi\u8bbe\u8ba1\u4e00\u4e2a\u8f6f\u4ef6\u542f\u52a8\u753b\u9762\uff0c\u5f53\u53cc\u51fbExe\u540e\uff0c\u5148\u663e\u793a\u7684\u4e0d\u662f\u7a0b\u5e8f\u4e3b\u754c\u9762\u800c\u662f\u4e00\u4e2a\u5177\u6709\u7f13\u51b2\u52a0\u8f7d\u6548\u679c\u7684\u542f\u52a8\u753b\u9762\uff0c\u8fd9\u79cd\u542f\u52a8\u7a97\u4f53\u4f1a\u589e\u52a0\u8f6f\u4ef6\u7684\u4f53\u9a8c\u5ea6\uff0c\u5f00\u53d1\u8005\u53ef\u5728\u663e\u793a\u542f\u52a8\u753b\u9762\u7684\u65f6\u5019\uff0c\u8ba9\u4e3b\u7a0b\u5e8f\u8f7d\u5165\u76f8\u5173\u7ec4\u4ef6\uff0c\u6709\u6548\u907f\u514d\u7528\u6237\u7684\u7b49\u5f85\u65f6\u95f4\uff0c\u589e\u52a0\u7f8e\u89c2\u6548\u679c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"142\" src=\"https:\/\/www.cuishaofeng.com\/wp-content\/uploads\/2023\/05\/\u52a0\u8f7d\u753b\u9762.png\" alt=\"\" class=\"wp-image-507\" srcset=\"https:\/\/www.cuishaofeng.com\/wp-content\/uploads\/2023\/05\/\u52a0\u8f7d\u753b\u9762.png 460w, https:\/\/www.cuishaofeng.com\/wp-content\/uploads\/2023\/05\/\u52a0\u8f7d\u753b\u9762-300x93.png 300w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>program SplashDemo;\n\nuses\n  Forms,\n  Windows,\n  Controls,\n  Messages,\n  Main in 'Main.pas',\n  Splash in 'Splash.pas' {frmSplash};\/\/\u8fd9\u4e2a\u7a97\u4f53\u662f\u6700\u5148\u5f39\u51fa\u7684\u7a97\u4f53\n\n{$R *.res}\n\nvar\n  hMutex: THandle;\n  FoundWnd: THandle;\n  ModuleName: string;\n\nfunction EnumWndProc(hwnd: THandle; Param: Cardinal): Bool; stdcall;\n\/\/\u5217\u8868\u5e76\u4e14\u5f97\u5230\u6700\u521d\u7684\u7b2c\u4e00\u4e2a\u7a97\u53e3\u5b9e\u4f8b\u7684\u53e5\u67c4\uff0c\u8d4b\u503c\u7ed9FoundWnd\nvar\n  ClassName, WinModuleName: string;\n  WinInstance: THandle;\nbegin\n  Result := True;\n  SetLength(ClassName, 100);\n  GetClassName (hwnd, PChar (ClassName), Length (ClassName));\n  ClassName := PChar(ClassName);\n  if ClassName = TfrmMain.ClassName then\n  begin\n    {10 \u83b7\u53d6\u76ee\u6807\u7a97\u53e3\u7684\u6a21\u5757\u540d }\n    SetLength(WinModuleName, 200);\n    WinInstance := GetWindowLong(hwnd, GWL_HINSTANCE);\n    GetModuleFileName (WinInstance, PChar (WinModuleName),\n      Length(WinModuleName));\n    WinModuleName := PChar(WinModuleName); \/\/ \u8c03\u6574\u957f\u5ea6\n\n    {20 \u6bd4\u8f83\u6a21\u5757\u540d }\n    if WinModuleName = ModuleName then\n    begin\n      FoundWnd := Hwnd;\n      Result := False; \/\/ \u5982\u679c\u5df2\u627e\u5230\uff0c\u505c\u6b62\u7ee7\u7eed\u5217\u4e3e\n    end;\n  end;\nend;\n\nbegin\n  {10 \u68c0\u6d4b\u662f\u5426\u4e92\u65a5\u5df2\u5b58\u5728 }\n  HMutex := CreateMutex(nil, False, 'OneCopyMutex');\n  if WaitForSingleObject(hMutex, 0) &lt;> WAIT_TIMEOUT then\n  begin\n    Application.Initialize;\n\n    {10.1 \u542f\u52a8Splash\u5c4f\u5e55 }\n    frmSplash := TfrmSplash.Create(nil);\n    try\n      with frmSplash do\n      begin\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">BeginLoad;<\/mark>\n\n        {10.2 \u88c5\u8f7d\u4e3b\u7a97\u4f53}\n        Application.CreateForm(TfrmMain, frmMain); \/\/\u5207\u8bb0\uff1a\u9700\u8981\u5c06\u4e3b\u7a97\u4f53\u7684VISBLE\uff1a=FALSE\uff1b\n        Application.CreateForm(TfrmSplash, frmSplash);\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">UpdateLoadStatus<\/mark>('\u6b63\u5728\u8f7d\u5165\u542f\u52a8\u53c2\u6570', 10);\n\n        {10.3 \u8f7d\u5165\u6570\u636e1\u7684\u8fc7\u7a0b }\n        \/\/LoadSomeData1;\n        UpdateLoadStatus('\u6b63\u5728\u8f7d\u5165\u6570\u636e1', 20);\n\n        {10.4 \u88c5\u8f7d\u5176\u4ed6\u6570\u636e }\n        \/\/LoadSomeData2;\n        UpdateLoadStatus('\u8f7d\u5165\u5176\u4ed6\u6570\u636e2', 40);\n        \/\/LoadSomeData3;\n        UpdateLoadStatus('\u5f00\u59cb\u88c5\u8f7d\u6570\u636e3', 60);\n        \/\/LoadSomeData4;\n        UpdateLoadStatus('\u5f00\u59cb\u88c5\u8f7d\u6570\u636e4', 70);\n        \/\/LoadSomeData5;\n        UpdateLoadStatus('\u5f00\u59cb\u88c5\u8f7d\u6570\u636e5', 80);\n        \/\/LoadSomeData6;\n        UpdateLoadStatus('\u5f00\u59cb\u88c5\u8f7d\u6570\u636e6', 90);\n        {\/\/ \u7ed3\u675f }\n\n        {10.5 \u88c5\u8f7d\u5b8c\u6bd5 }\n        frmSplash.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">EndLoad<\/mark>;\n      end;\n    finally\n      frmSplash.Free;\n    end;\n    Application.Run;\n  end\n  else\n  begin\n    {20 \u83b7\u53d6\u5f53\u524d\u6a21\u5757\u540d }\n    SetLength(ModuleName, 200);\n    GetModuleFileName (HInstance, PChar(ModuleName), Length (ModuleName));\n    ModuleName := PChar(ModuleName); \/\/ \u8c03\u6574\u957f\u5ea6\n\n    {30 \u5217\u8868\u6700\u521d\u5b9e\u4f8b\u7684\u7a97\u53e3 }\n    EnumWindows(@EnumWndProc, 0);\n    if FoundWnd &lt;> 0 then\n    begin\n      {40 \u6700\u540e\u663e\u793a\u6700\u521d\u5b9e\u4f8b\u7684\u7a97\u53e3 }\n      if not IsWindowVisible(FoundWnd) then\n        PostMessage(FoundWnd, wm_App, 0, 0);\n      SetForegroundWindow(FoundWnd);\n    end;\nend;\nend.\n\n\u800c\u5728\u7a97\u4f53\u4e2d\u8981\u58f0\u660e\u4e00\u4e0b\u53d8\u91cf\u5e76\u8d4b\u4e88\u76f8\u5e94\u4ee3\u7801\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> private\r\n    { Private declarations }\r\n    procedure Repaintform;\r\n  public\r\n    { Public declarations }\r\n    procedure beginload;\r\n    procedure endload;\r\n    procedure updateloadstatus(const astatustext: string;aprogress:Integer);\n\n\n\n\u5728\u5355\u5143\u4ee3\u7801\u4e2d\u8f93\u5165\u4ee3\u7801<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>procedure tfrmlogo.beginload;\r\nbegin\r\n  lblStatus.Caption:='\u6b63\u5728\u52a0\u8f7d\u4e2d... ...';\r\n  g1.Progress:=0;\r\n  Repaintform;\r\nend;\r\n\r\nprocedure tfrmlogo.endload;\r\nbegin\r\n  lblStatus.Caption:='\u8f7d\u5165\u7a97\u4f53\u5b8c\u6210';\r\n  g1.Progress:=100;\r\n  Repaintform;\r\nend;\r\n\r\nprocedure tfrmlogo.Repaintform;\r\nbegin\r\n  show;\r\n  Update;\r\n  Sleep(300);\/\/\u65b9\u4fbf\u52a8\u753b\u6f14\u793a\uff0c\u5ef6\u957f\u65f6\u95f4\uff1b\r\nend;\r\n\r\n\r\nprocedure tfrmlogo.updateloadstatus(const astatustext: string;aprogress:Integer);\r\nbegin\r\n  lblStatus.Caption:=AStatustext;\r\n  g1.Progress:=aprogress;\r\n  Repaintform;\r\nend;\nprocedure TfrmLogo.FormCreate(Sender: TObject);\r\nbegin\n lblStatus.Caption:='';\r\n g1.MinValue:=0;\r\n g1.MaxValue:=100;\r\nend;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Delphi\u8bbe\u8ba1\u4e00\u4e2a\u8f6f\u4ef6\u542f\u52a8\u753b\u9762\uff0c\u5f53\u53cc\u51fbExe\u540e\uff0c\u5148\u663e\u793a\u7684\u4e0d\u662f\u7a0b\u5e8f\u4e3b\u754c\u9762\u800c\u662f\u4e00\u4e2a\u5177\u6709\u7f13\u51b2\u52a0\u8f7d\u6548\u679c\u7684\u542f\u52a8\u753b\u9762\uff0c\u8fd9\u79cd\u542f\u52a8\u7a97\u4f53\u4f1a\u589e\u52a0\u8f6f\u4ef6\u7684\u4f53\u9a8c\u5ea6\uff0c\u5f00\u53d1\u8005\u53ef\u5728\u663e\u793a\u542f\u52a8\u753b\u9762\u7684\u65f6\u5019\uff0c\u8ba9\u4e3b\u7a0b\u5e8f\u8f7d\u5165\u76f8\u5173\u7ec4\u4ef6\uff0c\u6709\u6548\u907f\u514d\u7528\u6237\u7684\u7b49\u5f85\u65f6\u95f4\uff0c\u589e\u52a0\u7f8e\u89c2\u6548\u679c\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[73],"topic":[],"_links":{"self":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/506"}],"collection":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=506"}],"version-history":[{"count":1,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=506"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}