Shoutbox

[?] Creating menu's - 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: [?] Creating menu's (/showthread.php?tid=73591)

[?] Creating menu's by Matti on 04-14-2007 at 08:49 AM

Right...

So, I was working on another script which I want to be translatable. A lot of scripts use XML rewriting for that, but I think that method is getting overused, while the Win32 API has great functions to do that. So far, I managed to create tooltips using the _ToolTip class (thanks Eljay!!) but now I'm trying to develop an alternative for MenuButtonControls. I was thinking of a child window in the parent window which would be made visible by clicking on a button and be hidden by clicking somewhere else. But there seem to be a catch...

I first create the window with MsgPlus.CreateWnd and open it unactivated using a flag. Then, I set the parent of that child window to the main window. After that, I position the window so it's placed just beneath the button. And then, for testing purpose, I make it visible. But, the child window gets partially hidden by the underlaying window controls: the child is not on the top Z-index in the window. A screenshot to clarify:
[Image: attachment.php?pid=808469]

Now my question is: how can I set the child window to be on top of the other window controls? SetForegroundWindow and BringWindowToTop fail to do this... I understand that this is a very tricky method I'm trying, but if you could possibly help me, please do so! :)


RE: [?] Creating menu's by vikke on 04-14-2007 at 09:21 AM

I don't know if it'll work, but you should be able to try "Always on top".

code:
// Declares Put this on top of code
var HWND_TOPMOST = -1;
var SWP_NOMOVE = &H2; // No idea if those will work.
var SWP_NOSIZE = &H1;

// Function Note: Handle is HWND (window handle)
function AlwaysOnTop (Handle)
{
      // Also try HWND_TOP
      Interop.Call("user32.dll", "SetWindowPos", Handle, HWND_TOPMOST, 0, 0, 0, SWP_NOMOVE || SWP_NOSIZE);
}


RE: [?] Creating menu's by Matti on 04-14-2007 at 09:32 AM

The topmost flag doesn't seem to be accepted for child windows. I'll keep it on HWND_TOP (0x0).

The weird thing is that it's actually on top of the controls, only it doesn't get drawn on top. To prove this: when I mouse-over the Preferences button where it should be behind the window, it doesn't light up. I have to move the mouse out of the menu area to make it light up. :S

Maybe I should try to set the Z-order of the 2 buttons... but how?!


RE: [?] Creating menu's by vikke on 04-14-2007 at 09:42 AM

But the menu is not a child of the window right?
There should not be any problem.

How does your bottom bar XML code look like?


RE: [?] Creating menu's by Matti on 04-14-2007 at 09:47 AM

code:
      <DialogTmpl>
         <BottomBar Style="Plain">
            <LeftControls>
               <Control xsi:type="ButtonControl" Id="BtnPref">
                  <Position Left="0" Top="0" Width="80"></Position>
                  <Image Margin="5"><Name>panel-scripts</Name></Image>
                  <Caption>&amp;Preferences</Caption>
               </Control>
               <Control xsi:type="ButtonControl" Id="BtnHelp">
                  <Position Left="0" Top="0" Width="20"></Position>
                  <Image><Name>info-small</Name></Image>
                  <Caption/>
               </Control>
            </LeftControls>
            <RightControls>
               <Control xsi:type="ButtonControl" Id="BtnCancel">
                  <Position Left="0" Top="0" Width="60"></Position>
                  <Image Margin="5"><Name>sounds-delete2</Name></Image>
                  <Caption>&amp;Close</Caption>
               </Control>
            </RightControls>
         </BottomBar>
      </DialogTmpl>

You think that's it's because the bottom bar is always on top? Sounds likely, but how should I fix that? :S And how did Plus! get her (*) menu's on top then? Or maybe... those aren't child windows? :O

It seems like I'm having more luck with making it a stand-alone window. I'll now try to make it destroy when it gets deactivated.
RE: [?] Creating menu's by vikke on 04-14-2007 at 09:56 AM

This won't not help but I would use:

code:
<Position Left="0" Top="0" Width="60" />
instead of:
code:
<Position Left="0" Top="0" Width="60"></Position>

But if you have a look at the screenshot, the bottombar is under the menu, but the buttons is not, so it's something with the buttons. I think this is a bug. :(
RE: [?] Creating menu's by Matti on 04-14-2007 at 10:07 AM

That was because there was an <Anchor> element there once... I simply didn't noticed.

I now need to find a message which is been send to the window when it loses its activated state... any ideas?


Gotcha! WM_ACTIVATE saved me! :D I'll now work this thing out...

I'm happy to tell you all that I've managed to do it. The menu gets created when the window loads, hides and will be shown when the button is clicked. Then, the position is re-calculated and the menu pops up. When the menu is deactivated, it hides again.

Now, one last thing: can someone tell me if there's a function which calculates the bounding box of a text in a specified font, like PHP's imagettfbbox(). I'd like to use this to resize the menu to fit the messages inside.
RE: [?] Creating menu's by matty on 04-14-2007 at 02:57 PM

Take a look at this.

_tray_icon_0.3.plsc
It shows you how to create a menu at runtime (allowing you to change the text as needed) and create a tray icon, not really needed for you but the first part is.


RE: [?] Creating menu's by Matti on 04-15-2007 at 09:26 AM

Matty, you rock! (H)
I've analyzed your code, took the parts I needed and BANG! It works like a charm! :D

I can't thank you enough! Now, we don't have to use MenuButtonControls anymore! :D


RE: RE: [?] Creating menu's by deAd on 04-15-2007 at 02:48 PM

quote:
Originally posted by Mattike
Now, we don't have to use MenuButtonControls anymore! :D

Why don't you want to use MenuButtonControls :P?
RE: [?] Creating menu's by Matti on 04-15-2007 at 05:08 PM

quote:
Originally posted by deAd
Why don't you want to use MenuButtonControls :P?
Because you cannot translate the <Menu> XML elements in runtime, and because I want to use easier alternatives for XML rewriting like other scripts do (including mine). ;)