Jump to content

ViOrb in autoit


Alek
 Share

Recommended Posts

Autoit version of ViOrb.

incase you dont know what ViOrb is: http://www.lee-soft.com/viorb/

Please report back any problems you may have.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=AOrb.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>
#Include <GuiMenu.au3>
#include <SendMessage.au3>

If $Cmdline[0] Then
 _SendMessage($Cmdline[1],$WM_CLOSE)
EndIf

_Singleton("AutoitViOrbScript")

Opt("WinTitleMatchMode", 4)
Opt("OnExitFunc","OrbExit") ;To avoid trouble :)
;pt("TrayIconHide", 0)

;Settings
Global Const $ORB_TRANSPARENCY = 240

;Stuff
Global Const $AC_SRC_ALPHA      = 1

_GDIPlus_Startup()

Global $TaskBarHwnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
Global $StartMenuHwnd = WinGetHandle("[CLASS:DV2ControlHost]")

Global $Bitmap_Hwnd = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\flag.png")

Global $OrbSize[2] = [_GDIPlus_ImageGetWidth($Bitmap_Hwnd), Floor(_GDIPlus_ImageGetHeight($Bitmap_Hwnd) / 3)]
Global $Button_Normal = _GDIPlus_BitmapCloneArea($Bitmap_Hwnd, 0, $OrbSize[1] * 0, $OrbSize[0], $OrbSize[1],$GDIP_PXF32ARGB)
Global $Button_Hover = _GDIPlus_BitmapCloneArea($Bitmap_Hwnd, 0, $OrbSize[1] * 1, $OrbSize[0], $OrbSize[1], $GDIP_PXF32ARGB)
Global $Button_Push = _GDIPlus_BitmapCloneArea($Bitmap_Hwnd, 0, $OrbSize[1] * 2, $OrbSize[0], $OrbSize[1], $GDIP_PXF32ARGB)

Global $OrbPos = _GetOptimalOrbPos()

Global $Gui = GUICreate("", $OrbSize[0], $OrbSize[1], $OrbPos[0], $OrbPos[1], 0x80000000, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW, $TaskBarHwnd)


