BJP

Creating Context Menu on 3rd Party Apps

4 posts in this topic

#1 ·  Posted (edited)

first time poster....

I am working on an appbar that will allow applications to be docked to it (kinda like the windows taskbar) but will show on second monitor and apps will autoshow/hide on mouse over.  I want the user to be able to select 'dock to appbar' from the system menu of any windows program.  I have made this work using some code I found on the forums.    The code is still very messy.  I want to see if I can get away from using:

GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK')
_WinAPI_RegisterShellHookWindow($g_hForm)

and use _winapi_setwindowshookex instead.

 

Code below....

#include "appbarHelper.au3"
#include <GuiConstantsEx.au3>
#include <GUIConstants.au3>
#include <WinAPISys.au3>
#include <WinAPI.au3>
#include <APISysConstants.au3>
#include <Array.au3>
#include <GuiMenu.au3>
#include <StaticConstants.au3>
#include <WinAPIRes.au3>
#include <EditConstants.au3>


Opt("GUIOnEventMode", 1)
Opt("GuiOnEventMode",1);
opt("RunErrorsFatal",0)
opt("MustDeclareVars",1)
Opt('TrayAutoPause', 0)
OnAutoItExitRegister('OnAutoItExit')
Opt("WinTitleMatchMode", 4)

; Declare variables
If Not IsDeclared("WM_LBUTTONDOWN") Then Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";uint mouseData;uint flags;uint time;uint_ptr dwExtraInfo;"
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global Const $w00t = 0x8765
Global $hHookFunc, $hMouseFunc, $pFunc
Global $hWinHook, $hMouseHook
Global $hgMenu
Global $awindows[1][5]     ; array of information about the windows including:  window handle, x coord of the upper left, y coord of the upper left, x coord of the lower right, y coord of the lower right
global $aDockedWindows[0][6]
Global $ncounter = 0        ; counter of how many windows have been added to $awindows array
Global $hActiveWindow       ; handle to the active window
Global $g_hForm = GUICreate('')
global $hMyAppBar=_AppbarNew("My Appbar","MY_CALLBACK");
global $firstwinpos = 90   ;
global $nlastbuttonpos = 0
global $nbuttonpos = 90
global $aMyButtons[1]     ; array to hold the control id's of the buttons created on the appbar
global $nbuttoncount = 1   ; index to be able to iterate thu the $aMyButtons array
global $aCSR = GUIGetCursorInfo($hMyAppBar)
Global $tWindowPos = null  ; $tagRECT structure with the window rectangle coordinates of the window docked on the appbar
Global $hWinHandle     ;  handle to the window of the application docked on the appbar
Global $tButtonPos         ; $tagRECT structure with the button rectangle coordinates of the button on the appbar
Global $nPID
Global $bHover = False
global $nWindowCount = 0
global $hLastActiveWindow
global $hCurrentMenu

GUISwitch($hMyAppBar)
GUISetBkColor(0xFFFFFF)
$aMyButtons[0] = 0

; create appbar menu
local $dockmenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuitem ("Top",$dockmenu)
GUICtrlSetOnEvent  ( -1, "dockTop" )
GUICtrlCreateMenuitem ("Bottom",$dockmenu)
GUICtrlSetOnEvent  ( -1, "dockBottom" )
GUICtrlCreateMenuitem ("",$dockmenu)
GUICtrlCreateMenuitem ("Exit",$dockmenu)
GUICtrlSetOnEvent  ( -1, "DoExit" )
GUICtrlCreateMenuitem ("",$dockmenu)
GUICtrlCreateMenuitem ("About",$dockmenu)
GUICtrlSetOnEvent  ( -1, "DoAbout" )

; Add Sys Menu Option to 'Dock to Appbar' for any Windows window
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK')
_WinAPI_RegisterShellHookWindow($g_hForm)
$hMouseFunc = DllCallbackRegister("_MouseHook", "int", "int;wparam;lparam")
$pFunc = DllCallbackGetPtr($hMouseFunc)
$hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, _WinAPI_GetModuleHandle(0))
$hHookFunc = DllCallbackRegister('_WinEventProc', 'none', 'ptr;uint;hwnd;int;int;uint;uint')
$pFunc = DllCallbackGetPtr($hHookFunc)
$hWinHook = _SetWinEventHook($EVENT_MIN, $EVENT_MAX, 0, $pFunc, 0, 0, _
                BitOR($WINEVENT_SKIPOWNPROCESS, $WINEVENT_OUTOFCONTEXT))
if $hWinHook = 0 Then Exit MsgBox(0x10, 'Error', 'Could not register callback procedure')
GUIRegisterMsg($WM_NCLBUTTONDOWN, 'WM_NCLBUTTONDOWN')   ; message to keep window from moving

