Sign in to follow this  
Followers 0
James

SHMessageBoxCheck

16 posts in this topic

#1 ·  Posted (edited)

I found this function today and thought that a lot of people would probably find it useful! Basically with this function you'll be able to create a message

box looking like this:

Posted Image

The return values are the same as any other message box:

Button PressedReturn Value OK 1CANCEL 2ABORT 3RETRY 4IGNORE 5YES 6NO 7TRY AGAIN **10CONTINUE **11

If the user presses the "In the future, do not show me this dialog box" checkbox, that message will never appear again - not even if you call it. It's all based on the RegVal:

A pointer to a null-terminated string that contains a unique stringvalue to associate with this message. To avoid collisions with valuesused by Microsoft, this string should include a GUID. This string mustnot exceed REGSTR_MAX_VALUE_LENGTH characters in length, including theterminating null character.

So the code:

$hMsg = MsgBoxC(4, "Warning", "AutoIt just did something useful!", "{d9108ba3-9a61-4398-bfbc-b02102c77e8c}")
MsgBox(0, "Return Value:", "$hMsg returned: " & $hMsg)

Func MsgBoxC($dwType, $lpszTitle, $lpszText, $lpszId)
    $Ret = DllCall("shlwapi.dll", "long", "SHMessageBoxCheck", "long", ControlGetHandle("Program Manager", "", "SysListView32"), "string", $lpszText, _
    "string", $lpszTitle, "long", $dwType, "long", 0, "string", $lpszId)
    Return $Ret[0]
EndFunc

Have fun!

Edited by JamesBrooks

Share this post


Link to post
Share on other sites



Not supported in Win XP? I get this error:

Subscript used with non-Array variable.:

Return $Ret[0]
Return $Ret^ ERROR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Nice one man, i will defanately use this kind of msgbox. But one thing, are the button and flag codes the same like the normal msgbox codes ?


Share this post


Link to post
Share on other sites

Not supported in Win XP? I get this error:

Subscript used with non-Array variable.:

Return $Ret[0]
Return $Ret^ ERROR

MSDN says the minimum operating systems are; Windows 2000, Windows 2000 Server, Windows Server 2003, Windows XP. Remove the array [0] then, I never noticed anything different about using it or not.

Nice one man, i will defanately use this kind of msgbox. But one thing, are the button and flag codes the same like the normal msgbox codes ?

Thanks shadowhacker! Yes flags and return codes are just the same.

Share this post


Link to post
Share on other sites

Not supported in Win XP? I get this error:

Subscript used with non-Array variable.:

Return $Ret[0]
Return $Ret^ ERROR

Read this.

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Remove the array [0] then, I never noticed anything different about using it or not.

But the function still not called :D

Thanks, that solves the issue. Althought it's not supporting all the flags that msgbox does (262144 for example, it's «MsgBox has top-most attribute set»).

P.S

But anyway, i personally prefer to use custom MsgBox (GUI), where i can retrieve value base on selected (or not) checkbox, registry usage is not so convinient for those purposes.


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

But anyway, i personally prefer to use custom MsgBox (GUI), where i can retrieve value base on selected (or not) checkbox, registry usage is not so convinient for those purposes.

I too, but anyway it`s a good addition.

Share this post


Link to post
Share on other sites

I too, but anyway it`s a good addition.

Yes yes, i agree, it's very nice adition for simple tasks.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Thanks it works great!

Question? Can you get it back by reg edit. I have never used it before and I am very nervous about doing anything to it.

Yes I did check the box and it does not work any more.

REB


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

Here is how we can use it better:

$sIdentifier = "{D9108BA3-9A61-4398-BFBC-B02102C77E8C}"

;Just to allow the example to run every time
If _MessageBoxCheck_GetIDAnswer($sIdentifier) = "no" Then _MessageBoxCheck_RemoveIDAnswer($sIdentifier)

$iRet = _MessageBoxCheck(36, "Title", "Text", $sIdentifier)

ConsoleWrite("@error: " & @error & @CRLF & "@extended: " & @extended & @CRLF & "$iRet: " & $iRet & @CRLF)

Func _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault=0, $hWnd=0, $iTimeout = 0)
    Local $a_iCall = DllCall("shlwapi.dll", "int", 191, _; "SHMessageBoxCheckW" exported by ordinal prior Vista
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", $sTitle, _
            "dword", $iFlag, _
            "int", $iDefault, _
            "wstr", $sIdentifier)
    
    If @error Or $a_iCall[0] = -1 Then Return SetError(1, 0, MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd))
    Return SetError(0, Number(_MessageBoxCheck_GetIDAnswer($sIdentifier) = "no"), $a_iCall[0])
EndFunc

Func _MessageBoxCheck_GetIDAnswer($sIdentifier)
    Return RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
