What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Tips

Tips
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: Tips
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>&amp;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>&amp;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);
}

.plsc File Attachment: Modal Test.plsc (2.12 KB)
This file has been downloaded 307 time(s).

This post was edited on 06-24-2010 at 10:56 AM by whiz.
06-24-2010 10:53 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Tips - by surfichris on 03-13-2006 at 12:06 PM
RE: Tips - by -dt- on 03-13-2006 at 12:11 PM
RE: Tips - by segosa on 03-13-2006 at 12:39 PM
RE: Tips - by surfichris on 03-13-2006 at 01:13 PM
RE: Tips - by Volv on 04-19-2006 at 06:29 AM
RE: Tips - by -dt- on 04-19-2006 at 06:57 AM
RE: Tips - by davidt on 08-15-2006 at 09:21 AM
RE: RE: Tips - by CookieRevised on 10-21-2006 at 01:44 AM
RE: Tips - by Plan-1130 on 10-25-2006 at 08:15 PM
RE: Tips - by matty on 10-25-2006 at 08:21 PM
RE: Tips - by tryxter on 01-08-2007 at 06:46 PM
RE: Tips - by CookieRevised on 01-28-2007 at 01:15 AM
RE: Tips - by Matti on 06-02-2007 at 05:02 PM
RE: Tips - by Matti on 06-07-2007 at 05:38 PM
RE: Tips - by henry1817 on 12-30-2009 at 04:13 PM
RE: Tips - by matty on 12-30-2009 at 04:20 PM
RE: Tips - by whiz on 06-24-2010 at 10:53 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On