Jump to content

Another MsgBox option


SmOke_N
 Share

Recommended Posts

  • Moderators

Due to this thread: http://www.autoitscript.com/forum/index.ph...c=82250&hl=

I attempted to find a way to set scroll bars to a static control. I failed miserably with SetWindowLong/GetWindowLong so I took an alternative.

This option also has x and y position capability. Maybe others can add the button text options etc to it like we've done in the past to improve the other message box udfs.

Edit: Only compatible with 3.2.12.1 and above due to the hwnd parameter in the message box.

#Include <MsgBox.au3>

#include-once
Global $h_include_msgbox_hwnd = 0
Global $a_include_msgbox[7]
Global $i_include_msgbox_return = "NoValue"
Global $f_include_msgbox = False
Global $f_include_msgbox_wait = False

Func _MsgBox($i_flag, $s_title, $s_text, $i_time = 0, $h_parent = 0, $i_x = -1, $i_y = -1)
    If $i_x = Default Then $i_x = -1
    If $i_y = Default Then $i_y = -1
    
    $a_include_msgbox[0] = $i_flag
    $a_include_msgbox[1] = $s_title
    $a_include_msgbox[2] = $s_text
    $a_include_msgbox[3] = $i_time
    $a_include_msgbox[4] = $h_parent
    $a_include_msgbox[5] = $i_x
    $a_include_msgbox[6] = $i_y
    
    Local $h_mod, $h_timer, $i_ret
    $h_timer = _MsgBox_StartTimer($h_mod, "_MsgBox_Execute", "int", "", 0, 10001, 10)
    While $i_include_msgbox_return = "NoValue"
        Sleep(10)
    WEnd
    _MsgBox_StopTimer($h_mod, $h_timer)
    
    $i_ret = $i_include_msgbox_return
    $i_include_msgbox_return = "NoValue"
    $f_include_msgbox = False
    $f_include_msgbox_wait = False
    $h_include_msgbox_hwnd = 0
    
    Return $i_ret
EndFunc

Func _MsgBox_Execute()
    If Not $f_include_msgbox Then
        $f_include_msgbox = True
        $i_include_msgbox_return = _
            MsgBox($a_include_msgbox[0], _
                $a_include_msgbox[1], _
                $a_include_msgbox[2], _
                $a_include_msgbox[3], _
                $a_include_msgbox[4])
    EndIf
    If $f_include_msgbox Then
        If Not $f_include_msgbox_wait Then
            $f_include_msgbox_wait = True
            $h_include_msgbox_hwnd = WinGetHandle("[TITLE:" & $a_include_msgbox[1] & ";CLASS:#32770]")
            Local $a_winsize = WinGetPos($h_include_msgbox_hwnd)
            WinMove($h_include_msgbox_hwnd, "", 0, 0, 0, 0)
            Local $h_edit_handle, $i_add_static
            Do
                $i_add_static += 1
                $h_edit_handle = ControlGetHandle($h_include_msgbox_hwnd, "", "Static" & $i_add_static)
            Until ControlGetText($h_include_msgbox_hwnd, "", $h_edit_handle) <> ""
            
            Local $s_text = ControlGetText($h_include_msgbox_hwnd, "", $h_edit_handle)
            If StringLen($s_text) > 30 Then
                Local $i_width = 330
                Local $i_height = 100
                Local $i_x_pos = 35
                Local $i_y_pos = 10
                Local $a_list = WinGetClassList($h_include_msgbox_hwnd)
                Local $s_hold_button = "", $i_add, $h_button_handle
                Local $s_hold_static = ""
                While 1
                    $i_add += 1
                    If Not ControlGetHandle($h_include_msgbox_hwnd, "", "Static" & $i_add) Then ExitLoop
                    $s_hold_static &= "Static" & $i_add & ","
                WEnd
                Local $a_statics = StringSplit(StringTrimRight($s_hold_static, 1), ",")
                $i_add = 0
                While 1
                    $i_add += 1
                    $h_button_handle = ControlGetHandle($h_include_msgbox_hwnd, "", "Button" & $i_add)
                    If Not $h_button_handle Then ExitLoop
                    $s_hold_button &= "Button" & $i_add & ","
                WEnd
                Local $a_buttons = StringSplit(StringTrimRight($s_hold_button, 1), ",")
                If @OSVersion = "WIN_VISTA" Then
                    Switch $a_buttons[0]
                        Case 1
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * .48, $i_height + 20)
                        Case 2
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * 0.33, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button2", $i_width * 0.63, $i_height + 20)
                        Case 3
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * 0.17, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button2", $i_width * 0.47, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button3", $i_width * 0.77, $i_height + 20)
                    EndSwitch
                Else
                    Switch $a_buttons[0]
                        Case 1
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * .48, $i_height + 20)
                        Case 2
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * 0.38, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button2", $i_width * 0.63, $i_height + 20)
                        Case 3
                            ControlMove($h_include_msgbox_hwnd, "", "Button1", $i_width * 0.25, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button2", $i_width * 0.50, $i_height + 20)
                            ControlMove($h_include_msgbox_hwnd, "", "Button3", $i_width * 0.75, $i_height + 20)
                    EndSwitch
                EndIf
                Local $h_edit_handle = ControlGetHandle($h_include_msgbox_hwnd, "",  $a_statics[$a_statics[0]])
                Local $a_cpos = ControlGetPos($h_include_msgbox_hwnd, "", $h_edit_handle)
                If @OSVersion = "WIN_VISTA" Then
                    If $a_cpos[0] <> 12 Then
                        $i_x_pos = $a_cpos[0]
                        $i_y_pos = $a_cpos[1]
                    EndIf
                ElseIf $a_cpos[0] <> 15 Then
                    $i_x_pos = $a_cpos[0]
                    $i_y_pos = $a_cpos[1]
                EndIf
                Local $s_text = ControlGetText($h_include_msgbox_hwnd, "", $h_edit_handle)
                ControlHide($h_include_msgbox_hwnd, "", $h_edit_handle)
                Local $h_edit_control =  DllCall("user32.dll", "hwnd", "CreateWindowEx", "long", 0x00000200, "str", "Edit", "str", "", _
                                            "long", BitOR(0x503310C4, 0x0800), "int", $i_x_pos, "int", $i_y_pos, "int", 330, "int", 100, _
                                            "hwnd", $h_include_msgbox_hwnd, "hwnd", 0, "long", 0, "ptr",0)
                $h_edit_control = $h_edit_control[0]
                DllCall("user32.dll", "int", "SetParent", "hwnd", $h_edit_control, "hwnd", $h_include_msgbox_hwnd)
                DllCall("user32.dll", "int", "ShowWindow", "hwnd", $h_edit_control, "uint", 5)
                Local $t_settext = DllStructCreate("char[" & StringLen($s_text) + 1 & "]")
                DllStructSetData($t_settext, 1, $s_text)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_edit_control, "uint", 0x00C, "wparam", 0, "lparam", DllStructGetPtr($t_settext))
                If $a_include_msgbox[4] = 0 And $a_include_msgbox[5] = -1 Then $a_include_msgbox[5] = (@DesktopWidth / 2.5)
                If $a_include_msgbox[4] = 0 And $a_include_msgbox[6] = -1 Then $a_include_msgbox[6] = (@DesktopHeight / 2) - 150
                WinMove($h_include_msgbox_hwnd, "", $a_include_msgbox[5], $a_include_msgbox[6], 400, 185)
                DllCall("User32.dll", "int", "UpdateWindow", "hwnd", $h_include_msgbox_hwnd)
                ControlFocus($h_include_msgbox_hwnd, "", "Button1")
            Else
                If $a_include_msgbox[4] = 0 And $a_include_msgbox[5] = -1 Then $a_include_msgbox[5] = $a_winsize[0];(@DesktopWidth / 2.5)
                If $a_include_msgbox[4] = 0 And $a_include_msgbox[6] = -1 Then $a_include_msgbox[6] = $a_winsize[1];(@DesktopHeight / 2) - 150
                WinMove($h_include_msgbox_hwnd, "", $a_include_msgbox[5], $a_include_msgbox[6], $a_winsize[2], $a_winsize[3])
            EndIf
        EndIf
    EndIf