EndFunc

Func _MessageBoxCheck_RemoveIDAnswer($sIdentifier)
    Return RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
EndFunc

So now the @extended will be set to 1 if the checkbox is checked.

Or, another version, to return additional flag of 32 in return value for checkbox state:

$sIdentifier = "{D9108BA3-9A61-4398-BFBC-B02102C77E8C}"

$iShowMsg = 1

$iRet = _MessageBoxCheck(36, "Test 1", "Text", $sIdentifier)
ConsoleWrite("@error: " & @error & @CRLF & "$iRet: " & $iRet & @CRLF)

$iShowMsg = (Not BitAND($iRet, 32))

;If the checkbox checked, this dialog will not be shown
If $iShowMsg Then _MessageBoxCheck(36, "Test 2", "Text", $sIdentifier)

Func _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault=0, $hWnd=0, $iTimeout = 0)
    Local $a_iCall = DllCall("shlwapi.dll", "int", 191, _; "SHMessageBoxCheckW" exported by ordinal prior Vista
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", $sTitle, _
            "dword", $iFlag, _
            "int", $iDefault, _
            "wstr", $sIdentifier)
    
    If @error Or $a_iCall[0] = -1 Then Return SetError(1, 0, MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd))
    
    If RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier) = "no" Then
        $a_iCall[0] = BitOR($a_iCall[0], 32) ;32 is the checked checkbox indicator
        
        ;Remove the registry entries
        RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
    EndIf
    
    Return SetError(0, 0, $a_iCall[0])
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Here is how we can use it better:

$sIdentifier = "{D9108BA3-9A61-4398-BFBC-B02102C77E8C}"

;Just to allow the example to run every time
If _MessageBoxCheck_GetIDAnswer($sIdentifier) = "no" Then _MessageBoxCheck_RemoveIDAnswer($sIdentifier)

$iRet = _MessageBoxCheck(36, "Title", "Text", $sIdentifier)

ConsoleWrite("@error: " & @error & @CRLF & "@extended: " & @extended & @CRLF & "$iRet: " & $iRet & @CRLF)

Func _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault=0, $hWnd=0, $iTimeout = 0)
    Local $a_iCall = DllCall("shlwapi.dll", "int", 191, _; "SHMessageBoxCheckW" exported by ordinal prior Vista
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", $sTitle, _
            "dword", $iFlag, _
            "int", $iDefault, _
            "wstr", $sIdentifier)
    
    If @error Or $a_iCall[0] = -1 Then Return SetError(1, 0, MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd))
    Return SetError(0, Number(_MessageBoxCheck_GetIDAnswer($sIdentifier) = "no"), $a_iCall[0])
EndFunc

Func _MessageBoxCheck_GetIDAnswer($sIdentifier)
    Return RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
EndFunc

Func _MessageBoxCheck_RemoveIDAnswer($sIdentifier)
    Return RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
EndFunc

So now the @extended will be set to 1 if the checkbox is checked.

Or, another version, to return additional flag of 32 in return value for checkbox state:

$sIdentifier = "{D9108BA3-9A61-4398-BFBC-B02102C77E8C}"

$iShowMsg = 1

$iRet = _MessageBoxCheck(36, "Test 1", "Text", $sIdentifier)
ConsoleWrite("@error: " & @error & @CRLF & "$iRet: " & $iRet & @CRLF)

$iShowMsg = (Not BitAND($iRet, 32))

;If the checkbox checked, this dialog will not be shown
If $iShowMsg Then _MessageBoxCheck(36, "Test 2", "Text", $sIdentifier)

Func _MessageBoxCheck($iFlag, $sTitle, $sText, $sIdentifier, $iDefault=0, $hWnd=0, $iTimeout = 0)
    Local $a_iCall = DllCall("shlwapi.dll", "int", 191, _; "SHMessageBoxCheckW" exported by ordinal prior Vista
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", $sTitle, _
            "dword", $iFlag, _
            "int", $iDefault, _
            "wstr", $sIdentifier)
    
    If @error Or $a_iCall[0] = -1 Then Return SetError(1, 0, MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hWnd))
    
    If RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier) = "no" Then
        $a_iCall[0] = BitOR($a_iCall[0], 32) ;32 is the checked checkbox indicator
        
        ;Remove the registry entries
        RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", $sIdentifier)
    EndIf
    
    Return SetError(0, 0, $a_iCall[0])
EndFunc

Thanks MRCreatoR

The examples work and will be a source of study for me.

REB


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

This will be really useful to someone out there some day..... just not me or right now. Good job


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

This will be really useful to someone out there some day..... just not me or right now. Good job

 

It definitely is! Thanks a lot, MrCreatoR. :thumbsup:

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