// 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;