Shoutbox

HELP - Child Windows! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - Child Windows! (/showthread.php?tid=89343)

HELP - Child Windows! by whiz on 02-22-2009 at 04:50 PM

Whenever I make a child window, like these:

Javascript code:
MsgPlus.CreateChildWnd("WndBrowser", "Windows.xml", "WndSearch", "100", "100", true);
MsgPlus.CreateChildWnd("WndBrowser", "Windows.xml", "WndSearch", 100, 100, true);
MsgPlus.CreateChildWnd("WndBrowser", "Windows.xml", "WndSearch", "100", "100");
MsgPlus.CreateChildWnd("WndBrowser", "Windows.xml", "WndSearch", 100, 100);


I get an error in the Script Debugger, saying "type mismatch".  How come?
RE: HELP - Child Windows! by Matti on 02-22-2009 at 05:21 PM

quote:
Originally posted by whiz
How come?
You are passing a string "WndBrowser" as first parameter, where the script documentation clearly says:
quote:
Parent: [object] Existing PlusWnd object previously created with CreateWnd.
So, a valid example would be:
Javascript code:
//The parent window
var pBrowser = MsgPlus.CreateWnd("Windows.xml", "WndBrowser");
//The child window
var pSearch = MsgPlus.CreateChildWnd(pBrowser, "Windows.xml", "WndSearch", 100, 100);

As you can see, we're passing pBrowser (the created PlusWnd object) as first parameter. The reason why Plus! works this way is since you could make multiple instances of the same interface XML definition.
RE: HELP - Child Windows! by whiz on 02-23-2009 at 07:27 PM

So I have to store the parent window into a variable?


RE: HELP - Child Windows! by matty on 02-23-2009 at 07:28 PM

Yes that is what he said...


RE: HELP - Child Windows! by whiz on 02-23-2009 at 07:46 PM

Well, it still doesn't appear to be working.  Am I still missing something?

Javascript code:
// if a menu item is clicked
function OnEvent_MenuClicked(sMenuId, nLocation, iOriginWnd)
{
    if(sMenuId == "start")
    {
        if (OpenWnd)  // checks for another instance of the browser
        {
            Debug.Trace("> Detected OpenWnd: " + OpenWnd)
            Debug.Trace("> No more windows allowed!")
            MsgPlus.CreateWnd("Windows.xml", "WndMaximum", 0)
            // creates a warning alert window
        }
        else
        {
            Debug.Trace("> Detected OpenWnd: " + OpenWnd);
            Debug.Trace("> Window allowed!");
            Wnd = MsgPlus.CreateWnd("Windows.xml", "WndBrowser", 0);
            // creates a browser window (variable 'Wnd')
            OpenWnd = true;
            Browser = Wnd.Browser_GetInterface("Browser");
            Browser.GoHome();
        }
    }

Javascript code:
// if a browser button is clicked
function OnWndBrowserEvent_CtrlClicked(objWnd, strControlId)
{
    switch(strControlId)
    {
        case "BtnSearch":  // if the search button is clicked
            SearchWnd = MsgPlus.CreateChildWnd(Wnd, "Windows.xml", "WndSearch", 100, 100);
            // creates a child window (parent = 'Wnd')
            break;
    }
}

I have also tried putting your code in, exactly how it was, but only the main window appeared - the child window just didn't appear...
RE: HELP - Child Windows! by matty on 02-23-2009 at 07:56 PM

Is your variable Wnd globally defined?

And why not do this...

Javascript code:
// if a browser button is clicked
function OnWndBrowserEvent_CtrlClicked(objWnd, strControlId)
{
    switch(strControlId)
    {
        case "BtnSearch":  // if the search button is clicked
            SearchWnd = MsgPlus.CreateChildWnd(objWnd, "Windows.xml", "WndSearch", 100, 100);            // creates a child window (parent = 'Wnd')
            break;
    }
}


RE: RE: HELP - Child Windows! by whiz on 02-23-2009 at 08:04 PM

quote:
Originally posted by matty
Is your variable Wnd globally defined?
It is, but I have tried it without, and it still won't do anything.

quote:
Originally posted by matty
And why not do this...
Javascript code:
// if a browser button is clicked
function OnWndBrowserEvent_CtrlClicked(objWnd, strControlId)
{
    switch(strControlId)
    {
        case "BtnSearch":  // if the search button is clicked
            SearchWnd = MsgPlus.CreateChildWnd(objWnd, "Windows.xml", "WndSearch", 100, 100);            // creates a child window (parent = 'Wnd')
            break;
    }
}


Doesn't make any difference...  :S
RE: HELP - Child Windows! by matty on 02-23-2009 at 08:08 PM

Post the XML of your window.

matty's reply to Cannot CreateChildWnd

XML code:
<!-- The child window -->
    <Window Id="WndChildExample" Version="1">
        <ChildTmpl/>
        <Position Width="243" Height="193"/>
        <Controls>
            <Control xsi:type="StaticControl" Id="lblTitle">
                <Position Top="25" Width="100" Left="15" Height="15" />
                <Caption>hi I am a child window :)</Caption>
            </Control>
        </Controls>
    </Window>


RE: HELP - Child Windows! by whiz on 02-23-2009 at 08:21 PM

XML code:
<!-- Browser Window -->
<Window Id="WndBrowser" Version="1">
    <Attributes>
        <Caption>Plus! Browser</Caption>
    </Attributes>
    <TitleBar>
        <AllowMaximize>true</AllowMaximize>
        <Title>
            <Prefix>Image</Prefix>
            <Text>Plus! Browser</Text>
        </Title>
    </TitleBar>
    <Position Width="500" Height="400">
        <IsAbsolute>true</IsAbsolute>
        <Resizeable Allowed="BothSides">
            <MinWidth>500</MinWidth>
            <MinHeight>400</MinHeight>
        </Resizeable>
    </Position>
    <DialogTmpl>
    </DialogTmpl>
    <Controls>
        <Control xsi:type="ButtonControl" Id="BtnBack">
            <Position Left="5" Top="1" Width="15"/>
            <Image><Name>Back</Name></Image>
            <Help>Back</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnForward">
            <Position Left="20" Top="1" Width="15"/>
            <Image><Name>Forward</Name></Image>
            <Help>Forward</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnStop">
            <Position Left="35" Top="1" Width="15"/>
            <Image><Name>Cross</Name></Image>
            <Help>Stop</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnRefresh">
            <Position Left="50" Top="1" Width="15"/>
            <Image><Name>Refresh</Name></Image>
            <Help>Refresh</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnHome">
            <Position Left="65" Top="1" Width="15"/>
            <Caption>H</Caption>
            <Help>Home</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnSearch">
            <Position Left="80" Top="1" Width="15"/>
            <Image><Name>Find</Name></Image>
            <Help>Search</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnGo">
            <Position Left="102" Top="1" Width="30"/>
            <Caption>&amp;Go to:</Caption>
        </Control>
        <Control xsi:type="EditControl" Id="EdtAddress">
            <Position Left="199" Top="3" Width="281">
                <Anchor Horizontal="LeftRightFixed"/>
                <Units>AllPixels</Units>
            </Position>
            <Attributes><IsDefault>true</IsDefault></Attributes>
            <Help>Enter a web address or file path...</Help>
        </Control>
        <Control xsi:type="StaticControl" Id="TxtCurrentPage">
            <Transparency>100</Transparency>
            <Position Left="8" Top="30" Width="470">
                <Anchor Horizontal="LeftRightFixed"/>
                <Units>AllPixels</Units>
            </Position>
            <Caption>Current address:</Caption>
        </Control>
        <Control xsi:type="BrowserControl" Id="Browser">
            <Position Left="8" Top="55" Width="470" Height="290">
                <Anchor Horizontal="LeftRightFixed" Vertical="TopBottomFixed"/>
                <Units>AllPixels</Units>
            </Position>
        </Control>
    </Controls>
