StayOnTop Crashes when Compiled

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
krash2501
Newbie
Posts: 15
Joined: Thu Jul 21, 2016 7:04 pm

StayOnTop Crashes when Compiled

Post by krash2501 » Fri Feb 24, 2017 9:45 pm

I am not sure if I have this code in the correct spots or what the issue is. The dialog window works perfect when running from script editor but if I do a quick launch or run from EXE it locks up and does not work to the point I have to kill MS.

Do I have the GoSub>StayOnTop,Dialog1.Handle in the right place? as well as the SRT>StayOnTop?

Code: Select all

WriteLn>C:\Temp\Reboot.txt,result,NO
Dialog>Dialog1

....DIALOG DETAILS MINAMIZED...

EndDialog>Dialog1

GoSub>StayOnTop,Dialog1.Handle

AddDialogHandler>Dialog1,MSButton1,OnClick,DoClick(1)

Show>Dialog1,res1

SRT>StayOnTop
  Let>HWND_TOPMOST=-1
  Let>HWND_NOTOPMOST=-2
  Let>SWP_NOSIZE=1
  Let>SWP_NOMOVE=2
  Let>SWP_NOACTIVATE=16
  Let>SWP_SHOWWINDOW=64
  Let>WindowHandle=%StayOnTop_var_1%
  Let>Flags={%SWP_NOACTIVATE% Or %SWP_SHOWWINDOW% Or %SWP_NOMOVE% Or %SWP_NOSIZE%}
  LibFunc>User32,SetWindowPos,swpr,%WindowHandle%,HWND_TOPMOST,0,0,0,0,Flags
END>StayOnTop

SRT>DoClick
    SetDialogProperty>Dialog1,Edit2,Text,Restart in progress...
Message>The system is going to Log off now. Please wait 90 secs before you remote back in to th system.
wait>3
END>DoClick

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: StayOnTop Crashes when Compiled

Post by JRL » Sat Feb 25, 2017 5:46 am

I don't know why your script crashes but I can tell you that you no longer need to use the library function to make a dialog stay on top. Instead use the dialog formstyle property "fsStayOnTop". The property will make a dialog stay on top as long as the dialog is run as a script file. If you want to compile a script with a stay on top dialog, you will also have to add some code that perpetually cycles and perpetually "moves" the dialog to its current position. See the script below for an example.

In the sample the dialog is non-modal, meaning the Show> function does not contain a result variable. The lack of result variable allows the script to continue past the Show> function. We therefore get to add a loop that will cycle perpetually and perform the needed dialog "move" to its current location. I don't know why this technique is required I just know that for a compiled script to contain a stay on top dialog, the "fake moves" must be implemented. (I crack myself up.)


Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'StayOnTop Sample'
  ClientHeight = 150
  ClientWidth = 300
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
SetDialogProperty>Dialog1,,Formstyle,fsStayOnTop

Show>Dialog1

Label>Loop
  Wait>0.01
  //The next four lines only needed for compiled scripts
  Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,Dialog1X,Dialog1Y
    MoveWindow>Dialog1.handle,Dialog1X,Dialog1Y
  Let>WIN_USEHANDLE=0
Goto>Loop

SRT>Quit
  Exit>0
END>Quit

krash2501
Newbie
Posts: 15
Joined: Thu Jul 21, 2016 7:04 pm

Re: StayOnTop Crashes when Compiled

Post by krash2501 » Mon Feb 27, 2017 5:33 pm

Thanks this worked great for what I needed.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts