2

At start, if an update is available, runtime packages are downloaded and replaced. If one of them is in use, a dialog window that allows users to retry or cancel is shown (Using MessageDlg). When the dialog is showing, no form has been created yet and the application icon isn't visible in the taskbar. I could create a custom dialog form and override the CreateParams procedure (As here Force application to show TaskBar Icon during OnCreate procedure), but I'm wondering if I can do the same thing using a standard dialog message.

Additional info: In cases which "(Win32MajorVersion >= 6) and UseLatestCommonDialogs and ThemeServices.ThemesEnabled" is False, MessageDlg creates the dialog as a TMessageForm (Inherited from TForm). If the condition results True, the following function's executed:

var
  _TaskDialogIndirect: function(const pTaskConfig: TTaskDialogConfig;
    pnButton: PInteger; pnRadioButton: PInteger;
    pfVerificationFlagChecked: PBOOL): HRESULT; stdcall;

  _TaskDialog: function(hwndParent: HWND; hInstance: HINST;
    pszWindowTitle: LPCWSTR; pszMainInstruction: LPCWSTR; pszContent: LPCWSTR;
    dwCommonButtons: DWORD; pszIcon: LPCWSTR; pnButton: PInteger): HRESULT; stdcall;

function TaskDialogIndirect(const pTaskConfig: TTaskDialogConfig;
  pnButton: PInteger; pnRadioButton: PInteger; pfVerificationFlagChecked: PBOOL): HRESULT;
begin
  if Assigned(_TaskDialogIndirect) then
    Result := _TaskDialogIndirect(pTaskConfig, pnButton, pnRadioButton,
      pfVerificationFlagChecked)
  else
  begin
    InitComCtl;
    Result := E_NOTIMPL;
    if ComCtl32DLL <> 0 then
    begin
      @_TaskDialogIndirect := GetProcAddress(ComCtl32DLL, 'TaskDialogIndirect');
      if Assigned(_TaskDialogIndirect) then
        Result := _TaskDialogIndirect(pTaskConfig, pnButton, pnRadioButton,
          pfVerificationFlagChecked)
    end;
  end;
end;
Community
  • 1
  • 1
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • 1
    How is `MessageDlg` implemented in your Delphi? Is it a Delphi form, or is it a call to a Win32 API? – David Heffernan Dec 11 '15 at 09:04
  • 1
    In Delphi2007, Dialogs.MessageDlg calls Dialogs.CreateMessageDialog in which the window is created as a TMessageForm (Inherited from TForm) – Fabrizio Dec 11 '15 at 11:06
  • 1
    You could use CreateMessageDialog to get a form instance and add it to the taskbar with [`ITaskbarList::AddTab`](https://msdn.microsoft.com/en-us/library/windows/desktop/bb774646.aspx) but you'd need to be sure that you removed it again. VCL window re-creation is the danger. If I were you I'd just make a form and override its `CreateParams` to make it unowned, or add `WS_EX_APPWINDOW`. I suppose you could add `WS_EX_APPWINDOW` to the form created by `CreateMessageDialog` but you'd have to be wary about VCL window re-creation again. – David Heffernan Dec 11 '15 at 11:21
  • 1
    I'm sorry, I have omitted that CreateMessageDialog is executed just if "(Win32MajorVersion >= 6) and UseLatestCommonDialogs and ThemeServices.ThemesEnabled" is False. Otherwise, it executes CommCtrl.TaskDialogIndirect (I've added the function in the first post). – Fabrizio Dec 11 '15 at 11:28
  • 1
    @DavidHeffernan: I agree with your previous comment, making a form seems to be quite easier and less dangerous. I think I'll do so. Many thanks for explanation. – Fabrizio Dec 11 '15 at 11:33

0 Answers0