Sign in to follow this  
Followers 0
Chimp

How to Move an MsgBox from within the same script?

6 posts in this topic

I was reading >this old post about moving a msgbox(), and what seems interesting to me is that instead of executing an "external" script to show the msgbox(), this one (according to the explanation given >here) should move the msgbox() from within the same script using the SetTimer function that, unlike the AdlibRegister(), it shouldn't stop during the showing of the MsgBox().
Unfortunately the code of the first topic is corrupted.

Does someone knows how to restore that code or how to achieve that result.

Thanks


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Not sure if we still can recover the code, but the readable part refers to _MessageBox() not MsgBox()!

There are several UDFs out there where the MSGBOX() is created by a GUICreate() which makes it none blocking.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

If I do not misunderstand the explanation >given here, it should manage a real MsgBox() making use of the WM_TIMER notifications.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Something like this?
 

#include <WinAPISys.au3>
Global $WM_TIMER = 0x0113
Global $hTimerProc
Global $iTimerID
Global $MsgBox_Title
Global $MsgBox_Text
Global $MsgBox_X
Global $MsgBox_Y
Global $MsgBox_W
Global $MsgBox_H
;
_MessageBox(10, 10, Default, Default, 0, "Test", "This is just a test :)", 0) ;move the MsgBox to 10,10
;
Func _MessageBox($iMsgBox_X, $iMsgBox_Y, $iMsgBox_W, $iMsgBox_H, $iMsgBox_P1, $iMsgBox_P2, $iMsgBox_P3, $iMsgBox_P4 = 0, $iMsgBox_P5 = 0)
    $hTimerProc = DllCallbackRegister('_MoveMsgBox', 'none', 'hwnd;uint;uint_ptr;dword')
    $iTimerID = _WinAPI_SetTimer(0, 0, 50, DllCallbackGetPtr($hTimerProc))
    $MsgBox_Title = $iMsgBox_P2
    $MsgBox_Text = $iMsgBox_P3
    $MsgBox_X = $iMsgBox_X
    $MsgBox_Y = $iMsgBox_Y
    $MsgBox_W = $iMsgBox_W
    $MsgBox_H = $iMsgBox_H
    MsgBox($iMsgBox_P1, $iMsgBox_P2, $iMsgBox_P3, $iMsgBox_P4, $iMsgBox_P5)
    ; kill timer in case still there.
    _WinAPI_KillTimer(0, $iTimerID)
    DllCallbackFree($hTimerProc)
EndFunc   ;==>_MessageBox
;
Func _MoveMsgBox($hWnd, $iMsg, $iTimerID, $iTime)
    #forceref $hWnd, $iMsg, $iTimerId, $iTime
    $rc = WinMove($MsgBox_Title, $MsgBox_Text, $MsgBox_X, $MsgBox_Y, $MsgBox_W, $MsgBox_H)
    ; kill timer in case move was successfull.
    If $rc Then
        _WinAPI_KillTimer(0, $iTimerID)
        DllCallbackFree($hTimerProc)
    EndIf
EndFunc   ;==>_MoveMsgBox

Jos

2 people like this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks Jos,

maybe that old post had used this same way you posted here.

very interesting. It can be handy also in other situations, (since WM_TIMER doesn't stop working also against pausing function, for example Sleep, MsgBox or while dragging a windows for example (as AdlibRegister does instead))

Thanks again


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@Jos

Excellent example, but the window appears for a brief period of time, to avoid this, we can use "WH_CBT", see example below:

#include <WinAPI.au3>

#cs
    HCBT_MOVESIZE = 0
    HCBT_MINMAX = 1
    HCBT_QS = 2
    HCBT_CREATEWND = 3
    HCBT_DESTROYWND = 4
    HCBT_ACTIVATE = 5
    HCBT_CLICKSKIPPED = 6
    HCBT_KEYSKIPPED = 7
    HCBT_SYSCOMMAND = 8
    HCBT_SETFOCUS = 9
#ce
Global Const $HCBT_ACTIVATE = 5

Global $MsgBox_Title
Global $MsgBox_Text
Global $MsgBox_X
Global $MsgBox_Y
Global $MsgBox_W
Global $MsgBox_H
OnAutoItExitRegister("Terminate")

;---->
Global $hCBTPROC_CALLBK = DllCallbackRegister("_WH_CBT", "int", "int;int;int")
If Not $hCBTPROC_CALLBK Then
    MsgBox(4096, "Error!", "DllCallbackRegister fail!")
    Exit
EndIf
Global $hCBTPROC_HOOK = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hCBTPROC_CALLBK), 0, _WinAPI_GetCurrentThreadId())
If Not $hCBTPROC_HOOK Then
    DllCallbackFree($hCBTPROC_CALLBK)
    MsgBox(4096, "Error!", "_WinAPI_SetWindowsHookEx fail!")
    Exit
EndIf
;<----

;
_MessageBox(10, 10, Default, Default, 0, "Test", "This is just a test :)", 0) ;move the MsgBox to 10,10
;
Func _MessageBox($iMsgBox_X, $iMsgBox_Y, $iMsgBox_W, $iMsgBox_H, $iMsgBox_P1, $iMsgBox_P2, $iMsgBox_P3, $iMsgBox_P4 = 0, $iMsgBox_P5 = 0)
    $MsgBox_Title = $iMsgBox_P2
    $MsgBox_Text = $iMsgBox_P3
    $MsgBox_X = $iMsgBox_X
    $MsgBox_Y = $iMsgBox_Y
    $MsgBox_W = $iMsgBox_W
    $MsgBox_H = $iMsgBox_H
    MsgBox($iMsgBox_P1, $iMsgBox_P2, $iMsgBox_P3, $iMsgBox_P4, $iMsgBox_P5)
EndFunc   ;==>_MessageBox

Func _WH_CBT($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hCBTPROC_HOOK, $nCode, $wParam, $lParam)
    EndIf

    Switch $nCode
        Case $HCBT_ACTIVATE
            If WinGetTitle(HWnd($wParam)) = $MsgBox_Title Then
                ;TrayTip("$HCBT_ACTIVATE", "Win title: " & WinGetTitle(HWnd($wParam)), 20, 1)
                WinMove(HWnd($wParam), $MsgBox_Text, $MsgBox_X, $MsgBox_Y, $MsgBox_W, $MsgBox_H)
            EndIf
    EndSwitch

    Return _WinAPI_CallNextHookEx($hCBTPROC_HOOK, $nCode, $wParam, $lParam)
EndFunc   ;==>_WH_CBT

Func Terminate()
    _WinAPI_UnhookWindowsHookEx($hCBTPROC_HOOK)
    Exit
EndFunc   ;==>Terminate
JS Edited by JScript
1 person likes this

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
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
Sign in to follow this  
Followers 0