</Window>
 
<!-- Search Popup -->
<Window Id="WndSearch" Version="1">
    <ChildTmpl/>
    <Attributes>
        <Caption>Plus! Browser: Search...</Caption>
    </Attributes>
    <TitleBar>
        <AllowMinimize>false</AllowMinimize>
        <Title>
            <Prefix>Image</Prefix>
            <Text>Plus! Browser: Search...</Text>
        </Title>
    </TitleBar>
    <Position Width="400" Height="150">
        <IsAbsolute>true</IsAbsolute>
    </Position>
    <DialogTmpl>
        <BottomBar Style="Plain">
            <RightControls>
                <Control xsi:type="ButtonControl" Id="BtnSearchGoogle">
                    <Position Left="292" Top="2" Width="55"/>
                    <Image><Name>Find</Name></Image>
                    <Caption>&amp;Google</Caption>
                </Control>
                <Control xsi:type="ButtonControl" Id="BtnSearchYahoo">
                    <Position Left="292" Top="2" Width="55"/>
                    <Image><Name>Find</Name></Image>
                    <Caption>&amp;Yahoo</Caption>
                </Control>
                <Control xsi:type="ButtonControl" Id="BtnCancel">
                    <Position Left="292" Top="2" Width="55"/>
                    <Image> <Name>Cross</Name></Image>
                    <Caption>&amp;Cancel</Caption>
                </Control>
            </RightControls>
        </BottomBar>
    </DialogTmpl>
    <Controls>
        <Control xsi:type="StaticControl" Id="InfoTxt">
            <Position Left="8" Top="3" Width="370">
                <Anchor Horizontal="LeftRightFixed"/>
                <Units>AllPixels</Units>
            </Position>
            <Attributes>
                <IsDefault>true</IsDefault>
            </Attributes>
            <Caption>Enter the text to search for, and click Search to open a results window.</Caption>
        </Control>
        <Control xsi:type="EditControl" Id="EdtSearch">
            <Position Left="8" Top="23" Width="370">
                <Anchor Horizontal="LeftRightFixed"/>
                <Units>AllPixels</Units>
            </Position>
            <Attributes>
                <IsDefault>true</IsDefault>
            </Attributes>
            <Help>Enter a search query...</Help>
        </Control>
    </Controls>
</Window>


RE: HELP - Child Windows! by matty on 02-23-2009 at 08:29 PM

Your XML is invalid for your child window. You cannot have a <ChildTmpl /> and a <DialogTmpl /> at the same time as they signify different appearences for the windows.


RE: HELP - Child Windows! by whiz on 02-23-2009 at 08:33 PM

So can I put the <BottomBar> section into the <ChildTmpl/>, or can I not have a bottom bar at all?


RE: HELP - Child Windows! by matty on 02-23-2009 at 08:52 PM

You can't have it at all.

I really strongly recommend you read about it in the documentation... Only the DialogTmpl and WindowTmpl can have attributes to them.


RE: HELP - Child Windows! by Matti on 02-24-2009 at 08:45 AM

Also, you can't have an Attributes nor TitleBar block for a child window. Directly quoted from the documentation (see Window/ChildTmpl):

quote:
annotation: A window with this template must not have Attributes or TitleBar. It is only meant to be included in other windows.

Another remark: you're defining the width and height of the window as absolute values (in pixels) using IsAbsolute, however you don't use Control::Position::Units to make the controls use pixels. This causes them to work with dialog units which are about 1.5 pixels, making your controls much wider/higher and positioned too low/far than you want. As always: all these things are clearly mentioned in the documentation.
RE: HELP - Child Windows! by whiz on 02-24-2009 at 08:09 PM

