Creating a Modal Window
Create a modal dialog window, and keep it focused over a parent window.
Windows.xml
Spoiler:
xml code:
<Interfaces xmlns="urn:msgplus:interface" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:msgplus:interface PlusInterface.xsd">
<Window Id="WndParent" Version="1">
<!-- no specific guidelines for the parent window -->
<Attributes>
<Caption>Modal Test</Caption>
</Attributes>
<TitleBar>
<Title>
<Prefix>Image</Prefix>
<Text>Modal Test</Text>
</Title>
</TitleBar>
<Position Width="300" Height="250">
<IsAbsolute>true</IsAbsolute>
</Position>
<DialogTmpl/>
<Controls>
<Control xsi:type="CodeEditControl" Id="EdtCode">
<Position Left="3" Top="0" Width="280" Height="171">
<Units>AllPixels</Units>
</Position>
</Control>
<Control xsi:type="ButtonControl" Id="BtnConfirm">
<Position Left="3" Top="177" Width="70">
<Units>AllPixels</Units>
</Position>
<Attributes>
<IsDefault>true</IsDefault>
</Attributes>
<StandardLook Template="Blue"/>
<Caption>&Confirm...</Caption>
<Help>Display the confirmation...</Help>
</Control>
<Control xsi:type="ButtonControl" Id="BtnCancel">
<Position Left="228" Top="177" Width="55">
<Units>AllPixels</Units>
</Position>
<Caption>&Close</Caption>
<Help>Close the window...</Help>
</Control>
</Controls>
</Window>
<Window Id="WndChild" Version="1">
<!-- child window should not have taskbar button, and should not be allowed to minimize -->
<Attributes>
<Caption>Confirm?</Caption>
<ShowInTaskbar>false</ShowInTaskbar>
</Attributes>
<TitleBar>
<AllowMinimize>false</AllowMinimize>
<AllowClose>false</AllowClose>
<Title>
<Prefix>Image</Prefix>
<Text>Confirm?</Text>
</Title>
</TitleBar>
<Position Width="120" Height="73">
<IsAbsolute>true</IsAbsolute>
</Position>
<DialogTmpl/>
<Controls>
<Control xsi:type="ButtonControl" Id="BtnOk">
<Position Left="2" Top="0" Width="40">
<Units>AllPixels</Units>
</Position>
<StandardLook Template="Blue"/>
<Caption>Ok</Caption>
</Control>
<Control xsi:type="ButtonControl" Id="BtnCancel">
<Position Left="44" Top="0" Width="60">
<Units>AllPixels</Units>
</Position>
<Caption>Cancel</Caption>
</Control>
</Controls>
</Window>
</Interfaces>
Modal Test.js
Spoiler:
js code:
// make the parent window, make a variable for the child window
var WndParent = MsgPlus.CreateWnd("Interface.xml", "WndParent");
var WndChild = null;
// use any event here, this is just an example
function OnWndParentEvent_CtrlClicked(PlusWnd, ControlId)
{
if (ControlId === "BtnConfirm")
{
// create the child, disable and monitor the parent
WndChild = MsgPlus.CreateWnd("Interface.xml", "WndChild");
Interop.Call("user32", "EnableWindow", WndParent.Handle, false);
WndParent.RegisterMessageNotification(0x0006);
}
}
// when the parent window is focused
function OnWndParentEvent_MessageNotification(PlusWnd, Message, wParam, lParam)
{
if (wParam !== 0)
{
try
{
// focus the child window
Interop.Call("user32", "SetFocus", WndChild.Handle);
Interop.Call("user32", "BringWindowToTop", WndChild.Handle);
}
catch (error)
{
}
}
}
function OnWndChildEvent_CtrlClicked(PlusWnd, ControlId)
{
switch (ControlId)
{
case "BtnOk":
// do whatever here, then close the child
PlusWnd.Close(1);
break;
}
}
function OnWndChildEvent_Destroyed(PlusWnd, ExitCode)
{
// enable and focus the parent window
Interop.Call("user32", "EnableWindow", WndParent.Handle, true);
Interop.Call("user32", "SetFocus", WndParent.Handle);
}