Einzelnen Beitrag anzeigen

Benutzerbild von ralfiii
ralfiii

Registriert seit: 30. Mai 2007
489 Beiträge
 
Delphi 2010 Professional
 
#9

Re: "Don't ask again" Messagedialog ?

  Alt 6. Apr 2009, 17:00
Zitat von mjustin:
Standardlösung gibt es in der JVCL - DSA-Dialoge
Cheers,
Uups.
Das kam leider zu spät.

Hier eine Lösung:

Delphi-Quellcode:
// MessageDialog with "Don't ask again" checkbox
// Based on code from [url]http://www.dbrsoftware.de/delphi/nichtdlg.php[/url]
// Discussion: [url]http://www.delphipraxis.net/post1023099.html[/url]
//
// ATT: Could return unexpected values if the list of possible results
// was changed between versions and such an unexpected value was
// stored in registry by an older version of the software
// Take standard window captions from Consts.pas, e.g. SMsgDlgConfirm
function DsaMessageDlg(h: THandle; Text, Caption, DsaDialogId: string;
  uType: Uint): integer;
var HL: THandle;
    Dlg: function(h: THandle; Txt, Title: PChar; dw: DWORD; nll: integer;
                  GStr: PChar): integer; stdcall;
    DSA : boolean;
const SxDsaBaseKey = '\Software\SpoonworX\DontShowAgain';
      MsDsaKey = '\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain';
begin
     with TRegIniFile.Create(SxDsaBaseKey, KEY_READ or Key_Write) do
     begin
          // by holding down CTRL -> unlock!
          if GetAsyncKeyState(VK_CONTROL) and $8000<>0 then
             DeleteKey('', DsaDialogId);

          // Check if a default result is already defined
          result:=ReadInteger('', DsaDialogId, -1);
          Free;
     end;

     // Show Messagedialog
     if result=-1 then
     begin
          // Maintain dialog is shown
          // (clean old preferences - depends only from value in
          with TRegIniFile.Create(MsDsaKey, Key_Write) do
          begin
               DeleteKey('', DsaDialogId);
               Free;
          end;

          // Use standard "hidden" dialog with checkbox
          result := maxint;
          HL := LoadLibrary('shlwapi.dll');
          if HL <> 0 then begin
            @Dlg := GetProcAddress(HL, MAKEINTRESOURCE($B9));
            if Assigned(Dlg) then
              result := Dlg(h, PChar(Text), PChar(Caption),
                uType, 0, PChar(DsaDialogId));
            FreeLibrary(HL);
          end;

          // Determine if "don't show again" checkbox was visible
          with TRegIniFile.Create(MsDsaKey, KEY_READ or Key_Write) do
          begin
               DSA:=ValueExists(DsaDialogId);
               if DSA then
                  DeleteKey('', DsaDialogId);
               Free;
          end;

          // If DSA-checkbox was checked -> store defautl result of dialog
          if DSA and (result<>IDCANCEL) then
             with TRegIniFile.Create(SxDsaBaseKey, Key_Write) do
             begin
                  WriteInteger('', DsaDialogId, result);
                  Free;
             end;
     end;
end;
  Mit Zitat antworten Zitat