Home Technical Talk

MAXScript: giving dialogs focus / bringing to front

polycounter lvl 9
Offline / Send Message
PatJS polycounter lvl 9
Hey guys,

I'm running into an issue with a script I'm working on. It's for manipulating shells in the Unwrap UVW window, and unfortunately the UV window likes to steal the focus, sending my floating dialog behind it. Since it's an interactive tool, this renders it pretty unusable, especially if the UV window is maximized! I've done some searching, but I can't find anything, so I figured I'd ask here.

Does anyone know how to bring dialogs to the foreground?

Replies

  • Bryan Cavett
    Options
    Offline / Send Message
    Bryan Cavett polycounter lvl 19
    Look up "setFocus" in the maxscript help. You can use it to set focus to a specific dialog element.
  • PatJS
    Options
    Offline / Send Message
    PatJS polycounter lvl 9
    Thanks Bryan, but I already tried that :(

    I did some more testing, and I realized that the issue is due to the way that the UV dialog works: if you mouseover the UV field (not the controls, though), it automatically steals focus.

    Is there a solution more elegant than running a timer and constantly stealing focus? What I'm really looking for is a way to have it always-on-top, like you can do with forms in Windows.

    EDIT: blech, a timer doesn't work because you just get horrible flashing as the focus is constantly alternating between the UV window and the script window
  • monster
    Options
    Offline / Send Message
    monster polycounter
    You can look into Window parenting with dotNet: http://forums.cgsociety.org/showthread.php?t=1112216

    I've never used it for the UV window, but when you create dotNET forms they tend to go behind the main max window unless you parent it (or use a MaxForm).
  • PatJS
    Options
    Offline / Send Message
    PatJS polycounter lvl 9
    Thanks monster, I'll take a look into using dotNet.

    In the mean time, for interested parties, I've made the problem less severe by spawning the tool window underneath the cursor, which keeps it in focus until the user mouses off of it, which also means that the user will notice it getting eaten by the UV window. Not a solution at all, but it prevents the previous behavior, which was briefly popping up and then being immediately eaten.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    You could try get the HWND id(? think that's correct) and parent you're window to that. Used it to minimize another app I was running. If its a regular dialog i believe it inherits the control properties from Max so if you minimize max the window minimizes etc. Could try dotnet form as monster said.
  • PatJS
    Options
    Offline / Send Message
    PatJS polycounter lvl 9
    hey haiddasalami, that ended up being what I did :)

    here's the specific code for those interested:
    theParent = windows.getChildHWND 0 "Edit UVWs"
    createdialog UVMatchRO pos:(mouse.screenpos - [32,32]) parent:theParent[1]
    

    when you use getChildHWND you get a bunch of crap, but the first element is the pointer to that window, which is what you care about when using the parent parameter of createDialog.

    With this my big ol' pack o' scripts is nearly done, look forward to a thread soon!
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Thanks for posting your solution. I didn't realize createDialog had a parent parameter. I would have totally over complicated this tool.
Sign In or Register to comment.