找回密码
 加入
搜索
查看: 12216|回复: 18

[AU3基础] msgbox如何在主窗口居中显示?[已解决]

 火.. [复制链接]
发表于 2011-3-16 20:18:08 | 显示全部楼层 |阅读模式
本帖最后由 chenlu_ling 于 2011-3-19 07:16 编辑



如何让MSGBOX在主窗口居中显示呢?而且移动主窗口后再弹出msgbox也能实现在主窗口居中显示
请问如何实现
代码如下
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 439, 297, 281, 213)
$Button1 = GUICtrlCreateButton("点我试试", 176, 128, 75, 25, 0)

GUISetState(@SW_SHOW,$Form1)

#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $Button1
$xy=WinGetPos($Form1,"")
$Form2 = GUICreate("这是创建的新GUI可以实现", 225, 109,$xy[0]+ ($xy[2]-225)/2 , $xy[1]+ ($xy[3]-109)/2)
$Button2 = GUICtrlCreateButton("关闭", 64, 40, 75, 25, 0)
GUISetState(@SW_SHOW,$Form2)
MsgBox(0,"test","这是MsgBox弹出来的提示框,如何在主窗口居中呢?",$Form1)
While 1
$nMsg2 = GUIGetMsg()
Switch $nMsg2
                Case $Button2
           GUIDelete($Form2)
       ExitLoop
        EndSwitch
WEnd

        EndSwitch
WEnd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-3-16 21:44:24 | 显示全部楼层
我是新手。只能帮顶。。。
发表于 2011-3-16 21:44:28 | 显示全部楼层
不会!!!
 楼主| 发表于 2011-3-16 21:56:42 | 显示全部楼层
不会要自写  _MsgBox 函数吧。。。。
发表于 2011-3-16 22:02:03 | 显示全部楼层
很有现实意义的问题,关注
发表于 2011-3-16 23:28:34 | 显示全部楼层
本帖最后由 lixiaolong 于 2011-3-16 23:30 编辑

主窗口居中显示,这个方法不太好.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 439, 297, 281, 213)
$Button1 = GUICtrlCreateButton("点我试试", 176, 128, 75, 25, 0)

GUISetState(@SW_SHOW, $Form1)
$Timer = DllCallbackRegister("_WinCenter", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 0, "ptr", DllCallbackGetPtr($Timer))

#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $xy = WinGetPos($Form1, "")
                        $Form2 = GUICreate("这是创建的新GUI可以实现", 225, 109, $xy[0] + ($xy[2] - 225) / 2, $xy[1] + ($xy[3] - 109) / 2)
                        $Button2 = GUICtrlCreateButton("关闭", 64, 40, 75, 25, 0)
                        GUISetState(@SW_SHOW, $Form2)
                        MsgBox(0, "test", "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", $Form1)
                        While 1
                                $nMsg2 = GUIGetMsg()
                                Switch $nMsg2
                                        Case $Button2
                                                GUIDelete($Form2)
                                                ExitLoop
                                EndSwitch
                        WEnd

        EndSwitch
WEnd

Func _WinCenter($hWnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $TimerDLL[0] Then
                $pos = WinGetPos($Form1)
                If Not @error Then _
                                WinMove('[CLASS:#32770]', "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", $pos[0] + 52, $pos[1] + 80)
                                WinSetOnTop('[CLASS:#32770]', "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", 1)
        EndIf
EndFunc   ;==>_WinCenter
发表于 2011-3-17 14:11:10 | 显示全部楼层
呵呵移动
发表于 2011-3-17 22:50:29 | 显示全部楼层
楼主自己画个GUI,做得像MsgBox差不多不就行了
发表于 2011-3-18 14:02:04 | 显示全部楼层
把代码修改为
$Form1 = GUICreate("Form1", 439, 297)
即可
发表于 2011-3-18 22:17:06 | 显示全部楼层
楼主,msgbox的大小是会根据你里面的内容长短而变化的。
函数要事先计算msgbox的长度跟高度,然后根据lixiaolong的函数去移动。
发表于 2011-3-18 22:48:08 | 显示全部楼层
用钩子 _WinAPI_SetWindowsHookEx
P版以前写个一个类似的例子,需要的搜索下,稍加修改即可~
发表于 2011-3-19 02:18:31 | 显示全部楼层
http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=13550&pid=184278&fromuid=1003
参考P版的一段源码,根据楼主要求稍作修改:
#include <WinAPI.au3>

$hGUI = GUICreate("msgbox在主窗口居中显示", 400, 300)
GUICtrlCreateButton("Popup a MsgBox Window", 20, 40, 150, 20)
GUISetState(@SW_SHOW, $hGUI)

$hInst = _WinAPI_GetWindowLong($hGUI, -6)
$iThreadId = _WinAPI_GetCurrentThreadId()

$hCallBack = DllCallBackRegister("_CallBack", "int", "int;hWnd;ptr")
$pCallBack = DllCallBackGetPtr($hCallBack)

$hHook = _WinAPI_SetWindowsHookEx(5, $pCallBack, $hInst, $iThreadId)

While 1
        Switch GUIGetMsg()
        Case -3
                ExitLoop
        Case 3
                                DllCall("user32.dll","int","MessageBox","hwnd",$hGUI,"str","不会在任务栏出现对话框" & @crlf, "str","测试例子","int",48)
        EndSwitch
WEnd
GUIDelete($hGUI)
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallBackFree($hCallBack)


Func _CallBack($iCode, $wParam, $lParam)
        If ($iCode = 5) And ($wParam <> $hGUI) Then
                        $size = WinGetPos($hGUI)
                        WinMove($wParam, "", $size[0]+$size[2]/4, $size[1]+$size[3]/2.5, Default, Default)
        EndIf
        Return 0
EndFunc        ;==>_CallBack

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-3-19 07:14:44 | 显示全部楼层
回复 12# lynfr8


    多谢 lynfr8 已达到效果。  你的截图工具也挺强大的 O(∩_∩)O~
发表于 2011-3-19 11:36:14 | 显示全部楼层
LZ还需注意10#的提示,MsgBox 宽度较宽,甚至超出主界面的处理。
还有将弹出的 MsgBox 移开后点击其它第三方窗口,再点击本程序窗口,MsgBox 又会自动返回原处的问题。
发表于 2011-3-21 15:54:08 | 显示全部楼层
新手正好学习下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 03:39 , Processed in 0.085359 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表