Jump to content
Sign in to follow this  
ColtsFan

Adding a menu item to the taskbar icon?

Recommended Posts

ColtsFan

I've got a GUI that saves it's position upon exit. When I unplug my second monitor and use just my laptop screen the GUI is often docked off the screen. This brings up a question I've wondered for a long time, is it possible to add a menu item to the taskbar button? Not the icon by the clock, but the actual button itself (see attached thumbnail). For Example, when you right-click the AutoIt help file there are additional options there. This might not be possible. I searched the help file and couldn't find anything on it. Here's a screenshot of the menu I mean...

Perhaps someone knows of a UDF or something that might help?

Thanks for your help :D

post-55447-1263704586654_thumb.jpg

Share this post


Link to post
Share on other sites
Anoni

I am watching this string hopeful that someone can answer this question.

Hopefully it is possible.

Maybe having made a reply at all will get this the attention it needs for

someone to provide an answer?

*if you find a solution to this outside of the forums, it would be appreciated if you could share*

-good luck!-

Share this post


Link to post
Share on other sites
reb

Hi

I found this on the forum a while back.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>

Opt("TrayAutoPause",1)
Opt("TrayMenuMode",1)
        
HotKeySet("^!x" , "getcolor")
HotKeySet("{ESC}" , "fexit")

$setclip = 1

dim $vdif, $wdif, $output, $black, $cyanng, $magentang, $yellowng

$main = GUICreate("Get cursor Color", 75, 45, @DesktopWidth - 140, @DesktopHeight - 120, $WS_BORDER, $WS_EX_CLIENTEDGE + $WS_EX_TOPMOST )
GUISetState()

;Tray GUI Creation
$Clip = TrayCreateItem("To Clipboard ")
TrayItemSetState($clip, $TRAY_CHECKED)
$setclip = 1
TrayCreateItem("")
$valitem    = TrayCreateItem("Instructions")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exit = TrayCreateItem("Exit")
TraySetState()

While 1
    $mouse = MouseGetPos()
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            $var = PixelGetColor( $mouse[0] , $mouse[1])
            $background = GUICtrlSetBkColor($main, $var)
            GUISetBkColor($var, $main)
            ContinueLoop
        Case $msg = $Clip
            $decide = TrayItemGetState($clip)
            If $decide = 1 then
                $setclip = 1
            Else
                $setclip = 0
            endif
        Case $msg = $valitem
            Msgbox(64,"Instructions:","ALT+CTRL+X - Get Color" & @CRLF & "ESC - Exit Program")
        Case $msg = $aboutitem
            Msgbox(64,"about:","November 2009" & @CRLF & "Free usage")
        Case $msg = $exit
            exit
    EndSelect
WEnd

Func getcolor()
    
;Hex color to RGB
    $output = ""
    $hex = Hex ( $var , 6)
;~     $HR = StringMid($hex, 1, 2)
;~     $HG = StringMid($hex, 3, 2)
;~     $HB = StringMid($hex, 5, 2)
;~     $R = Dec($HR)
;~     $G = Dec($HG)
;~     $B = Dec($HB)
    
;Convert RGB to CMY
;~     $cyanr = 1-($r/255)
;~     $magentar = 1-($g/255)
;~     $yellowr= 1-($b/255)
    
;Convert CMY to CMYK
;~     $blackr=1

;~     If $blackr > $cyanr Then $blackr = $cyanr
;~     if $blackr > $magentar Then $blackr= $magentar
;~     if $blackr > $yellowr Then $blackr = $yellowr
;~     if $blackr = 1 Then
;~         $cyanr = 0
;~         $magentar = 0
;~         $yellowr = 0
;~     Else
;~         $cyanr = ($cyanr-$blackr)/(1-$blackr)
;~         $magentar = ($magentar-$blackr)/(1-$blackr)
;~         $yellowr = ($yellowr-$blackr)/(1-$blackr)
;~     EndIf
;~     $kr = $blackr
        
;Let's get only the three decimal numbert to match YMCK requirements    
;~     $cyan = StringFormat("%.3f", $cyanr)
;~     $magenta = StringFormat("%.3f", $magentar)
;~     $yellow = StringFormat("%.3f", $yellowr)
;~     $k = StringFormat("%.3f", $kr)
    
;Output results in a a ballon or to the clipboard
;~     $output = "Hexadecimal : " & $hex & @CRLF
;~     $output = $output & "RGB : " & $R & ", " & $G & ", " & $B & @CRLF
;~     $output = $output & "CYMK : C-" & $cyan & ", M-" & $magenta & ", Y-" &  $yellow & ", K-" & $k
    $output = "GUISetBkColor(0x" & $hex & ")"
    TrayTip("RGB / CYMK Color", $output, 1)
    $backup = ClipGet()
    If $setclip = 1 then
        ClipPut($output)
    Else
        ClipPut($backup)
    EndIf

