kann ich die Position einer Msgbox("test","") ändern?
Mit winmove oder sonstiges klappt es nicht
hat jemand eine Idee?
kann ich die Position einer Msgbox("test","") ändern?
Mit winmove oder sonstiges klappt es nicht
hat jemand eine Idee?
Das Problem hatten schon viele !
Während Deine MsgBox angezeigt wird, STEHT das Script. Wie soll also nun noch der nachfolgende Befehl ausgeführt werden ?
Lösungen: Eigene GUI als MsgBox nutzen (Vorschläge findest Du wahrscheinlich hier im Forum schon einige) oder ein zweites (im Vorfeld als EXE kompiliertes) Script in den Hintergrund starten, welches nur auf die MsgBox wartet, diese verschiebt (WinMove) und sich dann beendet.
Hier z.B.:Link
Nutzt am besten die UDF von Progandy
#include-once
#include <WinApi.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
OnAutoItExitRegister("MsgBoxHookDeRegister")
[/autoit] [autoit][/autoit] [autoit]; AutoIt Coding by Prog@ndy
[/autoit] [autoit][/autoit] [autoit];~Author of adapted VB-Code: © Copyright 2002 Pacific Database Pty Limited
;~ Graham R Seach [email='gseach@pacificdb.com.au'][/email]
;~ Phone: +61 2 9872 9594 Fax: +61 2 9872 9593
;~
;~ Adapted from Randy Birch;~s code for creating and
;~ displaying a custom MsgBox with user-defined button
;~ text: "Modifying a Message Box with SetWindowsHookEx"
;~
;~ You may freely use and distribute this code
;~ with any applications you may develop, on the
;~ condition that the copyright notice remains
;~ unchanged, and intact as part of the code. You
;~ may not publish this code in any form without
;~ the express written permission of the copyright
;~ holder.
;~
;~ http://www.pacificdb.com.au/MVP/Code/XMsgBox.htm
;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~;~
Global Const $HCBT_ACTIVATE = 5
Global $MSGBOXEX_strOk
Global $MSGBOXEX_strYes
Global $MSGBOXEX_strNo
Global $MSGBOXEX_strCancel
Global $MSGBOXEX_strPrompt
Global $MSGBOXEX_strTitle
Global $MSGBOXEX_iLeft
Global $MSGBOXEX_iTop
Global $sIcon
Global $MSGBOXEX_HOOK_PARAMS = "long hWndOwner;long hHook"
Global $MSGBOXEX_WINDOWPLACEMENT = "long Length;long flags;long showCmd;"&$tagPOINT&" ptMinPosition;"&$tagPOINT&" ptMaxPosition;" &$tagRECT& "rcNormalPosition"
Global $MSGBOXEX_MSGHOOK = DllStructCreate($MSGBOXEX_HOOK_PARAMS)
Global $MSGBOXHOOKPROC = DllCallbackRegister("MsgBoxHookProc","long","long;long;long")
;~ $mbNone = 0
;~ $mbInformation = 0x40
;~ $mbExclamation = 0x30
;~ $mbQuestion = 0x20
;~ $mbCritical = 0x10
;~ $mbDefaultButton1 = 0x0
;~ $mbDefaultButton2 = 0x100
;~ $mbDefaultButton3 = 0x200
;===============================================================================
;
; Function Name: MsgBoxEx
; Description:: Shows a Message Box with Cutsom Buttons and Optioinal a custom Icon
; Parameter(s): $iFlagType -> MsgBox Flags
; $sPrompt -> Text
; $sTitle -> Title
; $sButtonText1 -> Button1, "" = default Buttons
; $sButtonText2 -> Button2, "" = only 1 Button, if Button 1 defined
; $sButtonText3 -> Button2, "" = 2 Buttons if Button 1 and 2 defined
; $iLeft -> Left Position of MsgBox
; $iTop -> Top Position of MsgBox
; $sIconPath -> Optional: Path of Icon for MsgBox, Default: Empty
; $hwndThreadOwner -> Optional: Handle of owner window
;
; Requirement(s): v3.2.12.0 or higher
; Return Value(s): If no custom ButtonTexts: default MsgBox
; 1 named Button: Closing and Button = 1
; 2 named Buttons: Button1 = 6, Button2 = 7
; 3 named Buttons: Button1 = 6, Button2 = 7, Button3 = 2
; For 2 and 3 Buttons: Closing MsgBox = 2 (cancel) [ ! 3rd named Button is the same ! ]
; Author(s): Prog@ndy
;
;===============================================================================
;
Func MsgBoxEx($iFlagType, $sTitle, $sPrompt, $sButtonText1 = "" , $sButtonText2 = "" , $sButtonText3 = "" , $iLeft = 0, $iTop = 0, $sIconPath = "", $hwndThreadOwner = 0)
Local $hInstance, $hThreadId, $hWndOwner, $iButtons, $xMsgBox
$MSGBOXEX_strPrompt = $sPrompt
$MSGBOXEX_strTitle = $sTitle
$MSGBOXEX_iLeft = $iLeft
$MSGBOXEX_iTop = $iTop
If $iLeft = Default Then $MSGBOXEX_iLeft = Default
If $iTop = Default Then $MSGBOXEX_iTop = Default
If ($sButtonText1 <> "") Or ($sButtonText2 <> "") Or ($sButtonText3 <> "") Then $iFlagType = BitAND($iFlagType,BitNOT(21))
[/autoit] [autoit][/autoit] [autoit]If ($sButtonText1 <> "") And ($sButtonText2 <> "") And ($sButtonText3 <> "") Then
$MSGBOXEX_strYes = $sButtonText1
$MSGBOXEX_strNo = $sButtonText2
$MSGBOXEX_strCancel = $sButtonText3
$iButtons = BitOR(0x3 , $iFlagType )
ElseIf ($sButtonText1 <> "") And ($sButtonText2 <> "") Then
$MSGBOXEX_strYes = $sButtonText1
$MSGBOXEX_strNo = $sButtonText2
$iButtons = BitOR(0x4 , $iFlagType )
ElseIf ($sButtonText1 <> "") Then
$MSGBOXEX_strYes = $sButtonText1
$MSGBOXEX_strOk = $sButtonText1
$iButtons = $iFlagType
EndIf
$sIcon = ""
If $sIconPath <> "" And FileExists($sIconPath) Then $sIcon = $sIconPath
$hInstance = _WinAPI_GetWindowLong($hwndThreadOwner, $GWL_HINSTANCE)
If $hwndThreadOwner = 0 Then
$hInstance = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hInstance = $hInstance[0]
EndIf
$hThreadId = _WinAPI_GetCurrentThreadId()
$hWndOwner = _WinAPI_GetDesktopWindow()
DllStructSetData($MSGBOXEX_MSGHOOK, "hWndOwner", $hWndOwner)
$temp = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_CBT, "ptr", DllCallbackGetPtr($MSGBOXHOOKPROC), "hwnd", $hInstance, "dword", $hThreadId)
DllStructSetData($MSGBOXEX_MSGHOOK, "hHook", $temp[0])
$xMsgBox = MsgBox($iButtons, $sTitle, $sPrompt, 0, $hwndThreadOwner)
Return SetError(@error, @extended, $xMsgBox)
EndFunc
Func MsgBoxHookDeRegister()
DllCallbackFree($MSGBOXHOOKPROC)
EndFunc
Func MsgBoxHookProc($iMsg, $wParam, $lParam)
Local $iRet, $hWnd, $hIcon
If $iMsg = $HCBT_ACTIVATE Then
DllCall("user32.dll", "long", "UnhookWindowsHookEx", "long", DllStructGetData($MSGBOXEX_MSGHOOK, "hHook"))
WinSetTitle($wParam, "", $MSGBOXEX_strTitle)
If $MSGBOXEX_strOk <> "" Then DllCall("user32.dll", "long", "SetDlgItemText", "long", $wParam, "long", 1, "str", $MSGBOXEX_strOk)
If $MSGBOXEX_strYes <> "" Then DllCall("user32.dll", "long", "SetDlgItemText", "long", $wParam, "long", 6, "str", $MSGBOXEX_strYes)
If $MSGBOXEX_strNo <> "" Then DllCall("user32.dll", "long", "SetDlgItemText", "long", $wParam, "long", 7, "str", $MSGBOXEX_strNo)
If $MSGBOXEX_strCancel <> "" Then DllCall("user32.dll", "long", "SetDlgItemText", "long", $wParam, "long", 2, "str", $MSGBOXEX_strCancel)
DllCall("user32.dll", "long", "SetDlgItemText", "long", $wParam, "long", 65535, "str", $MSGBOXEX_strPrompt)
[/autoit] [autoit][/autoit] [autoit]$hWnd = HWnd($wParam)
[/autoit] [autoit][/autoit] [autoit]If $MSGBOXEX_iLeft > 0 Or $MSGBOXEX_iTop > 0 Then WinMove($hWnd, "", $MSGBOXEX_iLeft, $MSGBOXEX_iTop)
[/autoit] [autoit][/autoit] [autoit]If StringLen($sIcon) > 0 Then
$hIcon = _WinAPI_LoadImage(0, $sIcon, $IMAGE_ICON, 0, 0, $LR_LOADFROMFILE)
If $hIcon <> 0 Then
$iRet = _SendMessage($hWnd, $WM_SETICON, 1, $hIcon)
If $iRet <> 0 Then _WinAPI_DestroyIcon($iRet)
EndIf
_WinAPI_DestroyIcon($hIcon)
EndIf
EndIf
Return False
EndFunc
;~ ;### EXAMPLE
;~ $REturn = MsgBoxEx(16+0x200,"Title","Text","Butt 1","The 2nd","The3rd",Default,34,"C:\vista.ico")
;~ MsgBox(0, 'ReturnValue:', $REturn)
; To Use Custom OnAutoItExitFunc, use:
;~ Opt("OnExitFunc","OnAutoItExit")
;~ MsgBoxHookDeRegister() ; Should be called in OnAutoItExit, if it is used.
[/autoit]
Dort kannst u.a. die Position angeben.
Was du nicht brauchst kannste ja löschen.
#include <Constants.au3>
#include <WinAPI.au3>
Global $MsgBoxX = 20
Global $MsgBoxY = 20
Local $hProcMsgBox = DllCallbackRegister("CbtHookProcMsgBox", "int", "int;int;int")
Local $TIDMsgBox = _WinAPI_GetCurrentThreadId()
Local $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox)
Local $iRet = MsgBox(34, "Select example", "Please select the skin you want to try")
$MsgBoxX = 120
Local $iRet = MsgBox(34, "Select example", "Please select the skin you want to try")
$MsgBoxX = 220
Local $iRet = MsgBox(34, "Select example", "Please select the skin you want to try")
_WinAPI_UnhookWindowsHookEx($hHookMsgBox)
DllCallbackFree($hProcMsgBox)
#region Just for fun!!
;##########################################################
Func CbtHookProcMsgBox($nCode, $wParam, $lParam)
Local $RET = 0
If $nCode < 0 Then
$RET = _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
Return $RET
EndIf
Switch $nCode
Case 5 ;5=HCBT_ACTIVATE
_WinAPI_SetDlgItemText($wParam, 3, "1")
_WinAPI_SetDlgItemText($wParam, 4, "2")
_WinAPI_SetDlgItemText($wParam, 5, "3")
_WinAPI_SetWindowPos($wParam, $HWND_TOP, $MsgBoxX, $MsgBoxY, _WinAPI_GetWindowWidth($wParam), _WinAPI_GetWindowHeight($wParam), $SWP_NOZORDER)
EndSwitch
Return
EndFunc ;==>CbtHookProcMsgBox
Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString)
Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _
"hwnd", $hDlg, _
"int", $nIDDlgItem, _
"str", $lpString)
Return $aRet[0]
EndFunc ;==>_WinAPI_SetDlgItemText
;##########################################################
#endregion Just for fun!!
Das ist schön kurz. Aber wieso klappt das nicht bei einem FileSaveDialog mit den Buttons.
Nur der Abbrechen-Button.