Jump to content

MsgBox window position not in the middle of the screen


Recommended Posts

  • Moderators

antai,

Take a look at my ExtMsgBox UDF (link is in my sig - it allows you to specify the location of the dialog, as well as its colour, font, button text, etc, etc, etc.

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

Another way :

#include <Constants.au3>
#include <WinAPISysWin.au3>

Global $sTitle, $iPosX, $iPosY

Local $iRet = MsgBoxEx($MB_OKCANCEL, "Test", "Text here", 200, 60)
ConsoleWrite("Test response " & $iRet & @CRLF)
$iRet = MsgBoxEx($MB_YESNO, "New Test", "New text here", 300, 0)
ConsoleWrite("New Test response " & $iRet & @CRLF)

Func MsgBoxEx($iFlag, $sWin, $sText, $iX, $iY)
  Local $hTimerProc = DllCallbackRegister(TimerProc, 'none', 'hwnd;uint;uint_ptr;dword')
  Local $iTimerID = _WinAPI_SetTimer(0, 0, 10, DllCallbackGetPtr($hTimerProc))
  $sTitle = $sWin
  $iPosX = $iX
  $iPosY = $iY
  Local $iResp = MsgBox($iFlag, $sWin, $sText)
  DllCallbackFree($hTimerProc)
  Return $iResp
EndFunc   ;==>MsgBoxEx

Func TimerProc($hWnd, $iMsg, $iTimerID, $iTime)
  If WinActive($sTitle) Then
    _WinAPI_KillTimer(0, $iTimerID)
    WinMove($sTitle, "", $iPosX, $iPosY)
  EndIf
EndFunc   ;==>_TimerProc

 

Edited by Nine
better code
Link to comment
Share on other sites

Hello, Another alternative.

#include <WinAPIProc.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>



Global $hGUI = GUICreate("GUI")
Global $idbtnOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK')
_WinAPI_RegisterShellHookWindow($hGUI)



Local $nMsg = 0
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $nMsg = $idbtnOK
            _MsgBox(0, "", "Hello I'm an AutoIt Msgbox at Default Position :-)")
            _MsgBox(0, "", "Hello I'm an AutoIt Msgbox at 10,10 Position :-)", 10, 10)
            _MsgBox(0, "", "Hello I'm an AutoIt Msgbox at " &  @DesktopWidth - 300 & "," & @DesktopHeight - 300 & " Position :-)", @DesktopWidth - 300, @DesktopHeight - 300)
            _MsgBox(0, "", "Hello I'm an AutoIt Msgbox at 0,0 Position :-)", 0, 0)
    EndSelect

WEnd

_WinAPI_DeregisterShellHookWindow($hGUI)
Exit

Func _MsgBoxPostition($X = Default, $Y = Default)
    Local Static $aPos[] = [Default, Default]
    If $X = Default Or $Y = Default Then
        Return $aPos
    EndIf
    $aPos[0] = $X
    $aPos[1] = $Y
EndFunc   ;==>_MsgBoxPostition

Func _MsgBox($iFlag, $Title, $Text, $X = Default, $Y = Default, $iTimeout = Default, $hWnd = Default)
    _MsgBoxPostition($X, $Y)
    MsgBox($iFlag, $Title, $Text, $iTimeout, $hWnd)
EndFunc   ;==>_MsgBox

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg
    Switch $wParam
        Case $HSHELL_WINDOWCREATED
            If WinGetProcess($lParam) = @AutoItPID And _WinAPI_GetClassName($lParam) = "#32770" Then
                Local $aPos = _MsgBoxPostition()
                If $aPos[0] <> Default And $aPos[1] <> Default Then
                    WinMove($lParam, "", $aPos[0], $aPos[1])
                EndIf
            EndIf
    EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Saludos

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...