Sign in to follow this  
Followers 0
Lokdal

msgbox with no default button

5 posts in this topic

hello,

I was wondering if there was a way to code a simple msgbox with "ok" button where the button *is not* selected by default.

the purpose of this is you can't accidentally hit "ok" with the enter key when the box pops up...

I've found 3 options so far :

0 First button is default button 0x0

256 Second button is default button 0x100

512 Third button is default button 0x200

but does the possibility for "no default button" exist ?

Share this post


Link to post
Share on other sites



Lokdal,

Welcome to the AutoIt forum. :)

I am not sure that there is a simple way to do this with the standard API MsgBox. But if you look at the ExtMsgBox UDF in my sig, you can do this (and a lot more) easily with virtually the same syntax as the standard MsgBox. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

hello,

I was wondering if there was a way to code a simple msgbox with "ok" button where the button *is not* selected by default.

the purpose of this is you can't accidentally hit "ok" with the enter key when the box pops up...

I've found 3 options so far :

0 First button is default button 0x0

256 Second button is default button 0x100

512 Third button is default button 0x200

but does the possibility for "no default button" exist ?

Here is a GUI without Buttons. Just enter your data and press enter. The enter key will not work until some data is present. Maybe you can use this.

Regards

REBblank.au3


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

This is my solution for this problem

#include <WinAPI.au3>

Global $hHookMsgBox

 

Local $Ret = _MsgBoxNoDefault(3, "Test", "Is this OK?")
ConsoleWrite($Ret & @CRLF)

 

 

 

Func _MsgBoxNoDefault($flag, $title, $text)
 Local $hProcMsgBox = DllCallbackRegister("_CbtHookProcMsgBox", "int", "int;int;int")
 Local $TIDMsgBox = _WinAPI_GetCurrentThreadId()
 $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox)
 HotKeySet("{Enter}", "_MsgBoxNoDefault_BlockEnter")
 HotKeySet("{Tab}", "_MsgBoxNoDefault_BlockEnter")
 HotKeySet("{LEFT}", "_MsgBoxNoDefault_BlockEnter")
 HotKeySet("{RIGHT}", "_MsgBoxNoDefault_BlockEnter")
 HotKeySet("{UP}", "_MsgBoxNoDefault_BlockEnter")
 HotKeySet("{DOWN}", "_MsgBoxNoDefault_BlockEnter")
 Local $iRet = MsgBox($flag, $title, $text)
 _WinAPI_UnhookWindowsHookEx($hHookMsgBox)
 DllCallbackFree($hProcMsgBox)
 HotKeySet("{Enter}")
 HotKeySet("{TAB}")
 HotKeySet("{LEFT}")
 HotKeySet("{RIGHT}")
 HotKeySet("{UP}")
 HotKeySet("{DOWN}")
 Return $iRet
EndFunc   ;==>_MsgBoxNoDefault


Func _CbtHookProcMsgBox($nCode, $wParam, $lParam)
 Local $Ret = 0, $Style, $hCtrl
 If $nCode < 0 Then
  $Ret = _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
  Return $Ret
 EndIf
 Switch $nCode
  Case 5 ;5=HCBT_ACTIVATE
   $hCtrl = _WinAPI_GetDlgItem($wParam, 65535) ;Text label
   _WinAPI_SetFocus($hCtrl)
 EndSwitch
 Return
EndFunc   ;==>_CbtHookProcMsgBox

Func _MsgBoxNoDefault_BlockEnter()
 ConsoleWrite(@HotKeyPressed & @CRLF)
 If @HotKeyPressed <> "{ENTER}" Then
  HotKeySet("{Enter}")
  HotKeySet("{TAB}")
  HotKeySet("{LEFT}")
  HotKeySet("{RIGHT}")
  HotKeySet("{UP}")
  HotKeySet("{DOWN}")
  Send("{TAB}")
 EndIf
EndFunc   ;==>_MsgBoxNoDefault_BlockEnter

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

Thanks a lot for all your answers :)

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