Page 1 of 1 1
Topic Options
#190013 - 2008-10-03 05:09 PM Dynamic Wrapper Tutorial - Lesson 2
Arend_ Moderator Offline
MM club member

Registered: 2005-01-17
Posts: 1889
Loc: Hilversum, The Netherlands
Dynamic Wrapper Tutorial - Lesson 2

In the first lesson we've learned how to use the Dynamic Wrapper (DynaWrap) to find
the window that we are looking for. Now that we have found the Window and the corresponding
Handle. We have to do something with it and thats exactly what we are going to do.
Let's recap for a minute and see our previous code.
Dim $objDynaWrap, $lhWnd
$objDynaWrap = CreateObject("DynamicWrapper")
$=objDynaWrap.Register("USER32.DLL", "FindWindow", "i=ss", "f=s", "r=l")
$lhWnd = $objDynaWrap.FindWindow("Shell_TrayWnd", "")
? $lhWnd

This shows us the numeric handle.
In order to do something with the handle we have to send it a message.
So "SendMessage" would be the most obvious, let's use that ;\)
As Microsoft Dictates, SendMessage requires 4 parameters, in order: (int) hWnd, (int) msg, (int) wParam and (str) lParam.

(int) hWnd
We have learned before what hWnd is and that we got that by using FindWindow.
So we are set to use that.

(int) msg
The second is "msg" this is what we want the Tray to do.
This is the difficult part. We want it to show the QuickLaunch. As with Handles these are
mostly predefined parameters. But this one is a bit different. The QuickLaunch is enabled per
user and not per system, so we have to know the User parameter which his 400 in Hex, and 1024 in Binary.
Again Microsoft does a very good job explaining this.
However that's only the WM_User, we have to add the value for the Tray, unfortunately MS doesn't
do a very good job at explaining that so you will have to take my word for it when I say the Tray
is 237 (0xED). Now add that to the 1024 we had before from WM_User and the Tray+User=1261

(int) wParam
This basically tells SendMessage how to handle the parameters.
we provide -1 here because we can't do much else, KiX doesn't support return values so this
will suffice. -1 basically tells the Interpreter that we don't tell it how to handle the
provided parameters.

(str) lParam
Now this is the confusing part. Microsoft tells us that SendMessage needs a string value as
the provided lParam. I kept this error a secret so you would pay attention (I believe this is an
error) if you look at SendMessageEX (which we are not using) you see that lParam is
Integer. And I believe that SendMessage also needs an Integer in there.
This parameter will tell SendMessage to tell the Tray what to do with the handle.
In our case tell it to Turn QuickLaunch on or off. 1 being on and 0 being off (see that the string
value doesn't apply here?).

So now that we know this the following code can be added.
$=$objDynaWrap.Register("USER32.DLL", "SendMessage", "i=hlll", "f=s", "r=l")

As explained before I contains the 4 parameters. hlll
H being Handle, and L being long (as it's prefered above int).
F and R are explained in the previous lesson and remain the same.

So now we only have to "Do" it. The end code will look like this.
Dim $objDynaWrap, $lhWnd
$objDynaWrap = CreateObject("DynamicWrapper")
$=objDynaWrap.Register("USER32.DLL", "FindWindow", "i=ss", "f=s", "r=l")
$=$objDynaWrap.Register("USER32.DLL", "SendMessage", "i=hlll", "f=s", "r=l")
$lhWnd = $objDynaWrap.FindWindow("Shell_TrayWnd", "")
$=objDynaWrap.SendMessage($lhWnd, $WMTRAY_TOGGLEQL, -1, 1)

And this will turn your Quick Launch bar on.
Change this at the end 1 to 0
$=objDynaWrap.SendMessage($lhWnd, $WMTRAY_TOGGLEQL, -1, 0)

To turn it off again.

In the end you could have this function to do the work for you:
Function ToggleQL($switch)
  Dim $WM_USER, $WMTRAY_TOGGLEQL, $objDynaWrap, $lhWnd
  $WM_USER = &400
  $objDynaWrap = CreateObject("DynamicWrapper")
  $=$objDynaWrap.Register("USER32.DLL", "FindWindowA", "i=ss", "f=s", "r=l")
  $=$objDynaWrap.Register("USER32.DLL", "SendMessage", "i=hlll", "f=s", "r=l")
  $lhWnd = $objDynaWrap.FindWindowA("Shell_TrayWnd", "")
  $=$objDynaWrap.SendMessage($lhWnd, $WMTRAY_TOGGLEQL, -1, $switch)

Now use "ToggleQL(1)" for turning on and "ToggleQL(0)" for turning off.
Thats all for now, hope you've learned from it. We now continue with our regular program.

#190015 - 2008-10-03 08:09 PM Re: Dynamic Wrapper Tutorial - Lesson 2 [Re: Arend_]
NTDOC Administrator Offline

Registered: 2000-07-28
Posts: 11619
Loc: CA
Just a quick question.

So this does happen live as if the user turned it on or off via the properties and not via next logon.

#190016 - 2008-10-03 08:15 PM Re: Dynamic Wrapper Tutorial - Lesson 2 [Re: NTDOC]
Arend_ Moderator Offline
MM club member

Registered: 2005-01-17
Posts: 1889
Loc: Hilversum, The Netherlands
Yes, live actions \:\)
#190029 - 2008-10-06 09:26 AM Re: Dynamic Wrapper Tutorial - Lesson 2 [Re: Arend_]
It_took_my_meds Offline

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
Many thanks!
Page 1 of 1 1

Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 221 anonymous users online.
Newest Members
SHEBLU_HOSSAIN, JohnShearer, sam_white, Luuraap, mve666
17800 Registered Users

Generated in 0.139 seconds in which 0.112 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google: