Suppress Windows dialog in ShellLink Resolve with missing target in ShellLink? - shell

In Delphi XE7, I want to use the following code to replace the link target of a shell link file (.lnk):
uses
JclShell;
...
procedure ShellLinkReplaceLinkTarget(const AShellLinkFile, ANewTarget: string);
var
ThisShellLink: JclShell.TShellLink;
begin
if (JclShell.ShellLinkResolve(AShellLinkFile, ThisShellLink) = S_OK) then // Windows error dialog
begin
ThisShellLink.Target := ANewTarget;
JclShell.ShellLinkCreate(ThisShellLink, AShellLinkFile);
end
else CodeSite.Send('ShellLinkResolve Failed!');
end;
However, when the link target does not exist anymore, then at ShellLinkResolve the well known Link problem Windows error dialog comes up telling that the link target has been deleted etc. Here is the dialog in German:
So how can I suppress this dialog? Because the program needs to replace the missing link target with another one, not Windows.
Windows 7 x64 SP1
EDIT:
BTW: When I click on the Restore button (the leftmost button in the above dialog screenshot), then the missing target is restored from the waste basket - but the dialog is NOT being closed after the successful restore or at least the Restore button disabled after the restore. An example of bad UI design by Microsoft.

Try the following code:
if (JclShell.ShellLinkResolve(AShellLinkFile, ThisShellLink,
SLR_ANY_MATCH or SLR_NO_UI) = S_OK) then

Related

Why I can't display some site with TWebBrowser

I use Delphi Rio (Windows Desktop App) and need to display in a TWebBrowser some webpages.
I ran into a problem with this WooCommerce site, https://merletdance.com/eshop.
When I ask for this one, I can't pass the cookies dialog. I understand it's in relation with JScript and/or JQuery, but is there a way to bypass or better (some parameters of TwebBrowser) ?
[Edit] Works with Delphi 11 (Alexandria) using Edge
Found a solution, even if for my users with heterogeneous park it's not a cure-all: Embarcadero's documentation on TWebBrowser hints to edit the registry:
Supporting JavaScript Integration on Windows Platform
On Windows target platforms (WIN32 and WIN64), TWebBrowser may incorrectly display some Web pages if a Web site uses JavaScript dialog boxes, panels, and other elements for various purposes.
To work around this issue, your application should display Web pages in the IE11 edge mode using the FEATURE_BROWSER_EMULATION feature of Internet Explorer.
Open the Registry Editor.
Open the following key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
On the Edit menu, point to New, and then click DWORD (32-bit) Value.
Set the name of this new entry to your executable file name, such as MyApps.exe.
Select the newly created entry, and on the Edit menu, click Modify.
In the Edit dialog box that opens, do the following:
In the Value data text box, enter 11011
Under Base, select Decimal
Click OK to save your changes
You can also cause your application to make the above described changes when the application starts. For example, in your project, the FormCreate event handler can call the following TForm1.SetPermissions method:
procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF MSWINDOWS}
SetPermissions;
{$ENDIF}
end;
{$IFDEF MSWINDOWS}
procedure TForm1.SetPermissions;
const
cHomePath = 'SOFTWARE';
cFeatureBrowserEmulation =
'Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\';
cIE11 = 11001;
var
Reg: TRegIniFile;
sKey: string;
begin
sKey := ExtractFileName(ParamStr(0));
Reg := TRegIniFile.Create(cHomePath);
try
if Reg.OpenKey(cFeatureBrowserEmulation, True) and
not(TRegistry(Reg).KeyExists(sKey) and (TRegistry(Reg).ReadInteger(sKey)
= cIE11)) then
TRegistry(Reg).WriteInteger(sKey, cIE11);
finally
Reg.Free;
end;
end;
{$ENDIF}
Note: You should make these appropriate changes to the registry before starting the application. After you start your application for the first time, close it, and then start again.

CEF4Delphi - My program doesn't get visible again using Alt-Tab when browser is active

I have a Windows program, let's call it 'MyApp', written in Delphi, with embedded chromium on a certain tab. I use CEF4Delphi and I have a problem.
When I use 'MyApp' and the embedded browser is active, I can activate another program (using Alt-Tab or click the icon in the task bar). That's no problem. But when I want to activate 'MyApp' again, it won't get visible or brought to the front. I can not see 'MyApp'. The other program remains visible, however the icon in the taskbar is highlighted. To use 'MyApp', I will have to minimize the other program, so I will see it again.
This problem only occurs when the embedded browser in 'MyApp' is activated.
The chromium is running as a different process and created like recommended in the documentation: https://www.briskbard.com/index.php?lang=en&pageid=cef#usage
The dpr looks like this:
program MyApp;
{$R *.dres}
// uses files
{$SetPEFlags IMAGE_FILE_RELOCS_STRIPPED or IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP or IMAGE_FILE_NET_RUN_FROM_SWAP}
{$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE}
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
NullStrictConvert := System.false;
GlobalCEFApp := TCefApplication.Create;
if GlobalCEFApp.StartMainProcess then
begin
PauseMadExcept;
Application.Initialize;
// ... create forms ...
Application.Run;
It seems to be a Windows 10 bug!
Try this (which helped me with another software, Magix Video Edit Pro):
Disable the "Snap windows" under System > Settings > Multitasking and now the ALT + TAB works again. The software gets focused.
Update: The bug reappeared but still, it worked some time after disabling "Snap windwos". Anyone with some more hints, please comment below.

Crash when calling getOpenFileName from QItemDelegate's custom editor

