#190013 - 2008-10-03 05:09 PM
Dynamic Wrapper Tutorial - Lesson 2
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
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
$WMTRAY_TOGGLEQL = ($WM_USER + 237)
$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)
EndFunction
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.
|
Top
|
|
|
|
#190016 - 2008-10-03 08:15 PM
Re: Dynamic Wrapper Tutorial - Lesson 2
[Re: NTDOC]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Yes, live actions
|
Top
|
|
|
|
#214221 - 2023-04-21 03:40 AM
Re: Dynamic Wrapper Tutorial - Lesson 2
[Re: It_took_my_meds]
|
jassing
Just in Town
Registered: 2023-04-18
Posts: 3
Loc: Washington State, USA
|
Seems things have changed, the 1st bit of code doesn't run... errors on line 3, if I change $= to $ then line 4 errors.
C:\temp\syslog\misc\script\kix>type test.kix Dim $objDynaWrap, $lhWnd $objDynaWrap = CreateObject("DynamicWrapper") $objDynaWrap.Register("USER32.DLL", "FindWindow", "i=ss", "f=s", "r=l") $lhWnd = $objDynaWrap.FindWindow("Shell_TrayWnd", "") ? $lhWnd C:\temp\syslog\misc\script\kix>kix32.exe test.kix
ERROR : expected ')'! Script: C:\temp\syslog\misc\script\kix\test.kix Line : 4
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(mole)
and 405 anonymous users online.
|
|
|