Actually, SetWindowPos is the right function for this. I've had many trouble before using MoveWindow, and SetWindowPos was always the answer.
Anyway, I've done this in my
Countdown Live script in the same way as SmokingCookie said. Here's how:
- Place the RetrievePos function of SmokingCookie somewhere in your script.
- 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);
- 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!
Finally, I managed to beat someone instead of being beaten!