Modify dialog window position after grabbing with DialogMonitorOPS

polycounter lvl 11
Offline / Send Message
SimonT polycounter lvl 11
Hi, i try to set the position of the "Relax Tool" dialog right against the mouse cursor. Here is code from the help which alerts me when the dialog is opened. But how can i modifiy it's position? I didn't found anything in the help and also no examples using dotNet. :,(

DialogMonitorOPS.unRegisterNotification id:#eyeInTheSky

fn dmnotification =
(
WindowHandle = DialogMonitorOPS.GetWindowHandle()

dialogName = UIAccessor.GetWindowText WindowHandle;
if (dialogName == "Relax Tool") do messageBox("test");

true
)

DialogMonitorOPS.RegisterNotification dmnotification id:#eyeInTheSky
DialogMonitorOPS.Enabled = true
DialogMonitorOPS.ShowNotification()

Replies

  • monster
    Offline / Send Message
    monster Polycount Sponsor
    Unfortunately, I don't think it's trivial. For example, if you look at this script: http://www.scriptspot.com/3ds-max/scripts/give-me-back-my-dialogs

    It actually compiles dotNET code in memory to collect and move windows and dialogs. He has a post about it here, but the latest code is on scriptspot: http://lonerobot.net/?p=710
  • leslievdb
    Offline / Send Message
    leslievdb polycounter lvl 8
    I'm not sure what you are planning to do but i managed to get the dialog to snap to the mouseposition. If you bind this macroscript to a shortkey you can just press it and it will move the window to your mouseposition

    mostly referenced this code
    macroscript RelaxToolToMouse category:"RelaxToolToMouse" ButtonText:"RelaxToolToMouse"
    (
    fn DialogWindowOpsClass =
    (
    source = ""
    source += "Imports System.Runtime.InteropServices\n"
    source += "Imports System.Drawing\n"
    source += "Public Class DialogWindowOps\n"
    source += "Public Structure RECT\n"
    source += "Public left As Integer\n"
    source += "Public top As Integer\n"
    source += "Public right As Integer\n"
    source += "Public bottom As Integer\n"
    source += "Public ReadOnly Property Width() As Integer\n"
    source += "Get\n"
    source += "Return right - left\n"
    source += "End Get\n"
    source += "End Property\n"
    source += "Public ReadOnly Property Height() As Integer\n"
    source += "Get\n"
    source += "Return bottom - top\n"
    source += "End Get\n"
    source += "End Property\n"
    source += "End Structure\n"
    source += "Public Structure POINTAPI\n"
    source += "Public x As Integer\n"
    source += "Public y As Integer\n"
    source += "End Structure\n"
    source += "Public Structure WINDOWPLACEMENT\n"
    source += "Public Length As Integer\n"
    source += "Public flags As Integer\n"
    source += "Public showCmd As Integer\n"
    source += "Public ptMinPosition As POINTAPI\n"
    source += "Public ptMaxPosition As POINTAPI\n"
    source += "Public rcNormalPosition As RECT\n"
    source += "End Structure\n"
    source += "<DllImport(\"user32.dll\")> _\n"
    source += "Public Shared Function MoveWindow(ByVal hWnd As System.IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean\n"
    source += "End Function\n"
    source += "<DllImport(\"user32.dll\")> _\n"
    source += "Public Shared Function GetWindowRect(ByVal hWnd As System.IntPtr, ByRef lpRect As RECT) As Boolean\n"
    source += "End Function\n"
    source += "<DllImport(\"user32.dll\")> _\n"
    source += "Public Shared Function GetWindowPlacement(ByVal hWnd As System.IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Boolean\n"
    source += "End Function\n"
    source += "Public Function WindowSize(ByVal Hwnd As System.IntPtr) As System.Drawing.Size\n"
    source += "Dim LPRECT As RECT\n"
    source += "GetWindowRect(Hwnd, LPRECT)\n"
    source += "Dim WinSize As System.drawing.size = New System.drawing.size(LPRECT.Width, LPRECT.Height)\n"
    source += "Return WinSize\n"
    source += "End Function\n"
    source += "Public Function WindowPosition(ByVal Hwnd As System.IntPtr) As System.Drawing.Point\n"
    source += "Dim intRet As Integer\n"
    source += "Dim wpTemp As WINDOWPLACEMENT = New WINDOWPLACEMENT()\n"
    source += "wpTemp.Length = System.Runtime.InteropServices.Marshal.SizeOf(wpTemp)\n"
    source += "intRet = GetWindowPlacement(Hwnd, wpTemp)\n"
    source += "Dim WinPoint As System.drawing.point = New System.drawing.point(wpTemp.rcNormalPosition.left,wpTemp.rcNormalPosition.top)\n"
    source += "Return WinPoint\n"
    source += "End Function\n"
    source += "End Class"

    VBProvider = dotnetobject "Microsoft.VisualBasic.VBCodeProvider"
    compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
    compilerParams.ReferencedAssemblies.add "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.drawing.dll"
    compilerParams.GenerateInMemory = on
    compilerResults = VBProvider.CompileAssemblyFromSource compilerParams #(source)


    -- this is very useful to debug your source code and check for referencing errors
    if (compilerResults.Errors.Count > 0 ) then
    (
    errs = stringstream ""
    for i = 0 to (compilerResults.Errors.Count-1) do
    (
    err = compilerResults.Errors.Item
    format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line \
    err.Column err.ErrorText to:errs
    )
    MessageBox (errs as string) title: "Errors encountered while compiling VB code"
    return undefined
    )
    return compilerResults.CompiledAssembly.CreateInstance "DialogWindowOps"
    )
    on execute do
    (
    WindowOps = DialogWindowOpsClass()
    WindowHandle = DialogMonitorOPS.GetWindowHandle()
    dialogName = UIAccessor.GetWindowText WindowHandle;

    DialogList = for i in (windows.getChildrenHWND WindowHandle)--0 parent:#max)
    where UIAccessor.IsWindow i[1] and (not i[5] == "AdApplicationButton") and (not i[5] == "") collect i[1]
    RelaxToolHandle= (for i in DialogList where ((dotnetobject "system.string" (UIAccessor.GetWindowText i)).startswith "Relax") collect i)[1]
    if RelaxToolHandle !=undefined then
    (
    intPtrRelaxToolHandle = dotnetobject "System.IntPtr" RelaxToolHandle
    RelaxToolsize = WindowOps.Windowsize intPtrRelaxToolHandle
    WindowOps.moveWindow intPtrRelaxToolHandle mouse.screenpos.x mouse.screenpos.y RelaxToolSize.width RelaxToolsize.height true
    )
    )
    )



  • SimonT
    Offline / Send Message
    SimonT polycounter lvl 11
    Thx for the answers. I changed the script and converted it to an auto click script.

    You can setup a dialog name and the button which should be pressed automatically and when the script runs (after click on "activate") it will do the work for you as long as you not hit "deactivate". Works well for me and also saves the setup in a file for the next start.

    autoclick.jpg
  • mLichy
Sign In or Register to comment.