0

In Windows 11, when I try to double-click a .pptx file, I will see the following "Open with" dialog:

enter image description here

This is a little different from the standard "Open with" dialog, as it has included PowerPoint as the candidate.

I try to simulate such an action via ShellExecute in Delphi, as below:

  Value := ShellExecute(Handle, 'openas', PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL);

  if (Value <= 32) then
    MessageDlg(Format('openas Error code %d', [Value]), mtError, [mbOK], 0);

  Value := ShellExecute(Handle, nil, PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL);

  if (Value <= 32) then
    MessageDlg(Format('nil Error code %d', [Value]), mtError, [mbOK], 0);

  Value := ShellExecute(Handle, 'open', PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL);

  if (Value <= 32) then
    MessageDlg(Format('open Error code %d', [Value]), mtError, [mbOK], 0);

I try 'openas', 'open', nil as the verb, but all of them fail and return error code 31.

alancc
  • 487
  • 2
  • 24
  • 68
  • 1
    Questions like your previous [How to open file and show the "Open with" dialog?](https://stackoverflow.com/questions/73967124/how-to-open-file-and-show-the-open-with-dialog) are closed as duplicate for a reason. Also you nowhere even attempted to incorporate `.pptx` or _PowerPoint_. Try [`ShellExecuteEx` with its `SHELLEXECUTEINFO.lpClass` member as per the manual](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shellexecuteinfoa). – AmigoJack Oct 07 '22 at 10:27
  • 1
    The most important thing to learn here is that you should never ever call `ShellExecute` and instead you call `ShellExecuteEx`. If you can take that away from this thread then progress will have been made. – David Heffernan Oct 07 '22 at 11:28
  • @DavidHeffernan, I just try ShellExecuteEx and with the complete same sets of parameters, lpVerb and lpClass set to nil. Then it works! Why? I think ShellExecute is just a simple version of ShellExecuteEx, but it seems not the case, ShellExecute seems to invoke different library which contains bug? – alancc Oct 08 '22 at 21:49
  • No. ShellExecute doesn't have a bug. It's just there for backwards compatibility. But it has been superceded for at least 25 years now. – David Heffernan Oct 09 '22 at 05:24
  • @DavidHeffernan, Thank you for letting me know. I use ShellExecute just because it looks simpler. :) – alancc Oct 09 '22 at 07:38
  • The documentation tells you not to use it – David Heffernan Oct 09 '22 at 08:14

0 Answers0