EndFunc

func fexit()
    Exit
EndFunc

(don't know who to credit it to) It works great for me and includes a menu by right clicking the tray icon which I believe is what you want to do. You can adapt the code to suit your purposes.

REB


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites
danielmohr91

I've got a GUI that saves it's position upon exit. When I unplug my second monitor and use just my laptop screen the GUI is often docked off the screen. This brings up a question I've wondered for a long time, is it possible to add a menu item to the taskbar button? Not the icon by the clock, but the actual button itself (see attached thumbnail). For Example, when you right-click the AutoIt help file there are additional options there. This might not be possible. I searched the help file and couldn't find anything on it. Here's a screenshot of the menu I mean...

Perhaps someone knows of a UDF or something that might help?

Thanks for your help :D

post-55447-1263704586654_thumb.jpg

Great question. I've often wondered the same thing myself. Thanubus, you made a great suggestion with the _GUICtrlMenu_GetSystemMenu() functions. ColtsFan, Here's a quick example I made on how to add a menu items. This is my first time, this just shows how to get them there. Perhaps someone else here more experienced than myself can enlighten us as how to make it actually do something. I'm thinking something along the lines of GUIRegisterMsg to get started.

; gui create menu

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3> ; This is needed for the GUI Menu...

$title = "Menu Test"
$Form1 = GUICreate($title, 600, 275, 300, 125)
$Button1 = GUICtrlCreateButton("Button1", 10, 15, 580, 60, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 10, 80, 580, 180)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_menu()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _menu()
    Local $hWnd, $hMenu
    $hWnd = WinGetHandle($title)
    $hMenu = _GUICtrlMenu_GetSystemMenu($hWnd)

For $i = 5 to 10
    _GUICtrlMenu_InsertMenuItem($hMenu, $i, "Menu Item " &$i)
    Next

    ; Display system menu
    $iCount = _GUICtrlMenu_GetItemCount($hMenu)
   EndFunc   ;==>_Main
Edited by danielmohr91

Share this post


Link to post
Share on other sites
ColtsFan

Great question. I've often wondered the same thing myself. Thanubus, you made a great suggestion with the _GUICtrlMenu_GetSystemMenu() functions. ColtsFan, Here's a quick example I made on how to add a menu items. This is my first time, this just shows how to get them there. Perhaps someone else here more experienced than myself can enlighten us as how to make it actually do something. I'm thinking something along the lines of GUIRegisterMsg to get started.

; gui create menu

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3> ; This is needed for the GUI Menu...

$title = "Menu Test"
$Form1 = GUICreate($title, 600, 275, 300, 125)
$Button1 = GUICtrlCreateButton("Button1", 10, 15, 580, 60, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 10, 80, 580, 180)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_menu()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _menu()
    Local $hWnd, $hMenu
    $hWnd = WinGetHandle($title)
    $hMenu = _GUICtrlMenu_GetSystemMenu($hWnd)

For $i = 5 to 10
    _GUICtrlMenu_InsertMenuItem($hMenu, $i, "Menu Item " &$i)
    Next

    ; Display system menu
    $iCount = _GUICtrlMenu_GetItemCount($hMenu)
   EndFunc   ;==>_Main

Thanks everyone! And thank you daniel, for the example :D I deleted the for... to... loop and added my own menu items. Pretty cool. Like you said, I still don't have anyway of responding to them. I read up on GuiRegisterMsg and you're on to something. I can't figure out what to call with it though. Anyone?

Share this post


Link to post
Share on other sites
Melba23

Hi guys,

You read a new SysMenu item by registering the WM_SYSCOMMAND message. I have based this on your script and used the Edit control to show the result:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3> ; This is needed for the GUI Menu...

$title = "Menu Test"
$Form1 = GUICreate($title, 600, 275, 300, 125)
$Button1 = GUICtrlCreateButton("Button1", 10, 15, 580, 60, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 10, 80, 580, 180)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_menu()

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _menu()
    Local $hWnd, $hMenu
    $hWnd = WinGetHandle($title)
    $hSystemMenu = _GUICtrlMenu_GetSystemMenu($hWnd)

    _GUICtrlMenu_GetItemCount($hSystemMenu)
    _GUICtrlMenu_AppendMenu($hSystemMenu, $MF_SEPARATOR, 0, "")
    _GUICtrlMenu_AppendMenu($hSystemMenu, $MF_STRING, 0x5000, "New Sysmenu Item")

EndFunc   ;==>_menu

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFFF) = 0x5000 Then Write("You pressed me!")
EndFunc   ;==>WM_SYSCOMMAND

; Write message to memo
Func Write($sMessage)
    GUICtrlSetData($Edit1, $sMessage & @CRLF, 1)
EndFunc   ;==>Write

I hope it does what you want. :D

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
Sign in to follow this  

×