RegWrite("HKCR\Directory\Shell\AOrb\", "","REG_SZ", "Exit AOrb")

If @Compiled Then
 RegWrite("HKCR\Directory\Shell\AOrb\Command", "","REG_SZ",'"' &  @ScriptFullPath & '" ' & $Gui)
Else
 RegWrite("HKCR\Directory\Shell\AOrb\Command", "","REG_SZ", '"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $Gui)
EndIf

SetBitmap($Gui, $Button_Normal, $ORB_TRANSPARENCY)
GUISetState()

ControlHide($TaskBarHwnd, "", 304)

Global $State = 0

While 1
 Sleep(10)

 ;This is to prevent the app from crashing if "explorer" crash (taskbar disappear)
 ;It will reinstate the orb once the taskbar appears again
 If Not BitAND(WinGetState("[CLASS:Shell_TrayWnd]"), 2) And $TaskBarHwnd <> 0 Then

    ;clear out all the old data from previus taskbar session.
    $TaskBarHwnd = 0
    $StartMenuHwnd = 0
    If $Gui <> 0 Then
        GUIDelete($Gui)
        $Gui = 0
    EndIf

    ContinueLoop
 ElseIf $TaskBarHwnd = 0 And BitAND(WinGetState("[CLASS:Shell_TrayWnd]"), 2) Then

    ;It appears that a new taskbar have merged.
    $TaskBarHwnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
    $StartMenuHwnd = WinGetHandle("[CLASS:DV2ControlHost]")

    ;time to reinstate the orb.
    $Gui = GUICreate("", 44, 44, $OrbPos[0], $OrbPos[1], 0x80000000, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW, $TaskBarHwnd)
    $Label = GUICtrlCreateLabel("",0,0,44,44)
    SetBitmap($Gui, $Button_Normal, $ORB_TRANSPARENCY)
    If @Compiled Then
        RegWrite("HKCR\Directory\Shell\AOrb\Command", "","REG_SZ",'"' &  @ScriptFullPath  & '" ' & $Gui)
    Else
        RegWrite("HKCR\Directory\Shell\AOrb\Command", "","REG_SZ", '"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $Gui)
    EndIf

    ;And hide the old start button.
    ControlHide($TaskBarHwnd, "", 304)

    ;Befor showing the orb
    GUISetState()
 ElseIf $TaskBarHwnd = 0 Then

    ;Opps, no taskbar was found, time to start all over again in this loop.
    ContinueLoop
 EndIf

 ;Update orb location in case the taskbar have bin resized/moved
 $pos = _GetOptimalOrbPos()

 If $pos[0] <> $OrbPos[0] Or $pos[1] <> $OrbPos[1] Then
    WinMove($Gui, "", $pos[0], $pos[1])
    $OrbPos = $pos
 EndIf

 $Msg = GUIGetMsg()
 $Info = GUIGetCursorInfo($Gui)
 If $Msg = $GUI_EVENT_CLOSE Then

    ;Should come from startbutton context menu
    Exit
 EndIf

 If $Info[0] > 0 And $Info[1] > 0 And $Info[0] < $OrbSize[0] And $Info[1] < $OrbSize[1] Then

    ;Manage events that can happen when cursor is over the button.
    If $Msg = -7 Then
        ;set the bitmap to "pushed" orb
        SetBitmap($Gui, $Button_Push, $ORB_TRANSPARENCY)

        ;Kinda hack fix, but seems better then expected :)
        ControlClick($TaskBarHwnd, "", 304)

        $State = 2
    ElseIf $Msg = -9 Then

        ;Make the "right click" event happen at the correct location so that the menu appears at the correct location like it was the real deal.
        $taskpos = WinGetPos($TaskBarHwnd)
        ControlClick($TaskBarHwnd, "", 304, "Right", 1, $OrbPos[0] - $taskpos[0] + $Info[0],  $OrbPos[1] - $taskpos[1] + $Info[1])

        $State = 3
    ElseIf $State <> 1 And Not $Info[2] And Not  $Info[3] And BitAND(WinGetState($StartMenuHwnd), 2) = 0 Then

        ;set the bitmap to "hover over" orb
        SetBitmap($Gui, $Button_Hover, $ORB_TRANSPARENCY)
        $State = 1
    EndIf
 ElseIf $State <> 0 And BitAND(WinGetState($StartMenuHwnd), 2) = 0  Then

    ;"no state" state (default)
    SetBitmap($Gui, $Button_Normal, $ORB_TRANSPARENCY)
    $State = 0
 ElseIf $State <> 2 And BitAND(WinGetState($StartMenuHwnd), 2) Then

    ;This usally happens when the user push the window key.
    SetBitmap($Gui, $Button_Push, $ORB_TRANSPARENCY)
    $State = 2
 EndIf
WEnd

Func _GetOptimalOrbPos()
 ;Get the location of the windows taskbar and stuff.
 Local $taskpos = WinGetPos($TaskBarHwnd)
 Local $buttonpos = ControlGetPos($TaskBarHwnd, "", 304)
 Local $retpos[2]

 If @error Then

    ;might cause a small hickup but it will prevent the app from cashing.
    Return $retpos
 EndIf

 ;check if its vertical or horizontal
 If $taskpos[2] > $taskpos[3] Then
    $retpos[0] = $taskpos[0] + ($buttonpos[0] + (($buttonpos[2] / 2)  - ($OrbSize[0] / 2)))
    $retpos[1] = $taskpos[1] + (($taskpos[3]/2) - ($OrbSize[1] / 2)) + 1 ; + 1 makes it look more correct I think
 ElseIf $taskpos[3] > $taskpos[2] Then
    $retpos[1] = $taskpos[1] + ($buttonpos[1] + (($buttonpos[3] / 2)  - ($OrbSize[1] / 2)))
    $retpos[0] = $taskpos[0] + (($taskpos[2]/2) - ($OrbSize[0] / 2)) + 1 ; + 1 makes it look more correct I think
 EndIf

 Return $retpos
EndFunc

Func OrbExit()
 ;Dispose all the bitmaps
 _GDIPlus_BitmapDispose($Button_Normal)
 _GDIPlus_BitmapDispose($Button_Hover)
 _GDIPlus_BitmapDispose($Button_Push)
 _GDIPlus_BitmapDispose($Bitmap_Hwnd)

 ;Show the original start menu
 ControlShow($TaskBarHwnd, "", 304)

 RegDelete("HKCR\Directory\Shell\AOrb\")
EndFunc

;Yay to autoit examples ^^
Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

Edit: opps, forgot to include a skin

Posted Image

Edit again:

added a few tweeks, like:

-Adds Exit AOrb option to the context menu, this should safely shut down the orb (anyone got any ideas how i can make the "Exit AOrb" appear at the botto of the startbutton context menu?)

- Somewhat better way of managing states of the orb.

-Smarter orb location calcluations. (should make the skin image size independt with some limits thou)

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

Works very well Alek, nice work.

I think you should make it revert back to normal when the script is closed though. To get the normal start button back I closed explorer then opened it again.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Works very well Alek, nice work.

I think you should make it revert back to normal when the script is closed though. To get the normal start button back I closed explorer then opened it again.

hmm, it should do that if you close it from the system tray (next to the clock).

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

mutiple start buttons, maby you could make an amazing toolbar out of this

I was thinking that you actually remade the vista start menu. Silly me

Still a pretty cool concept. The way you did the button could be useful for, say, custom start button. Nice work

You could also make this a really good prank. Someone sees there start button start flying around....lol

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...