Jelajahi Sumber

Opening Default Apps Settings page directly to avoid flashing Control Panel window

Source commit: a9ea22139bc32b2b7e346a26a3b1e48ee5671952
Martin Prikryl 2 hari lalu
induk
melakukan
3b526482f6
3 mengubah file dengan 15 tambahan dan 23 penghapusan
  1. 1 15
      source/windows/Setup.cpp
  2. 13 8
      source/windows/Tools.cpp
  3. 1 0
      source/windows/Tools.h

+ 1 - 15
source/windows/Setup.cpp

@@ -713,21 +713,7 @@ void __fastcall LaunchAdvancedAssociationUI()
 
   if (IsWin10())
   {
-    // WORKAROUND: On Windows 10, the IApplicationAssociationRegistrationUI::LaunchAdvancedAssociationUI does not work.
-    // https://stackoverflow.com/q/32178986/850848
-    // This approach (IOpenControlPanel::Open) works on Windows 7 too, but not on Windows Vista.
-    IOpenControlPanel * OpenControlPanel;
-
-    HRESULT Result =
-      CoCreateInstance(CLSID_OpenControlPanel,
-        NULL, CLSCTX_INPROC, __uuidof(IOpenControlPanel), (void**)&OpenControlPanel);
-    if (SUCCEEDED(Result))
-    {
-      // This does not work anymore since April 2018 Update, it now has the same effect as mere "pageDefaultProgram".
-      UnicodeString Page = FORMAT(L"pageDefaultProgram\\pageAdvancedSettings?pszAppName=%s", (AppNameString()));
-      OpenControlPanel->Open(L"Microsoft.DefaultPrograms", Page.c_str(), NULL);
-      OpenControlPanel->Release();
-    }
+    ShellOpen(L"ms-settings:defaultapps");
   }
   else
   {

+ 13 - 8
source/windows/Tools.cpp

@@ -766,6 +766,14 @@ UnicodeString __fastcall SecureUrl(const UnicodeString & Url)
   return Result;
 }
 //---------------------------------------------------------------------------
+void ShellOpen(const UnicodeString & Param)
+{
+  if (!CopyCommandToClipboard(Param))
+  {
+    ShellExecute(Application->Handle, L"open", Param.c_str(), NULL, NULL, SW_SHOWNORMAL);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall OpenBrowser(UnicodeString URL)
 {
   if (IsWinSCPUrl(URL))
@@ -773,16 +781,13 @@ void __fastcall OpenBrowser(UnicodeString URL)
     DebugAssert(!IsHttpUrl(URL));
     URL = CampaignUrl(URL);
   }
-  if (!CopyCommandToClipboard(URL))
+  // Rather arbitrary limit. Opening a URL over approx. 5 KB fails in Chrome, Firefox and Edge.
+  const int URLLimit = 4*1024;
+  if (URL.Length() > URLLimit)
   {
-    // Rather arbitrary limit. Opening a URL over approx. 5 KB fails in Chrome, Firefox and Edge.
-    const int URLLimit = 4*1024;
-    if (URL.Length() > URLLimit)
-    {
-      URL.SetLength(URLLimit);
-    }
-    ShellExecute(Application->Handle, L"open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL);
+    URL.SetLength(URLLimit);
   }
+  ShellOpen(URL);
 }
 //---------------------------------------------------------------------------
 void __fastcall OpenFolderInExplorer(const UnicodeString & Path)

+ 1 - 0
source/windows/Tools.h

@@ -48,6 +48,7 @@ void __fastcall ValidateMaskEdit(TEdit * Edit);
 void __fastcall ValidateMaskEdit(TMemo * Edit, bool Directory);
 bool __fastcall IsWinSCPUrl(const UnicodeString & Url);
 UnicodeString __fastcall SecureUrl(const UnicodeString & Url);
+void ShellOpen(const UnicodeString & Param);
 void __fastcall OpenBrowser(UnicodeString URL);
 void __fastcall OpenFileInExplorer(const UnicodeString & Path);
 void __fastcall OpenFolderInExplorer(const UnicodeString & Path);