What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » instantiate plus! scripting objects from outside?

instantiate plus! scripting objects from outside?
Author: Message:
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
RE: instantiate plus! scripting objects from outside?
well there's a long answer and a short answer.
if wlm is not minimized to tray (it still works if it's minimized to the taskbar) then you just need one line of code:
code:
WinMenuSelectItem, Windows Live Messenger, , File, My Status, Busy

however, if wlm is minimized to tray, then you'll need all this:
code:
#NoTrayIcon

DetectHiddenWindows, On

OnExit, HandleExit

WinGet, pid_target, PID, ahk_class MSNHiddenWindowClass

hw_notification_area := FindWindow( "Shell_TrayWnd|TrayNotifyWnd|SysPager|ToolbarWindow32,Notification Area" )
if ( ErrorLevel or ! hw_notification_area )
{
   MsgBox, [error] FindWindow failed: ToolbarWindow32,Notification Area
   ExitApp
}

WinGet, pid_explorer, PID, ahk_id %hw_notification_area%
if ( ErrorLevel or ! pid_explorer )
{
   MsgBox, [error] WinGet~PID failed: explorer
   ExitApp
}

hp_explorer := DllCall( "OpenProcess"
                     , "uint", 0x18                              ; PROCESS_VM_OPERATION|PROCESS_VM_READ
                     , "int", false
                     , "uint", pid_explorer )
if ( ErrorLevel or ! hp_explorer )
{
   MsgBox, [error] OpenProcess failed: explorer
   ExitApp
}

remote_buffer_size = 0x1000
remote_buffer := DllCall( "VirtualAllocEx"
                     , "uint", hp_explorer
                     , "uint", 0
                     , "uint", remote_buffer_size
                     , "uint", 0x1000                           ; MEM_COMMIT
                     , "uint", 0x4 )                              ; PAGE_READWRITE
if ( ErrorLevel or ! remote_buffer )
{
   MsgBox, [error] VirtualAllocEx failed: explorer ~ remote_buffer
   ExitApp
}

; TB_BUTTONCOUNT
SendMessage, 0x418, 0, 0,, ahk_id %hw_notification_area%
button_count := ErrorLevel

buffer_size = 40
VarSetCapacity( buffer, buffer_size )

loop, %button_count%
{
   ; TB_GETBUTTON
   SendMessage, 0x417, A_Index-1, remote_buffer,, ahk_id %hw_notification_area%
   if ( ! ErrorLevel )
   {
      MsgBox, [error] SendMessage~TB_GETBUTTON failed: hw_notification_area
      ExitApp
   }
   
   result := DllCall( "ReadProcessMemory"
                  , "uint", hp_explorer
                  , "uint", remote_buffer
                  , "uint", &buffer
                  , "uint", buffer_size
                  , "uint", 0 )
   if ( ErrorLevel or ! result )
   {
      MsgBox, [error] ReadProcessMemory failed: explorer ~ remote_buffer (TB_GETBUTTON)
      ExitApp
   }
                 
   data_address := *( &buffer+12 )+( ( *( &buffer+13 ) ) << 8 )+( ( *( &buffer+14 ) ) << 16 )+( ( *( &buffer+15 ) ) << 24 )
   
   result := DllCall( "ReadProcessMemory"
                     , "uint", hp_explorer
                     , "uint", data_address
                     , "uint", &buffer
                     , "uint", buffer_size
                     , "uint", 0 )
   if ( ErrorLevel or ! result )
   {
      MsgBox, [error] ReadProcessMemory failed: explorer ~ data_address
      ExitApp
   }
   
   wid := *( &buffer )+( ( *( &buffer+1 ) ) << 8 )+( ( *( &buffer+2 ) ) << 16 )+( ( *( &buffer+3 ) ) << 24 )
   
   WinGet, pid, PID, ahk_id %wid%
   
   if ( pid = pid_target )
   {
      ; TB_GETITEMRECT
      SendMessage, 0x41D, A_Index-1, remote_buffer,, ahk_id %hw_notification_area%
      if ( ! ErrorLevel )
      {
         MsgBox, [error] SendMessage~TB_GETITEMRECT failed: hw_notification_area
         ExitApp
      }
     
      result := DllCall( "ReadProcessMemory"
                        , "uint", hp_explorer
                        , "uint", remote_buffer
                        , "uint", &buffer
                        , "uint", buffer_size
                        , "uint", 0 )
      if ( ErrorLevel or ! result )
      {
         MsgBox, [error] ReadProcessMemory failed: explorer ~ remote_buffer (TB_GETITEMRECT)
         ExitApp
      }
     
      WinGetPos, x, y,,, ahk_id %hw_notification_area%

      x := x+*( &buffer )+( ( *( &buffer+1 ) ) << 8 )+( ( *( &buffer+2 ) ) << 16 )+( ( *( &buffer+3 ) ) << 24 )+8
      y := y+*( &buffer+4 )+( ( *( &buffer+5 ) ) << 8 )+( ( *( &buffer+6 ) ) << 16 )+( ( *( &buffer+7 ) ) << 24 )+8
     
      CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
      MouseClick, Left, x, y, 2, 0
MouseMove, xpos, ypos
WinMenuSelectItem, Windows Live Messenger, , File, My Status, Busy
WinClose, Windows Live Messenger

      break
   }
}
return

HandleExit:
   result := DllCall( "VirtualFreeEx"
                     , "uint", hp_explorer
                     , "uint", remote_buffer
                     , "uint", 0
                     , "uint", 0x8000 )                           ; MEM_RELEASE
   if ( ErrorLevel or ! result )
      MsgBox, [warning] VirtualFreeEx failed: explorer ~ remote_buffer
   
   result := DllCall( "CloseHandle", "uint", hp_explorer )
   if ( ErrorLevel or ! result )
      MsgBox, [warning] CloseHandle failed: explorer
ExitApp

FindWindow( p_tree )
{
   level_total = 0

   loop, parse, p_tree, |
   {
      level_total++
     
      ix := InStr( a_LoopField, "," )

      if ( ix )
      {
         StringMid, tree[%level_total%]?class, a_LoopField, 1, ix-1
         StringMid, tree[%level_total%]?title, a_LoopField, ix+1, StrLen( a_LoopField )-ix
      }
      else
      {
         tree[%level_total%]?class := a_LoopField
         tree[%level_total%]?title = 0
      }
   }
   
   hw_parent = 0
   hw_child = 0
   
   level = 1
   
   loop,
   {
      hw_child := FindWindowEx( hw_parent, hw_child, tree[%level%]?class, tree[%level%]?title )

      if ( hw_child )
      {
         if ( level = level_total )
            return, hw_child
     
         level++
         
         hw_parent_old := hw_parent
         hw_parent := hw_child
         
         hw_child_old := hw_child   
         hw_child = 0
      }
      else
      {
         if ( level = 1 )
            return, 0
     
         level--
         
         hw_parent := hw_parent_old
         
         hw_child := hw_child_old
      }
   }
}

FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title=0 )
{
   if ( p_title = 0 )
      type_title = uint
   else
      type_title = str

   return, DllCall( "FindWindowEx"
                  , "uint", p_hw_parent
                  , "uint", p_hw_child
                  , "str", p_class
                  , type_title, p_title )
}