It still won't work!

  • no <DialogTmpl>, just a <ChildTmpl/>
  • tried taking out all the pieces (controls, title etc) one by one
  • tried taking them all out
I know the XML is fine, and in the right format, because the other windows load up normally.  :@

RE: HELP - Child Windows! by Matti on 02-24-2009 at 08:11 PM

And how exactly do you want us to see what's wrong when you don't post your current interfaces code? :P


RE: HELP - Child Windows! by whiz on 02-24-2009 at 08:18 PM

Okay, don't worry about the child window, I give up...

I'll try something else.  If the Search window is already open, and the user clicks the button again, is it possible to bring the Search window to the front?


RE: HELP - Child Windows! by matty on 02-24-2009 at 08:31 PM

Post the code we will show you where you went wrong.

To answer your question:

Store the window handle in a variable and when clicking the button use the IsWindow API to check if it returns true; if it does use the SetForegroundWindow API to bring it forward if not open it.


RE: HELP - Child Windows! by whiz on 02-24-2009 at 08:41 PM

I know it doesn't have any buttons, but this is what I have tried:

XML code:
<Window Id="WndSearch" Version="1">
    <Position Width="400" Height="150"/>
    <ChildTmpl>
    <Controls>
        <Control xsi:type="StaticControl" Id="InfoTxt">
            <Position Left="8" Top="3" Width="370"/>
            <Caption>Enter the text to search for, and click Search to open a results window.</Caption>
        </Control>
        <Control xsi:type="EditControl" Id="EdtSearch">
            <Position Left="8" Top="23" Width="370"/>
            <Help>Enter a search query...</Help>
        </Control>
    </Controls>
</Window>

I have also tried using the exact window mentioned above:
XML code:
<Window Id="WndChildExample" Version="1">
   <ChildTmpl/>
   <Position Width="243" Height="193"/>
   <Controls>
      <Control xsi:type="StaticControl" Id="lblTitle">
         <Position Top="25" Width="100" Left="15" Height="15" />
         <Caption>hi I am a child window :)</Caption>
      </Control>
   </Controls>
</Window>


RE: HELP - Child Windows! by matty on 02-24-2009 at 09:00 PM

Nothing is wrong with the code for the window. What about the full script you use to create the window. Better yet post the PLSC.


RE: HELP - Child Windows! by whiz on 02-25-2009 at 05:15 PM

Attached.


RE: RE: HELP - Child Windows! by pollolibredegrasa on 02-25-2009 at 05:48 PM

XML code:
<Window Id="WndSearch" Version="1">
    <Position Width="400" Height="150"/>
    <ChildTmpl>


This is just after your commented out original search window. You don't close <ChildTmpl>. After changing this to <ChildTmpl/> the script works for me.

Just out of curiosity, are you sure you want a child window and not a modal one? A child window gets placed on the parent form, whereas a modal window is a seperate window that has to be closed before you can do anything further on the parent window. The way your code and xml currently works (as a child window) is that the search textbox & label get hidden behind the browser object and are thus inaccessible (see attached pic) :P
RE: HELP - Child Windows! by whiz on 02-25-2009 at 06:51 PM

Umm...  in that case, I would probably want a modal window, but I have no idea how to do that.  :S

I thought a modal window was a child window...  I'm confused now.  :P


RE: HELP - Child Windows! by matty on 02-25-2009 at 08:11 PM

A child window is a seperate window like in the Plus! Preferences. The section that changes when you click a different tab... is a child window. A modal window is a seperate window. Instead why not make it like IE and FF and have the search box beside the address bar?


RE: HELP - Child Windows! by whiz on 02-25-2009 at 08:30 PM

Well, I was actually thinking of having it like a chat window, in the sense that you could type something like "!search <google/yahoo/etc> <query>".  This could then be used for other purposes, like "!send <contact email>", to send the current page address to a Messenger contact.  I'll give it a go...