AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

"Don't ask again" Messagedialog ?

Ein Thema von ralfiii · begonnen am 6. Apr 2009 · letzter Beitrag vom 14. Jul 2010
 
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, 16: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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:15 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz