What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » HELP - Resizing a child window!

Pages: (2): « First [ 1 ] 2 » Last »
HELP - Resizing a child window!
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. HELP - Resizing a child window!
This is basically a script which gives you a "command bar" (sort of like a floating deskbar), with various commands.

xml code:
<!-- the parent window -->

<Window Id="WndCommandBar_Shell" Version="1">

    <Attributes>
        <Caption>Command Bar</Caption>
        <TopMost>true</TopMost>
        <ShowInTaskbar>false</ShowInTaskbar>
    </Attributes>
   
    <TitleBar>
        <AllowMinimize>false</AllowMinimize>
        <AllowClose>false</AllowClose>
    </TitleBar>
   
    <Position Width="188" Height="28">
        <IsAbsolute>true</IsAbsolute>
        <Resizeable Allowed="BothSides">
            <MinWidth>150</MinWidth>
            <MinHeight>28</MinHeight>
        </Resizeable>
    </Position>
   
    <WindowTmpl>
        <Borders Type="Simple"/>
    </WindowTmpl>

</Window>
xml code:
<!-- the child window -->

<Window Id="WndCommandBar_CMain" Version="1">

    <Position Width="188" Height="28">
        <IsAbsolute>true</IsAbsolute>
        <Resizeable Allowed="BothSides">
            <MinWidth>150</MinWidth>
            <MinHeight>28</MinHeight>
        </Resizeable>
    </Position>
   
    <ChildTmpl/>
   
    <Controls>
        <Control xsi:type="ButtonControl" Id="BtnCommands">
            <Position Left="10" Top="0" Width="24">
                <Units>AllPixels</Units>
                <Anchor Vertical="TopBottomFixed"/>
            </Position>
            <Image><Name>Options</Name></Image>
            <Help>Some useful preset commands.</Help>
            <StandardLook Template="Clear"/>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnContacts">
            <Position Left="35" Top="0" Width="24">
                <Units>AllPixels</Units>
                <Anchor Vertical="TopBottomFixed"/>
            </Position>
            <Image><Name>Contacts</Name></Image>
            <Help>Your Messenger contacts.</Help>
            <StandardLook Template="Clear"/>
        </Control>
        <Control xsi:type="EditControl" Id="EdtCmd">
            <Position Left="60" Top="0" Width="99" Height="24">
                <Units>AllPixels</Units>
                <Anchor Horizontal="LeftRightFixed" Vertical="TopBottomFixed"/>
            </Position>
            <Help>Type a command here...</Help>
        </Control>
        <Control xsi:type="ButtonControl" Id="BtnOk">
            <Position Left="160" Top="0" Width="24">
                <Units>AllPixels</Units>
                <Anchor Horizontal="RightFixed" Vertical="TopBottomFixed"/>
            </Position>
            <Attributes>
                <IsDefault>true</IsDefault>
            </Attributes>
            <Image><Name>Tick</Name></Image>
            <Help>Click to process the command, or press Enter.</Help>
            <StandardLook Template="Clear"/>
        </Control>
    </Controls>

</Window>
And that builds it fine, but I want to make it resizable, and when it is resized, only the parent changes.  How do I go about making the child resize with the parent?
09-12-2009 01:28 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: HELP - Resizing a child window!
You need to specify a PlaceHolderElement at the size and position of the child window. Then hook WM_SIZE into your parent window and use PlusWnd::GetElementPos() to retrieve the relative coordinates, which you need to pass to SetWindowPos() in User32.dll.

This post was edited on 09-12-2009 at 02:26 PM by SmokingCookie.
09-12-2009 02:24 PM
Profile PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: HELP - Resizing a child window!
quote:
Originally posted by SmokingCookie
You need to specify a PlaceHolderElement at the size and position of the child window.
Okay, done that.

quote:
Originally posted by SmokingCookie
Then hook WM_SIZE into your parent window and use PlusWnd::GetElementPos() to retrieve the relative coordinates, which you need to pass to SetWindowPos() in User32.dll.
I don't know where to start for doing that...  something like this?
js code:
var WndCommandBar_Shell = MsgPlus.CreateWnd("Windows.xml", "WndCommandBar_Shell", 0); // parent
var WndCommandBar_CMain = MsgPlus.CreateChildWnd(WndCommandBar_Shell, "Windows.xml", "WndCommandBar_CMain", 12, 2); // child
Interop.Call("User32", "SetWindowPos", WndCommandBar_Shell.Handle, WndCommandBar_Shell.GetElementPos());
09-12-2009 02:35 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: HELP - Resizing a child window!
First, I was wrong about SetWindowPos();. My apologies. You actually need to use MoveWindow();

Second, you've probably got the first part correct, but the second is kinda.. ya know.. :P

As the scripting docs say, you need to pass the element ID to PlusWnd::GetElementPos(). (It's actually PlusWnd.GetElementPos(ElementID,Type)). So this is what you'll need to do with your PlusWnd:

JScript code:
function RetrievePos(PlusWnd,ElementID) {
    var PosInfo = new Object();
    PosInfo.X = PlusWnd.GetElementPos(ElementID,POSINFO_X /* Predefined within MPL itself */);
    PosInfo.Y = PlusWnd.GetElementPos(ElementID,POSINFO_Y);
    PosInfo.Width = PlusWnd.GetElementPos(ElementID,POSINFO_WIDTH);
    PosInfo.Height = PlusWnd.GetElementPos(ElementID,POSINFO_HEIGHT);
    return PosInfo;
}

Call this function with the parent window object (WndCommandBar_Shell) and the element ID specified in your interface XML.

For MoveWindow(), you need to pass the handle to your child window (WndCommandBar_CMain), its coordinates and size (the information stored in the object returned by my RetrievePos() function) and whether it should be redrawn or not. So it's MoveWindow(hWnd,x,y,width,height,redraw);. Once again, this function is located in User32.dll.

BTW, I recommend redrawing the window through MoveWindow();

This post was edited on 09-12-2009 at 02:54 PM by SmokingCookie.
09-12-2009 02:49 PM
Profile PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: HELP - Resizing a child window!
js code:
var WndCommandBar_Shell = MsgPlus.CreateWnd("Windows.xml", "WndCommandBar_Shell", 0);
var WndCommandBar_CMain = MsgPlus.CreateChildWnd(WndCommandBar_Shell, "Windows.xml", "WndCommandBar_CMain", 12, 2);
var PosInfo = RetrievePos(WndCommandBar_Shell, "PlhChild");
Interop.Call("User32", "MoveWindow", WndCommandBar_CMain.Handle, PosInfo.X, PosInfo.Y, PosInfo.Width, PosInfo.Height, true);
Seems to get stuck (Messenger doesn't crash, but the debug doesn't get any further than "Script is starting", and the window appears and then disappears again).
09-12-2009 03:09 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: HELP - Resizing a child window!
Actually, SetWindowPos is the right function for this. I've had many trouble before using MoveWindow, and SetWindowPos was always the answer. :P

Anyway, I've done this in my Countdown Live script in the same way as SmokingCookie said. Here's how:
  1. Place the RetrievePos function of SmokingCookie somewhere in your script.
  2. Create your window and child window as you normally would. After creation, register WM_SIZE on your parent.
    js code:
    WndCommandBar_Shell.RegisterMessageNotification(/* WM_SIZE */ 0x5, true);
  3. Create a handler for the message notification event. Check the Message parameter and when you got WM_SIZE, you can resize the child window like so:
    js code:
    // Get the place-holder's position
    var posChild = RetrievePos(WndCommandBar_Shell, "PlhChild");
    // SetWindowPos flags
    var flagsSWP = /* SWP_NOACTIVATE */ 0x10 | /* SWP_NOMOVE */ 0x2;
    // Position the child
    Interop.Call("user32", "SetWindowPos", WndCommandBar_CMain.Handle, 0, 0, 0, posChild.Width, posChild.Height, flagsSWP);
    // Done!
I assume that on creation, the child window's size matches that of the place-holder. If not, execute the code provided for the message notification event also just after registering the notification.

On a side note, here's a nifty trick: when you need to get the new size of the window inside the WM_SIZE handler, you can do this without having to call GetWindowRect! The lParam contains the width in the low-order word and the height in the high-order word, so all you have to do is:
js code:
var wWidth = lParam & 0xFFFF; //Get low-order word
var wHeight = (lParam >> 16); //Get high-order word
And tadaa, you saved yourself another call to the Win32 API! :D

Finally, I managed to beat someone instead of being beaten! :P

This post was edited on 09-12-2009 at 03:35 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-12-2009 03:32 PM
Profile E-Mail PM Web Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: HELP - Resizing a child window!
From line 3: you mustn't move the window by that time already. You need to register WM_SIZE into your parent window (PlusWnd::RegisterMessageNotification()). When WM_SIZE is received (OnWindowIdEvent_MessageNotification()), you need to move it.

* Angry at Matti for being quicker ^o) :P

But I do not see why MoveWindow(); shouldn't work..?

This post was edited on 09-12-2009 at 03:36 PM by SmokingCookie.
09-12-2009 03:33 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: HELP - Resizing a child window!
quote:
Originally posted by SmokingCookie
But I do not see why MoveWindow(); shouldn't work..?
I've tried many times before, but it simply fails to work. Either it throws an unknown exception in the script debugger, or it just doesn't do anything. Feel free to try MoveWindow, but I'm sticking to SetWindowPos. :P

This post was edited on 09-12-2009 at 03:42 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-12-2009 03:42 PM
Profile E-Mail PM Web Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
RE: HELP - Resizing a child window!
It works perfectly fine in my scripts.
09-12-2009 03:46 PM
Profile PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: HELP - Resizing a child window!
quote:
Originally posted by Matti
  1. Place the RetrievePos function of SmokingCookie somewhere in your script.
  2. Create your window and child window as you normally would. After creation, register WM_SIZE on your parent.
    js code:
    WndCommandBar_Shell.RegisterMessageNotification(/* WM_SIZE */ 0x5, true);
  3. Create a handler for the message notification event. Check the Message parameter and when you got WM_SIZE, you can resize the child window like so:
    js code:
    // Get the place-holder's position
    var posChild = RetrievePos(WndCommandBar_Shell, "PlhChild");
    // SetWindowPos flags
    var flagsSWP = /* SWP_NOACTIVATE */ 0x10 | /* SWP_NOMOVE */ 0x2;
    // Position the child
    Interop.Call("user32", "SetWindowPos", WndCommandBar_CMain.Handle, 0, 0, 0, posChild.Width, posChild.Height, flagsSWP);
    // Done!

I've done all that, and the parent/child windows are loaded, but as soon as I resize the window, the child disappears.  It leaves just an empty parent window...
09-13-2009 09:59 AM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


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