Jump to content

CLOSED-How to add a button to a toolbar in an other program


Recommended Posts

  • Moderators

RDSchaefer,

The following is the code I used to create a small toobar on another application. I could not find any way of getting it to act as a proper child in Vista - so I went the overlay route as suggested by RobertKipling.

The toobar is created as a small pop-up with the TOPMOST style. Within the While...WEnd loop, it first checks if the app window has moved and if so, repositions itself. It then reactivates the app window when the toolbar is activated by being clicked on so that any subsequent actions take place on the app and not the toolbar! Finally, the toolbar hides when the app is not the active window - otherwise it would stay TOPMOST over something else! It means that the toolbar vanishes if the app is visible and not active - but I could not think of any other way to do it. ;-)

Anyway, feel free to plunder this as much as you want:

Global $fToolBar_Vis = True, $iLast_X = -99999, $iLast_Y = -99999

; -------

; Create ToolBar GUI
Global $hToolBar = GUICreate("ToolBar", 300, 18, Default, Default, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

; -------

While 1

    ; Check App still running
    If Not WinExists($hApp_Wnd) Then Exit
    
    $iMsg = GUIGetMsg()
    
    If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $hExit_Icon Then Exit
    
    ; Correct position of window if required
    If WinActive($hApp_Wnd) Or WinActive($hToolBar) Then
        $aApp_Pos = WinGetPos($hApp_Wnd)
        If $aApp_Pos[0] <> $iLast_X Or $aApp_Pos[1] <> $iLast_Y Then
            $iLast_X = $aApp_Pos[0]
            $iLast_Y = $aApp_Pos[1]
            $aApp_Client_Size = WinGetClientSize($hApp_Wnd)
            ; You will need to adjust the position to fit your app, of course
            WinMove($hToolBar, '', $aApp_Pos[0] + 360, $aApp_Pos[1] + ($aApp_Pos[3] - $aApp_Client_Size[1]) - 5, $iToolBar_Width, 18)
            GUISetState(@SW_SHOW)
        EndIf
    EndIf
    
    ; Reactivate App when Button window is activated
    If WinActive($hToolBar) Then 
        WinActivate($hApp_Wnd)
    EndIf
    
    ; Hide ToolBar when App not active
    If BitAND(WinGetState($hApp_Wnd), 8) <> 8 And $fToolBar_Vis = True Then
        GUISetState(@SW_HIDE, $hToolBar)
        $fToolBar_Vis = False
    ElseIf BitAND(WinGetState($hApp_Wnd), 8) = 8 And $fToolBar_Vis = False Then
        GUISetState(@SW_SHOW, $hToolBar)
        $fToolBar_Vis = True
    EndIf
    
    ; -------
    
WEnd

Exit

And if you ever find out how to get the toolbar to act as a real child in Vista - please let me know!

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 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

 

Link to comment
Share on other sites

The following is the code...

And if you ever find out how to get the toolbar to act as a real child in Vista - please let me know!

M23

Wow, thanks a lot. Not exactly what I was looking for but it will sure help. BTW - I neither use nor support Vista so if you have something else for XP I'm all ears (eyes?).

Link to comment
Share on other sites

  • Moderators

Zedna,

I hope it helps the OP, but I could not get the anygui UDF to work in Vista. Have you had any luck? I imagine it is Vista doing its "each app in a separate area" security thing, so I am not optimistic. :-(

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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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