p.s. all of the tray icon stuff was taken from http://www.autohotkey.com/forum/post-36103.html#36103

This post was edited on 08-08-2006 at 04:27 PM by AberNStein.
[Image: gybouserbar6hc.gif]
08-08-2006 04:26 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 11:15 AM
RE: instantiate plus! scripting objects from outside? - by RaceProUK on 08-08-2006 at 12:20 PM
RE: instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 12:24 PM
RE: instantiate plus! scripting objects from outside? - by markee on 08-08-2006 at 12:33 PM
RE: instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 12:40 PM
RE: instantiate plus! scripting objects from outside? - by Veggie on 08-08-2006 at 12:42 PM
RE: instantiate plus! scripting objects from outside? - by AberNStein on 08-08-2006 at 03:36 PM
RE: instantiate plus! scripting objects from outside? - by Intosia on 08-08-2006 at 03:37 PM
RE: instantiate plus! scripting objects from outside? - by deAd on 08-08-2006 at 04:01 PM
RE: RE: instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 05:52 PM
RE: instantiate plus! scripting objects from outside? - by Intosia on 08-08-2006 at 04:08 PM
RE: instantiate plus! scripting objects from outside? - by matty on 08-08-2006 at 04:18 PM
RE: instantiate plus! scripting objects from outside? - by deAd on 08-08-2006 at 04:19 PM
RE: instantiate plus! scripting objects from outside? - by Intosia on 08-08-2006 at 04:24 PM
RE: instantiate plus! scripting objects from outside? - by AberNStein on 08-08-2006 at 04:26 PM
RE: RE: instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 05:59 PM
RE: RE: RE: instantiate plus! scripting objects from outside? - by AberNStein on 08-08-2006 at 06:36 PM
RE: RE: instantiate plus! scripting objects from outside? - by J-Thread on 08-08-2006 at 09:50 PM
RE: instantiate plus! scripting objects from outside? - by Veggie on 08-08-2006 at 05:45 PM
RE: instantiate plus! scripting objects from outside? - by deAd on 08-08-2006 at 10:18 PM
RE: RE: instantiate plus! scripting objects from outside? - by rh on 08-08-2006 at 10:47 PM
RE: instantiate plus! scripting objects from outside? - by Shondoit on 08-08-2006 at 10:55 PM
RE: instantiate plus! scripting objects from outside? - by Silentdragon on 08-08-2006 at 11:18 PM
RE: instantiate plus! scripting objects from outside? - by Shondoit on 08-08-2006 at 11:23 PM
RE: RE: instantiate plus! scripting objects from outside? - by AberNStein on 08-09-2006 at 04:49 AM
RE: instantiate plus! scripting objects from outside? - by rh on 08-09-2006 at 07:38 AM
RE: instantiate plus! scripting objects from outside? - by Intosia on 08-09-2006 at 09:08 AM


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