EndFunc

Func _MsgBox_StartTimer(ByRef $h_mod, $s_func, $v_ret_type, $v_params, $h_wnd, $i_event_id, $i_event_time)
    $h_mod = DllCallbackRegister($s_func, $v_ret_type, $v_params)
    If @error Then Return SetError(@error, 1, 0)
    Local $h_timer = DllCall("User32.dll", "int", "SetTimer", _
                        "hwnd", $h_wnd, _
                        "uint", $i_event_id, _
                        "uint", $i_event_time, _
                        "ptr", DllCallbackGetPtr($h_mod))
    If @error Then Return SetError(@error, 2, 0)
    Return $h_timer[0]
EndFunc

Func _MsgBox_StopTimer($h_mod, $h_timer, $h_wnd = 0)
    DllCallbackFree($h_mod)
    DllCall("User32.dll", "int", "KillTimer", "hwnd", $h_wnd, "int", $h_timer)
    If @error Then Return SetError(@error, 0, 0)
    Return 1
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm curious to see this in action, but....

3.2.13.8, Vista SP1 32-bit, and it's not working. The window is hidden. WinSpy shows it centered on the screen but with a width of 0x0. So I manually changed it, but the window doesn't work correctly, and I can't close it. Bummer.

Link to comment
Share on other sites

Ok, here's the deal on Vista. When there is an icon, the icon is Static2, and the text is Static3. Without the icon, the text is Static2.

This is a neat idea. I think the control posiitons need to be tweaked, probably just on Vista, but it's a nice solution.

Link to comment
Share on other sites

  • Moderators

I'm curious to see this in action, but....

3.2.13.8, Vista SP1 32-bit, and it's not working. The window is hidden. WinSpy shows it centered on the screen but with a width of 0x0. So I manually changed it, but the window doesn't work correctly, and I can't close it. Bummer.

Ok, here's the deal on Vista. When there is an icon, the icon is Static2, and the text is Static3. Without the icon, the text is Static2.

This is a neat idea. I think the control posiitons need to be tweaked, probably just on Vista, but it's a nice solution.

Should be easy enough to over come with a few tweaks... but I'd have to run in both environments to see the differences. The Static thing could be over come with using the WinGetClassList() and pushing it above and making an exception for the Icon/No Icon/Vista by using the last static control.

I don't have much time to play with it to be honest... thought you guys could add/take away as you saw fit :P ... I don't need the recognition, you guys are more than capable of taking this to another level :(.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Ok, here's the deal on Vista. When there is an icon, the icon is Static2, and the text is Static3. Without the icon, the text is Static2.

This is a neat idea. I think the control posiitons need to be tweaked, probably just on Vista, but it's a nice solution.

I think the update I just made is a poor option, but I simply don't have the time to do it properly.... But it "should" work all the same.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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