; send the appbar to the BOTTOM of the screen
_AppbarSetDockingEdges(false,false,true,true)
_AppbarDock($hMyAppBar,$ABE_BOTTOM,100,40)
WinActivate($hMyAppBar)
Local $idPic = GUICtrlCreatePic("dish.jpg", 10, 07, 70, 25)
global $ihiddenbutton = GUICtrlCreateButton("",-100,-100, 0,0)


while 1=1
   local $x = 1, $nArraySize

 sleep(10)
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch

   ;ConsoleWrite("$bHover = " & $bHover & @CRLF)
   ;ConsoleWrite("ubound($aMyButtons) = " & ubound($aMyButtons) & @CRLF)
   $nArraySize = ubound($aDockedWindows, $UBOUND_ROWS)
   if $nArraySize > 0 Then
   while $nArraySize >= $x and $bHover = True  ; iterate thru the buttons on the appbar
   ;ConsoleWrite("_on_hover($aMyButtons[" & $x & "]," & $x & ")" & @CRLF)
   _on_hover($aMyButtons[$x], $x)
   ;ConsoleWrite("_on_hover(" & $aMyButtons[$x] & ")" & @CRLF)
   $x = $x + 1
   $nArraySize = ubound($aDockedWindows, $UBOUND_ROWS)
   WEnd
   EndIf
WEnd

; called by the exit button
func DoExit()
 Exit
 EndFunc

; this will be called by the appbarHelper.au3 with msgs from the appbar
; to see this try docking the appbar at the bottom and then resize the windows
; taskbar
; NB: not all windows msgs are responded to yet.
func MY_CALLBACK($hWnd, $MsgID, $WParam, $LParam)
 ;ConsoleWrite("MY_CALLBACK hwnd: " & $hwnd & @LF)
 ;consolewrite("MY_CALLBACK Window Title:  " & WinGetTitle($hWnd) & @CRLF)
EndFunc

; this will be called as autoit exits - this ensures the appbar is cleaned up
func OnAutoItExit()
 _AppbarRemove($hMyAppBar)
    _WinAPI_DeregisterShellHookWindow($g_hForm)
    _WinAPI_UnhookWindowsHookEx($hMouseHook)
    DllCallbackFree($hMouseFunc)
    _UnhookWinEvent($hWinHook)
    DllCallbackFree($hHookFunc)
EndFunc

; dock appbar at the bottom of the second screen
func dockBottom()
 _AppbarDock($hMyAppBar,$ABE_BOTTOM,40,40)
EndFunc

; dock appbar at the top of the second screen
func dockTop()
 _AppbarDock($hMyAppBar,$ABE_TOP,40,40)
EndFunc

Func DoAbout()
 MsgBox(0,"Dish Appbar","Dish Appbar is a tool that was created to give call center agents more virtual screen space and make applications easier to access.")
EndFunc