Prerequisites:
I have a custom QItemDelegate which creates custom editor for treeview items.
The editor consists of a QLineEdit and QToolButton. The button is used to open the file dialog for selecting the file and placing it's path into line edit.
I use a call to QFileDialog::getOpenFileName to open the file dialog. The dialog is native Windows file dialog (this is important).
When the editor is created the first time, everything works ok no matter how often I press that button. But after the editor is closed and reopened again the first press on the button results in a crash. The reason of the crash is that my custom editor eventually gets deleted.
Here is some code:
void CCustomEditor::on_RunSetupBtn_clicked()
{
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
if (qFilename.isEmpty())
return;
SetCommandLine(QDir::toNativeSeparators(qFilename), m_qParameters);
}
I have made some digging and found out that calling WinAPI function GetOpenFileName results in the very same way: my editor gets deleted (although crash doesn't happen). It seems that Qt calls it also internally.
I have tracked down the reason of why my editor gets deleted and found out that when getOpenFileName is called, active window changes and focus changes with it.
In the first case the focus is moved from TreeView item, but in the second case it is moved from the editor itself!
This results in the deletion of editor because of 'focus out' event.
It is important to say that this situation doesn't happen if 'DontUseNativeDialog' flag is set when file dialog is created. Therefore this should be a bug in Qt's window management between native windows and Qt widgets.
As a workaround of this bug I suggest the following solution: before making a call to getOpenFileName set the focus to the button itself.
m_pUI->RunSetupBtn->setFocus();
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
The other workaround is to use 'DontUseNativeDialog' flag, but the resulting file dialog doesn't look native, in fact it is quite ugly.
If someone has a better solution, feel free to share.
I have a similar problem with getOpenFileName and getSaveFileName. My solution is, after getOpenFileName, getSaveFileName or at the end of the function set the windows as active with activateWindow().

Replace or customize modal uninstallation windows in Inno Setup

Is it possible to replace next uninstalling modal windows with custom modal windows or pages in Inno Setup:
Both messages are shown always, except for silent (or very silent) uninstallations.
What you can do:
Change message texts:
[Messages]
ConfirmUninstall=Are you sure you want to completely remove %1 and all of its components?
UninstalledAll=%1 was successfully removed from your computer.
UninstalledMost=%1 uninstall complete.%n%nSome elements could not be removed. These can be removed manually.
UninstalledAndNeedsRestart=To complete the uninstallation of %1, your computer must be restarted.%n%nWould you like to restart now?
Get rid of the messages by making the uninstaller run silently always by adding the /SILENT command-line switch to the UninstallString registry key. See also Can I disable uninstall confirmation message?
Though this is bit of a hack, and you better do it only, if you have a good reason.
And optionally implementing your custom messages/dialogs by implementing InitializeUninstall and CurUninstallStepChanged(usDone), like:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
DoneForm: TSetupForm;
begin
if CurUninstallStep = usDone then
begin
DoneForm := CreateCustomForm;
{ populate the form here... }
DoneForm.ShowModal;
end;
end;
Another way to get rid of the message, when the uninstallation completes, is to handle usPostUninstall event and display your custom dialog box there. And forcefully abort the installer afterwards. But then the automatic restart of Windows, in case it's needed to complete the uninstallation, won't work.
You can also implement some DLL that watches for new message boxes and updates/submits them as they appear.
If you want to create custom pages in Uninstaller then No.
Uninstaller does NOT support creating custom pages.

Delphi Firemonkey does not display fonts correctly

I'm building cross-platform desktop app with additional font (Abilene). On startup I check is the font installed and if it is not, I install it and use it. For Mac everything seems to be fine, but Windows version (and the IDE!!) does not display the font correctly. Here is the font installation procedure:
procedure InstallFont;
const
REG_NT = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts';
var
Reg: TRegistry;
res: Boolean;
installName,FileName: UnicodeString;
begin
Reg := TRegistry.Create(KEY_ALL_ACCESS);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
res := Reg.OpenKey(REG_NT, False);
if not Res then Exit;
installName := 'Abilene Regular (TrueType)';
FileName:=ExtractFilePath(ParamCount(0)+'\Abilene.ttf';
Reg.WriteString(installName, FileName);
Reg.CloseKey;
finally
Reg.Free;
end;
AddFontResourceW(PWideChar(FileName));
SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0);
end;
After installing the font it is displayed as shortcut in the Control panel, but all other programs can use it. Even Delphi can, but with VCL, not FMX applications (see attached pictures). I've attached pictures from the IDE. In the runtime it's the same.
Is there anything that must be done additionally for the font installation especially for FMX apps? Or this is just a bug which must be reported to Embarcaderro QC?
Edit: Adding some details: If I install the font by downloading it, clicking with the right mouse button and choose 'Install' then everything is OK. If I install it by my proc then the font is visible and usable for the whole world except the Delphi FMX. Delphi VCL can use it also. To test this I install ed the font with my proc in my %APPDATA% folder. Word, Excel, Delphi VCL can use it. Delphi FMX cannot.
Edit2: Added SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0). No change.
Edit3: In the Font dialog the font is displayed correctly (image 3)
Obviously this is some sort of bug, because I've found a workaround: if I first copy the font to %windir%\Fonts folder then everything is OK. Even if I made a subfolder of the \windows\fonts folder and copy the font in it everything is fine also.
Why Firemonkey does not want to display fonts outside that folder I have no idea. And, as I said, this is for Windows only. Mac OS is OK (I use ~/Library/Fonts).

Resources