Jump to content

msgbox with no default button


Lokdal
 Share

Recommended Posts

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 ?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...