; function to identify any Windows window that is activated
Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg
 ;ConsoleWrite("Window Handle that WM_SHELLHOOK has is: " & $lParam & "  title=" & WinGetTitle($lParam) & @CRLF)
    Switch $hWnd
        Case $g_hForm
            Switch $wParam
       $hLastActiveWindow = $lParam
                Case $HSHELL_WINDOWACTIVATED
                    Local $sTitle = WinGetTitle($lParam)
     ;ConsoleWrite("Cisco WebEx string left 11 = " & stringleft($sTitle) & @CRLF)   ; and stringleft($sTitle, 11) <> "Cisco WebEx"
     If IsString($sTitle) Then
      ;WinActivate($hWnd)
      $hActiveWindow = winactive($sTitle)
      consolewrite("Window handle = " & $hActiveWindow & @CRLF)
         local $WindowHandle = $hActiveWindow
         local $HMENU = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $WindowHandle, "int", False)
         If @error Then
         MsgBox(0, "Error", "An error occured when getting the SystemMenu: " & @error)
         Exit
         EndIf
          ;WinMove($hActiveWindow, "", @DesktopWidth, @DesktopHeight-250, 175, 175)
                        ConsoleWrite('Activated: ' & $sTitle & @CRLF)
      EndIf
      Case $HSHELL_WINDOWDESTROYED
      if WinExists($lParam) = 1 Then
      ConsoleWrite("$lParam = " & $lParam & "  and Title = " & WinGetTitle($lParam) & @CRLF)
      ConsoleWrite("window hidden but still exists" & @CRLF)
      Else ; window has really been closed
      ConsoleWrite("window does not exist.  Window is not just hidden it has been closed" & @CRLF)
      local $nDeleteIndex = _arraysearch($aDockedWindows, $lParam)
      if  $nDeleteIndex <> -1 Then
         _RemoveDockedApplication($lParam)
      EndIf
      Endif
      Case $HSHELL_FLASH
      ;WinActivate($hLastActiveWindow)
      ConsoleWrite("app flashing " & @CRLF)
      ConsoleWrite("winapi_getactivewindow = " & _WinAPI_GetActiveWindow & @CRLF)

            EndSwitch
    EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Func _RemoveDockedApplication($lParam)
   ConsoleWrite("*******************************************  Function called to remove " & $lParam & " as a docked application" & @CRLF)
   $bHover = False
   local $i = 0
   local $j = 0
   local $b = 0
   local $p = 0
   Local $disp = ""
   local $irows = ubound($aDockedWindows, $UBOUND_ROWS) - 1
   local $icols = ubound($aDockedWindows, $UBOUND_COLUMNS) - 1

   ConsoleWrite("# of rows in $aDockedWindows = " & $irows + 1 & @CRLF)
   For $b = 0 to $irows
   for $p = 0 to $icols
   $disp = $disp & $aDockedWindows[$b][$p] & ","
   Next
   ConsoleWrite("$aDockedWindows = " & $disp & @CRLF)
   $disp = ""
   Next


   local $nDeleteIndex = _arraysearch($aDockedWindows, $lParam)
   if  $nDeleteIndex <> -1 Then     ; if windows handle ($lParam) found in the docked apps array then proceed with code below
   ConsoleWrite("$lParam (a.k.a. window handle) found in Docked Windows array" & @CRLF)
   ConsoleWrite("control to delete is $aDockedWindows[$nDeleteIndex][5] = " & $aDockedWindows[$nDeleteIndex][5] & @CRLF)
   GUICtrlDelete($aDockedWindows[$nDeleteIndex][5])  ; Delete the button off of the appbar
   ConsoleWrite("ubound($aMyButtons) = " & ubound($aMyButtons) & @CRLF)
   ;ConsoleWrite("Deleting this out of $aMyButtons, record # = " &
   local $nButtonDeleteIndex = _arraysearch($aMyButtons, $aDockedWindows[$nDeleteIndex][5])
   if $nButtonDeleteIndex <> -1 Then  ; if button control ID ($aDockedWindows[$nDeleteIndex][5]) is found in MyButtons array then proceed with below code
   _ArrayDelete($aMyButtons, $nButtonDeleteIndex)  ; Delete associated button record out of MyButtons array
   Else
   ConsoleWrite("Could not find control in $aMyButtons" & @CRLF)
   EndIf
   ConsoleWrite("ubound($aMyButtons) = " & ubound($aMyButtons) & " after deleteion" & @CRLF)
  ;local $nButtonDeleteIndex =  _arraysearch($aMyButtons, $lParam)

   ; Move starting position for any new buttons back 100 since a button has been deleted
   if $nbuttonpos <> 90 Then
   $nbuttonpos = $nbuttonpos - 100 ; next button
   EndIf
   ; loop to decrease starting position and ending position of buttons/windows by 100

   ConsoleWrite(" deleteindex = " & $ndeleteindex & @CRLF)
   ConsoleWrite(" $irows = " & $irows & @CRLF)
   _ArrayDelete($aDockedWindows, $nDeleteIndex)   ; Delete the record in the Docked Windows Array
   $nbuttoncount = $nbuttoncount - 1
   $nWindowCount = $nWindowCount - 1

   GUISwitch($hMyAppBar)
   ; Move the buttons if needed
   if $irows > 0 and $nDeleteIndex < $irows then   ; if more than one application docked and if there are other applications docked after the one being deleted
   ConsoleWrite("nbuttoncount = " & $nbuttoncount & @CRLF)
   ConsoleWrite("nWindowCount = " & $nWindowCount & @CRLF)
   ;Local $nWindowDiff = $nWindowCount - $nDeleteIndex
   ;Consolewrite("$nWindowDiff = " & $nWindowCount & " - " & ($nDeleteIndex+1) & " =  " & $nWindowDiff & @CRLF)
    for $i = $nDeleteIndex to ($nWindowCount-1)
   ConsoleWrite("$aDockedWindows[" & $i & "][1] = " & $aDockedWindows[$i][1] & @CRLF)
   local $nCurVal = $aDockedWindows[$i][1]
   ConsoleWrite("++++++++++++++++++++++++++++++++++++++++++++++  $i = " & $i & @CRLF)
   ConsoleWrite("++++++++++++++++++++++++++++++++++++++++++++++  Updating $aDockedWindows[" & $i & "][1] = " & ($aDockedWindows[$i][1] - 100) & @CRLF)
   $aDockedWindows[$i][1] = $nCurVal - 100
   ConsoleWrite("++++++++++++++++++++++++++++++++++++++++++++++  Updating $aDockedWindows[" & $i & "][3] = " & ($aDockedWindows[$i][3] - 100) & @CRLF)
    $aDockedWindows[$i][3] = $aDockedWindows[$i][3] - 100
   ConsoleWrite("GUICtrlSetPos(" & $aDockedWindows[$i][5] & ", " & ($aDockedWindows[$i][1] - @DesktopWidth) & ", -8, 100, 30)" & @CRLF)

   GUICtrlSetPos($aDockedWindows[$i][5], ($aDockedWindows[$i][1] - @DesktopWidth), -8, 100, 30)
   local $hMoveWindow = WinActivate($aDockedWindows[$i][0])
   ;_WinAPI_SetWindowPos($hMoveWindow, $HWND_TOPMOST, $aDockedWindows[$nWindowCount-1][1], $aDockedWindows[$nWindowCount-1][2],  _WinAPI_GetWindowWidth($hMoveWindow), _WinAPI_GetWindowHeight($hMoveWindow), $SWP_HIDEWINDOW)
   _WinAPI_SetWindowPos($hMoveWindow, $HWND_TOPMOST, $aDockedWindows[$i][1], $aDockedWindows[$i][2],  _WinAPI_GetWindowWidth($hMoveWindow), _WinAPI_GetWindowHeight($hMoveWindow), $SWP_HIDEWINDOW)
    Next
   endif

   EndIf

   ConsoleWrite(" ----------- After Array deletion -------------" & @CRLF)
   $irows = $irows - 1
   ConsoleWrite("# of rows in $aDockedWindows = " & $irows + 1 & @CRLF)

   For $b = 0 to $irows
   for $p = 0 to $icols
   $disp = $disp & $aDockedWindows[$b][$p] & ","
   Next
   ConsoleWrite("$aDockedWindows = " & $disp & @CRLF)
   $disp = ""
   Next


   ConsoleWrite("nbuttoncount = " & $nbuttoncount & @CRLF)
   ConsoleWrite("nWindowCount = " & $nWindowCount & @CRLF)
EndFunc

; function to add 'Dock To Appbar' menu option in the system menu of any window that is activated and keep docked apps from moving
Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
   Local $hMenu, $nWindowIndex

   If $iEvent =  $EVENT_SYSTEM_MENUPOPUPSTART Then
   $hCurrentMenu = _GUICtrlMenu_GetMenu($hActiveWindow)
   ConsoleWrite("Current menu handle = " & $hCurrentMenu & @CRLF)
   ;ConsoleWrite("$EVENT_SYSTEM_MENUPOPUPSTART happened" & @CRLF)
   $hMenu = _SendMessage($hWnd, 0x01E1)
   $hgMenu = $hMenu
   if _GUICtrlMenu_GetItemText($hMenu, 0) == "&Restore"  or _GUICtrlMenu_GetItemText($hMenu, 0) == "M&enu bar" Then ; Test to see if this is the system menu   ;
   if _ArraySearch($awindows, $hActiveWindow) = -1  Then  ; or _GUICtrlMenu_GetItemText($hMenu, 0) == "M&enu bar"
   ;ConsoleWrite("ncounter = " & $ncounter & @CRLF)
   $awindows[$ncounter][0] = $hActiveWindow
   redim $awindows[Ubound($awindows)+1][5]
   ;ConsoleWrite("new ubound of $awindows is =  " & ubound($awindows) & @CRLF)
   $ncounter = $ncounter + 1
   If _GUICtrlMenu_IsMenu($hMenu) Then
      _GUICtrlMenu_InsertMenuItem($hMenu, _GUICtrlMenu_GetItemCount($hMenu), "Dock To Appbar", $w00t)
   EndIf
   ;ConsoleWrite("system menu here -1" & @CRLF)
   ElseIf $iEvent = $EVENT_SYSTEM_MENUPOPUPEND Then
   $hgMenu = 0
   ;ConsoleWrite("system menu here 0" & @CRLF)
   Else ; 'Dock to Appbar' option already added to menu
   ;ConsoleWrite("system menu here 1" & @CRLF)
   if _GUICtrlMenu_GetItemText($hMenu, 0) == "M&enu bar" Then   ; if Internet Explorer have to add the "Dock to Appbar menu" and set it to checked
      if _ArraySearch($awindows, $hActiveWindow) >= 0  Then
      If _GUICtrlMenu_IsMenu($hMenu) Then
      _GUICtrlMenu_InsertMenuItem($hMenu, _GUICtrlMenu_GetItemCount($hMenu), "Dock To Appbar", $w00t)
      if _ArraySearch($aDockedWindows, $hActiveWindow) >= 0 Then
      _GUICtrlMenu_CheckMenuItem($hgMenu, $w00t, True, False)    ; set the Dock To Appbar to be checked checked
      EndIf
      EndIf
      EndIf
   EndIf
   EndIf
   Else
   ConsoleWrite("system menu here 2" & @CRLF)
   ConsoleWrite(" first menu = " & _GUICtrlMenu_GetItemText($hMenu, 0) & @CRLF)
   EndIf
   Else

   EndIf

   ; Keep the docked applications from being moved
   $nWindowIndex = _ArraySearch($aDockedWindows, $hActiveWindow)
   If $nWindowIndex = - 1 Then
   ; do nothing
   ;ConsoleWrite("$hActiveWindow (" & WinGetTitle($hActiveWindow) & ") not found in $aDockedWindows Array" & @CRLF)
   Else
   Switch $iEvent ; check to see if window is getting resized
   Case $EVENT_SYSTEM_MOVESIZEEND
   ;ConsoleWrite("End" & @CRLF)
   ;ConsoleWrite("**  After Window Move data for this window (" & WinGetTitle($hActiveWindow) & ") is:  [" &  $aDockedWindows[$nWindowIndex][0] & "], [" & $aDockedWindows[$nWindowIndex][1] & "], [" & $aDockedWindows[$nWindowIndex][2] & "], [" & $aDockedWindows[$nWindowIndex][3] & "], [" & $aDockedWindows[$nWindowIndex][4] & "]" &  @CRLF)
   _WinAPI_SetWindowPos($hActiveWindow, $HWND_TOPMOST, $aDockedWindows[$nWindowIndex][1], $aDockedWindows[$nWindowIndex][2],  _WinAPI_GetWindowWidth($hActiveWindow), _WinAPI_GetWindowHeight($hActiveWindow), $SWP_SHOWWINDOW)
   Case $EVENT_SYSTEM_MOVESIZESTART
   ;ConsoleWrite("Start - Got Here" & @CRLF)
   Case $EVENT_SYSTEM_FOREGROUND
   ;ConsoleWrite("System Foreground - Got Here" & @CRLF)
   EndSwitch
   EndIf
EndFunc   ;==>_WinEventProc

; function to know when the 'Dock To Appbar' menu option has been selected and to detect mouse positioning on the screen
Func _MouseHook($iCode, $iwParam, $ilParam)
   Local $tMouseInfo, $sWindowTitle, $nMenuID
   If $iCode >= 0 Then
      If $hgMenu And $iwParam = $WM_LBUTTONDOWN Then
         If _GUICtrlMenu_GetItemHighlighted($hgMenu, $w00t, False) Then
   ;ConsoleWrite("Docking to Appbar :)" & @CRLF)
   ;Local $aWinDimesions = WinGetClientSize($hActiveWindow)
   ;local $arrayindex = _ArraySearch($awindows, $hActiveWindow)
   local $arrayindex = _ArraySearch($aDockedWindows, $hActiveWindow)
   if $arrayindex = -1 and WinGetTitle($hActiveWindow) <> "My Appbar"  Then
      ; ******  Dock app and create button on appbar (add info to $aMyButtons array) and add app info to the $aDockedWindows Array  *****
      $sWindowTitle = WinGetTitle($hActiveWindow)
      ReDim $aMyButtons[UBound($aMyButtons) + 1]
      $aMyButtons[$nbuttoncount] = GUICtrlCreateButton($sWindowTitle,$nbuttonpos,-8, 100, 30, $BS_BOTTOM)
      GUICtrlSetOnEvent($aMyButtons[$nbuttoncount], "ButtonClick")
      ;ConsoleWrite("$aMyButtons[" & $nbuttoncount & "] = " & $aMyButtons[$nbuttoncount] & @CRLF)
      ;ConsoleWrite("Created button on appbar and redim $aMyButtons to have rows = " & ubound($aMyButtons) & @CRLF)
      ReDim $aDockedWindows[ubound($aDockedWindows)+1][6]
      $aDockedWindows[$nWindowCount][0] = $hActiveWindow
      $aDockedWindows[$nWindowCount][1] = @DesktopWidth + $nbuttonpos   ; x position of the upperleft corner of the window
      $aDockedWindows[$nWindowCount][2] = @DesktopHeight- ( _WinAPI_GetWindowHeight($hActiveWindow)+41 )  ; y position of the upper left corner of the window
      $aDockedWindows[$nWindowCount][3] = _WinAPI_GetWindowWidth($hActiveWindow) + @Desktopwidth + $nbuttonpos  ; x position of the lower right hand corner of the window
      $aDockedWindows[$nWindowCount][4] = @DesktopHeight - 41
      $aDockedWindows[$nWindowCount][5] = $aMyButtons[$nbuttoncount]
      $nbuttonpos = $nbuttonpos + 100

      ; Assign a Local variable the style
      Local $iStyle = _WinAPI_GetWindowLong($aDockedWindows[$nWindowCount][0], $GWL_STYLE)
      ;Remove from the window style the MAXIMIZEBOX, MINIMIZEBOX and SIZEBOX styles.
      $iStyle = BitXOR($iStyle, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)
      ; Set the style of the window.
      _WinAPI_SetWindowLong($aDockedWindows[$nWindowCount][0], $GWL_STYLE, $iStyle)
      ;local $iEXStyle =  _WinAPI_GetWindowLong($aWindows[$arrayindex][0], $GWL_EXSTYLE)

      ;$nMenuID_GUICtrlMenu_GetItemID($hgMenu, $w00t, False)
      ;_GUICtrlMenu_SetItemChecked($hgMenu,$w00t, False)
      _GUICtrlMenu_CheckMenuItem($hgMenu, $w00t, True, False)    ; set the Dock To Appbar to be checked checked
      $bHover = True
   Else
      ConsoleWrite("**********************    App Already Docked Do Nothing ********************************" & @CRLF)
      _RemoveDockedApplication($hActiveWindow)
      $tWindowPos = null
      $tButtonPos = null
      $bHover = False
      return
   EndIf

   GUISwitch($hMyAppBar)

   ;GUICtrlSetBkColor($ctlid,0xffffff)
   ;GUICtrlSetColor($ctlid,0x555111)

   ConsoleWrite("Data for this window is:  [" &  $aDockedWindows[$nWindowCount][0] & "], [" & $aDockedWindows[$nWindowCount][1] & "], [" & $aDockedWindows[$nWindowCount][2] & "], [" & $aDockedWindows[$nWindowCount][3] & "], [" & $aDockedWindows[$nWindowCount][4] & "]" &  @CRLF)
   ;WinMove($hActiveWindow, "", @DesktopWidth+50, @DesktopHeight-($awindows[$arrayindex][2]+38), $awindows[$arrayindex][1], $awindows[$arrayindex][2])
   ;_WinAPI_SetWindowPos($hActiveWindow, $HWND_TOPMOST, @DesktopWidth+$lastwinpos, @DesktopHeight-($awindows[$arrayindex][2]+41), $awindows[$arrayindex][1], $awindows[$arrayindex][2], $SWP_HIDEWINDOW)
   _WinAPI_SetWindowPos($hActiveWindow, $HWND_TOPMOST, $aDockedWindows[$nWindowCount][1], $aDockedWindows[$nWindowCount][2],  _WinAPI_GetWindowWidth($hActiveWindow), _WinAPI_GetWindowHeight($hActiveWindow), $SWP_HIDEWINDOW)
   $nbuttoncount = $nbuttoncount + 1
   $nWindowCount = $nWindowCount + 1
   GUISwitch($hActiveWindow)
   ;WinSetState($hActiveWindow, "", @SW_HIDE)
   Else

   EndIf
   Else

   EndIf
   EndIf
   Switch ($iwParam)
    Case $WM_MOUSEMOVE  ; check if the mouse is moving
       ;ConsoleWrite("Mouse is moving and = " & $btest & @CRLF)
   local $tMouseInfo = DllStructCreate($MSLLHOOKSTRUCT, $ilParam)
   ;ConsoleWrite("Mouse x = " & DllStructGetData($tMouseInfo, 1) & "  |  mouse y = " & dllstructgetdata($tMouseInfo, 2) & @CRLF)
         local $tMousePos = _WinAPI_CreatePoint(DllStructGetData($tMouseInfo, 1), DllStructGetData($tMouseInfo, 2))
   ;ConsoleWrite("rect top left = " & dllstructgetdata($tWindowPos, 1) & ", top right = " & dllstructgetdata($tWindowPos, 2) & ", bottom right = " & dllstructgetdata($tWindowPos, 3) & ", bottom left = " & dllstructgetdata($tWindowPos, 4) &  @CRLF)
   ; if mouse is inside docked application window or inside tab on appbar
   If _WinAPI_PtInRect($tWindowPos, $tMousePos) or  _WinAPI_PtInRect($tButtonPos, $tMousePos) or $tWindowPos = Null Then   ; if mouse is hovering over button or app do nothing
   ;GUISwitch($hWinHandle)
   ;_WinAPI_ShowWindow($hWinHandle, @SW_SHOW)
   ConsoleWrite("Mouse inside window of " & WinGetTitle($hWinHandle) &  @CRLF)
   ;if $tWindowPos = Null then ;  No window in DockedWindows array currently being hovered
   ;if _GUICtrlMenu_GetItemChecked($hgMenu, $w00t, False) then
   ;   ConsoleWrite("Docked to Appbar Checked" & @CRLF)
   ;EndIf
   if ubound($aDockedWindows) > 0 and $tWindowPos = Null then
     $bHover = True
   EndIf

   Else
   if $bHover = False Then
      ConsoleWrite("Mouse is OUTSIDE the needed window coordinates " & @CRLF)
      ;ConsoleWrite("Need to hide app " & WinGetTitle($hWinHandle) &  @CRLF)
      GUISwitch($hWinHandle)
      ;if _ArraySearch($aDockedWindows, $hWinHandle) = -1 Then  ; if current window handle is not in the DockedWindows array
      ConsoleWrite("Hiding Window " & @CRLF)
      _WinAPI_ShowWindow($hWinHandle, @SW_HIDE)
      ;EndIf

      ;;  Failed Attempts
      ;_WinAPI_SetWindowPos($hActiveWindow, $HWND_BOTTOM, $aDockedWindows[$nWindowCount][1], $aDockedWindows[$nWindowCount][2],  _WinAPI_GetWindowWidth($hActiveWindow), _WinAPI_GetWindowHeight($hActiveWindow), $SWP_HIDEWINDOW)
      ;GUICtrlSetState($ihiddenbutton, $GUI_Focus)
      ;if _WinAPI_SwitchToThisWindow($hMyAppbar) = True Then
      ;   ConsoleWrite("Success ++++++++++++ " & @CRLF)
      ;EndIf

      $tWindowPos = null
      ConsoleWrite("ubound of of $aDockedWindows = " & ubound($aDockedWindows) & @CRLF)
      if ubound($aDockedWindows) > 0 then
      $bHover = True
      EndIf
   EndIf
   $tMouseInfo = Null
   $tMousePos = Null
   EndIf
   Case Else
   ;ConsoleWrite("Mouse is NOT moving" & @CRLF)
   EndSwitch

   Return _WinAPI_CallNextHookEx($hMouseHook, $iCode, $iwParam, $ilParam)
EndFunc   ;==>_MouseHook

; Function to register callback for windows when setting new system menu option
Func _SetWinEventHook($ieventMin, $ieventMax, $hMod, $pCallback, $iProcID, $iThreadID, $iFlags)
 Local $aRet

 $aRet = DllCall('user32.dll', 'ptr', 'SetWinEventHook', 'uint', $ieventMin, 'uint', $ieventMax, _
    'hwnd', $hMod, 'ptr', $pCallback, 'dword', $iProcID, 'dword', $iThreadID, 'uint', $iFlags)

 If @error Or $aRet[0] = 0 Then Return SetError(1, 0, 0)
 Return $aRet[0]
EndFunc

; Function to unregister windows callback
Func _UnhookWinEvent($hWinEventHook)
 Local $aRet

 $aRet = DllCall('user32.dll', 'int', 'UnhookWinEvent', 'ptr', $hWinEventHook)
 If @error Or $aRet[0] = 0 Then Return SetError(1, 0, 0)
 Return $aRet[0]
 EndFunc

 func _on_hover($ctlid, $nAppsDocked)
 Local $nArrayCounter = $nAppsDocked - 1
 consolewrite("_______________________________________ _on_hover function called _________________________________________" & @CRLF)
    ;consolewrite("$ctlid = " & $ctlid & @CRLF)

    local static $last_ctlid
    local $aTabPosInGUI  ; array to store button position on the appbar
 local $tPoint    ; structure to store button position on the appbar, which will then be translated to position on the screen at large
    local $tTab   ; structure to store button position on the screen

;~     local $irows = ubound($aDockedWindows, $UBOUND_ROWS)
;~     local $icols = ubound($aDockedWindows, $UBOUND_COLUMNS)
;~     ConsoleWrite("$aDockedWindows row count = " & $irows & @CRLF)
;~     ConsoleWrite("$aDockedWindows col count = " & $icols & @CRLF)
;~     ConsoleWrite("$nAppsDocked = " & $nAppsDocked & @CRLF)
;~     consolewrite("$aDockedWindows[0][0] = " & $aDockedWindows[$nArrayCounter][0] & @CRLF)
;~     consolewrite("$aDockedWindows[" & $nArrayCounter & "][0] = " & WinGetTitle($aDockedWindows[$nArrayCounter][0]) & @CRLF)

    $hWinHandle = WinGetHandle($aDockedWindows[$nArrayCounter][0])
    ;ConsoleWrite("before windowhandle = " & $hWinHandle & @CRLF)
 switch GUIGetCursorInfo($hMyAppBar)[4]
   ;ConsoleWrite("windowhandle = " & $hWinHandle & @CRLF)
   case $ctlid
   ;ConsoleWrite("_on_hover fired... Case $ctlid" & @CRLF)
   if $ctlid = 0 then  ; no button being hovered
   ; do nothing
   ConsoleWrite("no button being hovered" & @CRLF)
   Else
   ; code to create rect structures to define where on the screen the button on the appbar is as well as the docked application
   ; then code shows the docked application
   $aTabPosInGUI = controlgetpos($hMyAppBar, "", $ctlid)
   ;consolewrite("controlgetpos x position = " & $aTabPosInGUI[0] & " y position = " & $aTabPosInGUI[1] & " width = " & $aTabPosInGUI[2] & " height = " & $aTabPosInGUI[3] & @CRLF)
   Local $tPoint = DllStructCreate("int X;int Y")
   DLLStructSetData($tPoint, "X", $aTabPosInGUI[0] )
   DLLStructSetData($tPoint, "Y", $aTabPosInGUI[1] )
   $tTab = _WinAPI_ClientToScreen($hMyAppBar, $tPoint)
   $tButtonPos = _WinAPI_CreateRect(DllStructGetData($tTab, 1), DllStructGetData($tTab, 2), DllStructGetData($tTab, 1)+ $aTabPosInGUI[2], DllStructGetData($tTab, 2)+$aTabPosInGui[3])
      GUICtrlSetBkColor($ctlid,0xff0000)
      GUICtrlSetColor($ctlid,0xffffff)
      ;$tWindowPos = _WinAPI_CreateRect($aDockedWindows[$nAppsDocked][1], $aDockedWindows[$nAppsDocked][2], $aDockedWindows[$nAppsDocked][3], $aDockedWindows[$nAppsDocked][4])
      $tWindowPos = _WinAPI_CreateRect($aDockedWindows[$nArrayCounter][1], $aDockedWindows[$nArrayCounter][2], $aDockedWindows[$nArrayCounter][3], $aDockedWindows[$nArrayCounter][4])
      GUISwitch($hWinHandle)
      _WinAPI_ShowWindow($hWinHandle, @SW_SHOW)
      $bHover = False
   EndIf
   case else
   ;ConsoleWrite("_on_hover fired... Case else" & @CRLF)
            if $last_ctlid = $ctlid then
      GUICtrlSetBkColor($ctlid,0x555111)
      GUICtrlSetColor($ctlid,0xffffff)
      if _WinAPI_GetActiveWindow() <> $hActiveWindow then
      ;consolewrite("docked window not active" & @CRLF)
      if $hActiveWindow <> 0 and wingettitle($hActiveWindow) <> "My Appbar" Then
      GUISwitch($hWinHandle)
      EndIf
      $last_ctlid = 0
      EndIf
            endif
   endswitch
   ;ConsoleWrite("done with _on_hover"  & @CRLF)
 endfunc

 Func WM_NCLBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case 0x02
            Return 0
    EndSwitch
    Return 'GUI_RUNDEFMSG'
 EndFunc   ;==>WM_NCLBUTTONDOWN

 Func ButtonClick()
    ; Note: At this point @GUI_CtrlId would equal $iOKButton,
    ; and @GUI_WinHandle would equal $hMainGUI
 local $aInfo = GUIGetCursorInfo()
    MsgBox(0, "GUI Event", "The control id for this control is = " & $aInfo[4])
EndFunc   ;==>OKButton

 

Edited by JLogan3o13

Share this post


Link to post
Share on other sites



@BJP please use code tags - <> for your code in the future. Keeps our eyes from bleeding as we try to read the code.

Also, as the Developer forum clearly states...

Quote

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

I am going to move this to a more appropriate forum. Please be mindful of where you post in the future....


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites
15 hours ago, JLogan3o13 said:

@BJP please use code tags - <> for your code in the future. Keeps our eyes from bleeding as we try to read the code.

Also, as the Developer forum clearly states...

I am going to move this to a more appropriate forum. Please be mindful of where you post in the future....

Sorry for posting in the wrong place.  I have looked for where you moved this topic to and can't find it.  Please advise.

Share this post


Link to post
Share on other sites

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