Sign in to follow this  
Followers 0
perfaram

Don't show me your useless message again !

9 posts in this topic

#1 ·  Posted (edited)

Hi !
Here's a short code that creates a MsgBox with a "don't show this message anymore" checkbox.
Also provided, a function to clear this setting.
Moreover, at the end of the script you'll find a GUID generator : you will have to use a different one for each of yours msgboxes, otherwise the "don't show..." will apply everywhere (and none of your boxes will show !)
In the following code, uncomment the eighth line (;_RestoreDefaultSettings()) to clear the settings.
 
$hGui=GUICreate("GUI principale", 300, 300)
GUISetState()

Local $sIdentifier = "{315Ef1E9-1078-4E74-8AB4-171BE0D793E71}"
Local $iDefault = 1

;_RestoreDefaultSettings()
$msgNr=_MessageBoxCheck(33, 'TITRE', 'Bonjour,'&@CRLF&'Qui es-tu, toi qui joue avec le registre ?', $sIdentifier, $iDefault, $hGui)
ConsoleWrite('MsgBox returned : '&$msgNr)

; #FUNCTION# =================================================================================================
; Name...........: _MessageBoxCheck
; Description ...: Creates a MessageBox with a "Do not show me this message again" checkbox.
; Syntax.........: _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault, $hWnd, $iTimeout = 0)
; Parameters....:   $iFlag   - MsgBox flag
;    $sTitle    - MsgBox title
;    $sText - MsgBox text
;    $sIdentifier   - Unique GUID, that identifies the MsgBox in the registry (for the "Do not show..." setting)
;    $iDefault  - Default button
;    $hWnd  - MsgBox's parent
;    $iTimeout  - Timeout value
; Return values .: Success  - The index of the button
; Author ........: Perceval FARAMAZ (perfaram)
; Remarks .......: This function will create an classic MsgBox in case the MessageBoxCheckW interface is not available
; =================================================================================================
Func _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault, $hWnd, $iTimeout = 0)
Local $msgN_Call = DllCall("shlwapi.dll", "int", "SHMessageBoxCheckW", _
"hwnd", $hWnd, "wstr", $sText, "wstr", $sTitle, _
"dword", $iFlag, "int", $iDefault, "wstr", $sIdentifier)

If @error Or $msgN_Call[0] = -1 Then
$iRet=MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd)
Return SetError(1, 0, $iRet) ;fallback
EndIf
Return $msgN_Call[0]
EndFunc


; #FUNCTION# =================================================================================================
; Name...........: _RestoreDefaultSettings
; Description ...: Clear user's setting for "Do not show me this message again" checkbox.
; Author ........: Perceval FARAMAZ (perfaram)
; Remarks .......: You must change the GUID (in the registry path below), to match the one you used to call the MsgBoxCheck
; =================================================================================================
Func _RestoreDefaultSettings()
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", "{315Ef1E9-1078-4E74-8AB4-171BE0D793E71}")
EndFunc

;taken from : http://www.autoitscript.com/forum/topic/134387-version-4-uuid-generator/
Func uuid()
Return StringFormat('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', _
Random(0, 0xffff), Random(0, 0xffff), _
Random(0, 0xffff), _
BitOR(Random(0, 0x0fff), 0x4000), _
BitOR(Random(0, 0x3fff), 0x8000), _
Random(0, 0xffff), Random(0, 0xffff), Random(0, 0xffff) _
)
EndFunc

That's all, folks !

Edited by perfaram
1 person likes this

Never forget to mark a question as resolved, this button has been purposely created :-P 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nice! As a less-invasive rewrite of the above (will not any leave permanent registry entries), where the script itself is subsequently responsible for showing or hiding the msgbox (storing the response in an INI file or whatever) consider:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIDlg.au3>

Local $msgNr = _WinAPI_ShellMessageBoxCheck($MB_OK + $MB_ICONINFORMATION, "SHMessageBoxCheckW Test", "Ne pas perdre sa vie à la gagner")
MsgBox(0, "", "Msgbox = " & $msgNr & @LF & "CheckState = " & ((@extended = $GUI_CHECKED) ? "$GUI_CHECKED" : "$GUI_UNCHECKED"))

Func _WinAPI_ShellMessageBoxCheck($iFlag, $sTitle, $sText, $iTimeout = 0, $hWnd = Null)
    Local Const $ShowMeNot = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain"
    Local Const $sID = "_WinAPI_ShellMessageBoxCheck"

    Local $bCheckbox = $GUI_UNCHECKED
    Local $msgN_Call = _WinAPI_MessageBoxCheck($iFlag, $sTitle, $sText, $sID, 0, $hWnd)

    If @error Or $msgN_Call = -1 Then
        $iRet = MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd)
        Return SetError(1, $bCheckbox, $iRet)
    EndIf

    If RegDelete($ShowMeNot, $sID) Then $bCheckbox = $GUI_CHECKED

    Return SetExtended($bCheckbox, $msgN_Call)
EndFunc

 

It just returns @Extended as $GUI_CHECKED or $GUI_UNCHECKED for quick reference.  Like I said, this could just be stored in an INI/Array so there's no need for persistent registry spam, GUID's, or anything like that (making it easier for a user to "reset" individual message-states in the future).

That being said, if someone did prefer the original method where the system itself suppresses the msgbox call, I suggest using _WinAPI_CreateGUID to generate a true GUID, as randomising can never be considered "unique". Just a thought. :ermm:

Edited by Kilmatead

Share this post


Link to post
Share on other sites

This function is already in the AutoIt UDFs I thought?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

It is, but in the same way as you'll never learn anything about Mont Saint-Michel from Google Street View (except how not to do it), no one ever learned anything from a generically codified dllcall/@error trap, which is all the WinAPIDlg header gives you.  We're here to play, after all.

Share this post


Link to post
Share on other sites

@Kilmatead : THIS is totally true !

Moreover, my function has a fallback in case the MessageBoxCheckW interface is not available  :thumbsup:


Never forget to mark a question as resolved, this button has been purposely created :-P 

Share this post


Link to post
Share on other sites

Alright, just saying.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It is, but in the same way as you'll never learn anything about Mont Saint-Michel from Google Street View (except how not to do it), no one ever learned anything from a generically codified dllcall/@error trap, which is all the WinAPIDlg header gives you.  We're here to play, after all.

It is for you but not for others, so I don't see the point to post an existing function.

 

Edit : And FYI, this is the right way to generate a GUID :

#include <WinAPICom.au3>
 
ConsoleWrite(_WinAPI_CreateGUID() & @Lf)
But I guess you wanted to do it yourself too :)

_

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

@FireFox : Well... no, I didn't know...

BTW, the GUID generator I used isn't mine, it comes from here : '?do=embed' frameborder='0' data-embedContent>>


Never forget to mark a question as resolved, this button has been purposely created :-P 

Share this post


Link to post
Share on other sites

No problem :)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0