In the past, I use the following statement to open a file:
if ShellExecute(Handle, 'open', PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL) <= 32 then
MessageDlg('Error', mtError, [mbOK], 0);
However, in Windows 11, when I try to open a .pptx file, the statement fails and shows the error. ShellExecute will return 31.
I try to double-click to open the .pptx file directly, and I see the following dialog:
So, I hope my code works just like double-click the file in Windows, i.e. show the above "choose app" dialog instead of showing error.
I follow the instructions in How can you open a file with the program associated with its file extension? and change my code to:
if ShellExecute(Handle, nil, PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL) <= 32 then
MessageDlg('Error', mtError, [mbOK], 0);
But still not work. ShellExecute will return 31.
I try to use 'openas' instead as mentioned in How to open a default dialog for window if ShellExecute fails due to no file association in C++?, as follows:
ShellExecute(Handle, 'openas', PChar(txtFile.Text), nil, nil, SW_SHOWNORMAL);
But still fail and ShellExecute still returns 31.