Jump to content
LeonNic

Adding a menu in to a Windows program an using it

Recommended Posts

LeonNic

I want to add a menu to an existing program, such as the Windows Notepad and I found a simple way in the example that comes with AutoIt With the function "_GUICtrlMenu_GetMenu. The example creates a menu and their respective sub-menu in notepad and close. Not explained in the example how to handle the created menu which would be most interesting and useful, because if you can not use it, is worthless. Very grateful if someone could show me how. Thanks

Share this post


Link to post
Share on other sites
rudi

Hi.

Interesting question ...

I also can't get, how to use the new menu entries.

I want to add a menu to an existing program, such as the Windows Notepad and I found a simple way in the example that comes with AutoIt With the function "_GUICtrlMenu_GetMenu. The example creates a menu and their respective sub-menu in notepad and close. Not explained in the example how to handle the created menu which would be most interesting and useful, because if you can not use it, is worthless. Very grateful if someone could show me how. Thanks

From the help file, topic _GUICtrlMenu_TrackPopupMenu.au3, you can see, how that should work. The example seems to work only, if the whole GUI was "self created", but not for menu entries added to an existing application?

At least this doesn't work either:

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>

Dim $hWnd, $hMain, $hItem1, $hItem2, $msg

Global Enum $h_Sub1 = 1000, $h_Sub2

Opt('MustDeclareVars', 1)

_Main()

Func _Main()

    ; Open Notepad
    Run("Notepad.exe")
    WinWaitActive("[CLASS:Notepad]")
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    $hMain = _GUICtrlMenu_GetMenu($hWnd)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, "SubItem &1", $h_Sub1)
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, "SubItem &2", $h_Sub2)

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, "Item &1", 0x2000, $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, "Item &2", 0x2001)
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, "Item &3", 0x2002)
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, "Item &4", 0x2003)

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMain, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWnd)

EndFunc   ;==>_Main



While WinExists($hWnd)
    $msg = GUIGetMsg()
    Select
        Case $msg = $h_Sub1
            MsgBox(0, "You selected...", "SubItem 1")
        Case $msg = $h_Sub2
            MsgBox(0, "You selected...", "SubItem 2")
            ; case ...
    EndSelect
WEnd

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Melba23

LeonNic,

That was a lot harder than I thought it should be!!! :huggles:

There must be a simpler way, but this code works if there are no sub-menus (Edit: see below!!!!). You can use the mouse or the cursor keys with "Enter" to select from the added menu. All they do at the momnent is identify themselves to the SciTE console:

#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <Misc.au3>

HotKeySet('{ESC}', '_OnExit')

Global $hWnd, $hMenu, $sCurrent_Item  = ""

; Set menu text and CmdIds
Global $aCmdID[4][2] = [ _
    ["Item &1", 0x2000], _
    ["Item &2", 0x2100], _
    ["Item &3", 0x2200], _
    ["Item &4", 0x2300]]

; Insert menu into Notepad
_InsertMenu()

; Open DLL for IsPressed
$dll = DllOpen("user32.dll")

While 1

    ; Check status of Notepad menubar
    $aInfo = _GUICtrlMenu_GetMenuBarInfo($hWnd)

    ; If menu is active
    If $aInfo[6] = True Then
        ; Run through our added items to see if they are active
        $sCurrent_Item = ""
        For $i = 0 To 3
            If _GUICtrlMenu_GetItemHighlighted($hMenu, $aCmdID[$i][1], False) Then
                ; If active, get text
                If $aCmdID[$i][0] <> $sCurrent_Item Then $sCurrent_Item = $aCmdID[$i][0]
            EndIf
        Next
    EndIf

    ; If one of our menu items was selected
    If $sCurrent_Item <> "" Then
        ; If mouse clicked or Enter pressed
        If _IsPressed("01", $dll) Or _IsPressed("0D", $dll) Then
            ; This is where you do what the selection is there for!!!!!!!!!
            ConsoleWrite("You selected " & $sCurrent_Item & @CRLF)
            ; Prevent "double tap"
            $sCurrent_Item = ""
            ; Wait until mouse/Enter released
            While _IsPressed("0D", $dll) Or _IsPressed("01", $dll)
                Sleep(10)
            WEnd
        EndIf
    EndIf

    Sleep(10)

    ; Exit if Notepad is closed
    If Not WinExists("[CLASS:Notepad]") Then _OnExit()

WEnd

Func _InsertMenu()

    Local $hItem1, $hItem2

    ; Open Notepad
    Run("Notepad.exe")
    WinWaitActive("[CLASS:Notepad]")
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    $hMenu = _GUICtrlMenu_GetMenu($hWnd)

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID[0][0], $aCmdID[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID[1][0], $aCmdID[1][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID[2][0], $aCmdID[2][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID[3][0], $aCmdID[3][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWnd)

EndFunc   ;==>_Insertmenu

Func _OnExit()

    DllClose($dll)
    Exit

EndFunc

I am working on submenus next - the problem is that the top level menu item stays highlighted (highlit?) when the submenu is open. I have some ideas involving the CmdIDs. Accelerator keys may have to wait a bit, though.

There must be a way to do this using GUIRegisterMsg - but I have not found it yet. I know that menus send WM_COMMAND messages when selected, but I cannot seem to intercept those sent by Notepad. Either Vista will not let me see into another process (quite likely - but then I can see the menuitems themselves as the above code shows) or it need some horrible hook code and that waaaaay above my head. Perhaps someone more knowledgeable will take up the challenge. :D

I hope this helps a bit. Thanks for the question - it has filled in a rainy afternoon very pleasantly. :D

M23

Edit:

Ok, if you assume that a menu item with a submenu does not need to get selected itself (which I think is pretty reasonable) then only a very slight modification lets you have submenus as well - you just remove that item from the CmdID list. So change the initial setup array as follows:

Global $aCmdID[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

and submenus work as well! :

Now for the accelerators!

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
ResNullius

piccaso had done some work a while back on this, his used a hook.dll but was able to proccess the added menus properly.

Last time I ran it, AutoIt crashed, but it might give some ideas on what needs to be done to catch the Windows messages.

And maybe somebody brighter than me can update it.

http://www.autoitscript.com/forum/index.php?showtopic=22241&st=0&p=154574&#entry154574

Share this post


Link to post
Share on other sites
Melba23

ResNullius,

Thank you for that link - I had been searching all day for something like it! :

LeonNic,

Here you go - you need Hook.dll from the link ResNullius provided above. Everything works - even the accelerators: :huggles:

#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>

; Windows User Messages
Global Const $UM_ADDMESSAGE = $WM_USER + 0x100

Global $hWndTarget, $sSelection = ""
Global $aCmdID[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

; Insert menu into Notepad
_InsertMenu()

; Gather information...
$iPIDTarget = WinGetProcess($hWndTarget)
$iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok

; Register WM_COMMAND
$hWndLocal = GUICreate("") ;Needed to receive Messages
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
GUIRegisterMsg($WM_COMMAND, "_Filter")

; Keep running while target exists
While WinExists($hWndTarget)

    If $sSelection <> "" Then
        $sSelection = StringReplace($sSelection, "&", "")
        MsgBox(0, "New Menu", "You selected " & $sSelection)
    EndIf

    Sleep(10)

WEnd

; Uninstall Filter
DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok
DllClose($hDll_hook)

Exit

; Process Callback
Func _Filter($hGUI, $iMsg, $wParam, $lParam)

    Switch $iMsg
        Case $WM_COMMAND
            $iCmdID = _WinAPI_LoWord($wParam)
            $sSelection = ""
            For $i = 0 To 5
                If $aCmdID[$i][1] = $iCmdID Then
                    $sSelection = $aCmdID[$i][0]
                EndIf
            Next
    EndSwitch

EndFunc   ;==>_Filter

Func _InsertMenu()

    Local $hItem1, $hItem2

    ; Open Notepad
    Run("Notepad.exe")
    WinWaitActive("[CLASS:Notepad]")
    $hWndTarget = WinGetHandle("[CLASS:Notepad]")
    $hMenu = _GUICtrlMenu_GetMenu($hWndTarget)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, $aCmdID[0][0], $aCmdID[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, $aCmdID[1][0], $aCmdID[1][1])

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID[2][0], $aCmdID[2][1], $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID[3][0], $aCmdID[3][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID[4][0], $aCmdID[4][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID[5][0], $aCmdID[5][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_Insertmenu

That was fun! :D

Over to someone else to see if they can get it to work without the DLL. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
Melba23

Ok, my final say on this (for today at least :huggles: ).

Here is piccaso's script brought up to date. It does not crash for me on Vista - so it should work on everything else! :

As before you need Hook.dll which you can find by following the link in ResNullius' post.

#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>

; Windows User Messages
Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0

Global $hWndTarget, $sMenuSelection = "", $sButtonPressed = ""
Global $aCmdID[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

; Insert menu into Notepad
_InsertMenu()

; Make room for a button
WinMove($hWndTarget, "", 50,50,600,200)

; Add a Button
$iCmdID_Button = 0x3000 ;Unique ControlID to be created
$sButton_Text = "Click Me!"
_WinAPI_CreateWindowEx(0, "Button", $sButton_Text, BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), 490, 100, 80, 30, $hWndTarget, $iCmdID_Button)

; Gather information...
$iPIDTarget = WinGetProcess($hWndTarget)
$iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok

; Register WM_COMMAND
$hWndLocal = GUICreate("") ;Needed to receive Messages
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
GUIRegisterMsg($WM_COMMAND, "_Filter")

; Keep running while target exists
While WinExists($hWndTarget)

    If $sMenuSelection <> "" Then
        $sMenuSelection = StringReplace($sMenuSelection, "&", "")
        MsgBox(0, "New Menu", "You selected " & $sMenuSelection)
        $sMenuSelection = ""
    EndIf

    If $sButtonPressed <> "" Then
        MsgBox(0, "New Button", "You clicked me!")
        $sButtonPressed = ""
    EndIf

    Sleep(10)

WEnd

; Uninstall Filter
DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok
DllClose($hDll_hook)

Exit

; Process Callback
Func _Filter($hGUI, $iMsg, $wParam, $lParam)

    Switch $iMsg
        Case $WM_COMMAND
            $iCmdID = _WinAPI_LoWord($wParam)
            For $i = 0 To 5
                If $aCmdID[$i][1] = $iCmdID Then
                    $sMenuSelection = $aCmdID[$i][0]
                EndIf
            Next
            If _WinAPI_HiWord($wParam) = $BN_CLICKED And _WinAPI_LoWord($wParam) = 0x3000 Then $sButtonPressed = $sButton_Text
    EndSwitch

EndFunc   ;==>_Filter

Func _InsertMenu()

    Local $hItem1, $hItem2

    ; Open Notepad
    Run("Calc.exe")
    WinWaitActive("[CLASS:SciCalc]")
    $hWndTarget = WinGetHandle("[CLASS:SciCalc]")
    $hMenu = _GUICtrlMenu_GetMenu($hWndTarget)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, $aCmdID[0][0], $aCmdID[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, $aCmdID[1][0], $aCmdID[1][1])

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID[2][0], $aCmdID[2][1], $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID[3][0], $aCmdID[3][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID[4][0], $aCmdID[4][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID[5][0], $aCmdID[5][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_Insertmenu

Enjoy. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
Melba23

A small update to the script I posted yesterday to show how you might incorporate multiple buttons and set their font to the GUI default:

#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>

; Windows User Messages
Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0

Global $hWndTarget, $sMenuSelection = "", $sButtonPressed = ""
Global $aCmdID_Menu[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

Global $aCmdID_Button[6][2] = [ _
    ["Button 1", 0x3000], _
    ["Button 2", 0x3001], _
    ["Button 3", 0x3002], _
    ["Button 4", 0x3003], _
    ["Button 5", 0x3004], _
    ["Button 6", 0x3005]]

; Open Calc
Run("Calc.exe")
WinWaitActive("[CLASS:SciCalc]")
$hWndTarget = WinGetHandle("[CLASS:SciCalc]")

; Insert menu
_InsertMenu()

; Make room for buttons
WinMove($hWndTarget, "", 50,50,600,200)

; Add buttons
_AddButtons()

; Gather information...
$iPIDTarget = WinGetProcess($hWndTarget)
$iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok

; Register WM_COMMAND
$hWndLocal = GUICreate("") ;Needed to receive Messages
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
GUIRegisterMsg($WM_COMMAND, "_Filter")

; Keep running while target exists
While WinExists($hWndTarget)

    If $sMenuSelection <> "" Then
        $sMenuSelection = StringReplace($sMenuSelection, "&", "")
        MsgBox(0, "New Menu", "You selected " & $sMenuSelection)
        $sMenuSelection = ""
    EndIf

    If $sButtonPressed <> "" Then
        MsgBox(0, "New Button", "You clicked " & $sButtonPressed)
        $sButtonPressed = ""
    EndIf

    Sleep(10)

WEnd

; Uninstall Filter
DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok
DllClose($hDll_hook)

Exit

; Process Callback
Func _Filter($hGUI, $iMsg, $wParam, $lParam)

    Switch $iMsg
        Case $WM_COMMAND
            $iCmdID = _WinAPI_LoWord($wParam)
            For $i = 0 To 5
                If $aCmdID_Menu[$i][1] = $iCmdID Then
                    $sMenuSelection = $aCmdID_Menu[$i][0]
                EndIf
            Next
            For $i = 0 To 5
                If $aCmdID_Button[$i][1] = $iCmdID Then
                    $sButtonPressed = $aCmdID_Button[$i][0]
                EndIf
            Next
    EndSwitch

EndFunc   ;==>_Filter

Func _InsertMenu()

    Local $hItem1, $hItem2


    $hMenu = _GUICtrlMenu_GetMenu($hWndTarget)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, $aCmdID_Menu[0][0], $aCmdID_Menu[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, $aCmdID_Menu[1][0], $aCmdID_Menu[1][1])

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID_Menu[2][0], $aCmdID_Menu[2][1], $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID_Menu[3][0], $aCmdID_Menu[3][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID_Menu[4][0], $aCmdID_Menu[4][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID_Menu[5][0], $aCmdID_Menu[5][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_Insertmenu

Func _AddButtons()

    Local $hButton

    For $i = 0 To 5
        $hButton = _WinAPI_CreateWindowEx(0, "Button", $aCmdID_Button[$i][0], BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), _
                490, 10 + ($i * 40), 80, 30, $hWndTarget, $aCmdID_Button[$i][1])
        _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True)
    Next

EndFunc

M23

Edit: Tpying. :D

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
ResNullius

@Melba23

Excellent work, thanks very much.

As for

Over to someone else to see if they can get it to work without the DLL. :D

all the research I've done indicates you can't hook a 3rd party process's messages without a dll :huggles:

Share this post


Link to post
Share on other sites
Melba23

ResNullius,

all the research I've done indicates you can't hook a 3rd party process's messages without a dll

After another rainy day working on this, I agree! Although it is relatively easy :huggles: to get the controls in place in another GUI, it is much more difficult to use them. That is probably why there are so few examples in the forum. I think my searching skills are pretty good and I missed piccaso's topic completely - thanks for pointing it out. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
LeonNic

ResNullius,

After another rainy day working on this, I agree! Although it is relatively easy :huggles: to get the controls in place in another GUI, it is much more difficult to use them. That is probably why there are so few examples in the forum. I think my searching skills are pretty good and I missed piccaso's topic completely - thanks for pointing it out. :D

M23

Melba23

First of all I apologize for the delay in responding. I didn’t do it before because I can not devote as much time as I would to Autoit and wanted to try your solutions before writing again. The first approach was enough for my needs because I only needed a simple menu and your script works great. I used it in the program for which it was intended -Not exactly Notepad- and works great.

You found a very good solution and that was very fast, which shows that you enjoyed the job and reveals your talent. Very grateful. I also appreciate the contributions of other colleagues who have participated. Thenks you very much.

Share this post


Link to post
Share on other sites
Melba23

LeonNic,

Glad I could help. It was a fun project. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
hench

Sorry to Hijack this thread.

I am using Melba23 great example to add functionalities into a third party app.

In a need to clean the mess before this third app is being shut down by the user, I want to catch all the "Quit" options available : the [X] closing button as an example.

So, I tried registering WM_SYSCOMMAND > $SC_CLOSE messages.

Problem is, it is glitchy with the _WinAPI_CreateWindowExs'created buttons, the $SC_DRAGDROP (0xF012) behavior is wrong, window won't allow dragging!!!

To reproduce,

1. Comment/Uncomment "_AddButtons" around line 41

2. Run the script

3. Try Dragging the window around

Here's the code :

#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>

; Windows User Messages
Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0

Global $hWndTarget, $sMenuSelection = "", $sButtonPressed = ""
Global $aCmdID_Menu[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

Global $aCmdID_Button[6][2] = [ _
    ["Button 1", 0x3000], _
    ["Button 2", 0x3001], _
    ["Button 3", 0x3002], _
    ["Button 4", 0x3003], _
    ["Button 5", 0x3004], _
    ["Button 6", 0x3005]]

; Open Calc
Run("Calc.exe")
WinWaitActive("[CLASS:SciCalc]")
$hWndTarget = WinGetHandle("[CLASS:SciCalc]")

; Insert menu
_InsertMenu()

; Make room for buttons
WinMove($hWndTarget, "", 50,50,600,200)

; Add buttons
_AddButtons()

; Gather information...
$iPIDTarget = WinGetProcess($hWndTarget)
$iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok

; Register WM_COMMAND
$hWndLocal = GUICreate("") ;Needed to receive Messages
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_SYSCOMMAND, $hWndLocal)
GUIRegisterMsg($WM_COMMAND, "_Filter")
GUIRegisterMsg($WM_SYSCOMMAND, "_Filter")

; Keep running while target exists
While WinExists($hWndTarget)

    If $sMenuSelection <> "" Then
        $sMenuSelection = StringReplace($sMenuSelection, "&", "")
        MsgBox(0, "New Menu", "You selected " & $sMenuSelection)
        $sMenuSelection = ""
    EndIf

    If $sButtonPressed <> "" Then
        MsgBox(0, "New Button", "You clicked " & $sButtonPressed)
        $sButtonPressed = ""
    EndIf

    Sleep(10)

WEnd

; Uninstall Filter
DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok
DllClose($hDll_hook)

Exit

; Process Callback
Func _Filter($hGUI, $iMsg, $wParam, $lParam)

    Switch $iMsg
        Case $WM_COMMAND
            $iCmdID = _WinAPI_LoWord($wParam)
            For $i = 0 To 5
                If $aCmdID_Menu[$i][1] = $iCmdID Then
                    $sMenuSelection = $aCmdID_Menu[$i][0]
                EndIf
            Next
            For $i = 0 To 5
                If $aCmdID_Button[$i][1] = $iCmdID Then
                    $sButtonPressed = $aCmdID_Button[$i][0]
                EndIf
            Next
        Case $WM_SYSCOMMAND
            $iCmdID = $wParam
            ConsoleWrite("yeah : " & $iCmdID & @CRLF)

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Filter

Func _InsertMenu()

    Local $hItem1, $hItem2


    $hMenu = _GUICtrlMenu_GetMenu($hWndTarget)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, $aCmdID_Menu[0][0], $aCmdID_Menu[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, $aCmdID_Menu[1][0], $aCmdID_Menu[1][1])

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID_Menu[2][0], $aCmdID_Menu[2][1], $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID_Menu[3][0], $aCmdID_Menu[3][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID_Menu[4][0], $aCmdID_Menu[4][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID_Menu[5][0], $aCmdID_Menu[5][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_Insertmenu

Func _AddButtons()

    Local $hButton

    For $i = 0 To 5
        $hButton = _WinAPI_CreateWindowEx(0, "Button", $aCmdID_Button[$i][0], BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), _
                490, 10 + ($i * 40), 80, 30, $hWndTarget, $aCmdID_Button[$i][1])
        _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True)
    Next

EndFunc

in this post!

I would really appreciate somebody to take a minute and give a shot !

Thanks,

hench

Edit: english correction

Edit 2 :

According to MSDN page about WM_SYSCOMMAND, an application should return zero if it processes this message. Which I tried, and with success I could now drag window while using the added buttons. But this doesn't solve the problem in my main script ... the extra button is suppose to pop up another gui which is part of a module, and that gui won't move. Yet, I receive the various parameters correctly in WM_SC function, but window stay still ! . any clue about what could interfere with WM_SYSCOMMAND Message ?!

Edited by hench

Share this post


Link to post
Share on other sites
hench

Here's a code update showing the bug

I added the creation of a GUI within Button 1 click event. That GUI is not dragable!

#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>

; Windows User Messages
Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0

Global $hWndTarget, $sMenuSelection = "", $sButtonPressed = ""
Global $aCmdID_Menu[6][2] = [ _
    ["SubItem &1", 0x2100], _
    ["SubItem &2", 0x2101], _
    ["Item &1", 0], _
    ["Item &2", 0x2001], _
    ["Item &3", 0x2002], _
    ["Item &4", 0x2003]]

Global $aCmdID_Button[6][2] = [ _
    ["Button 1", 0x3000], _
    ["Button 2", 0x3001], _
    ["Button 3", 0x3002], _
    ["Button 4", 0x3003], _
    ["Button 5", 0x3004], _
    ["Button 6", 0x3005]]

HotKeySet("^!p","_CleanAndQuit")
; Open Calc
Run("Calc.exe")
WinWaitActive("[CLASS:SciCalc]")
$hWndTarget = WinGetHandle("[CLASS:SciCalc]")

; Insert menu
_InsertMenu()

; Make room for buttons
WinMove($hWndTarget, "", 50,50,600,200)

; Add buttons
_AddButtons()

; Gather information...
$iPIDTarget = WinGetProcess($hWndTarget)
$iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok

; Register WM_COMMAND
$hWndLocal = GUICreate("") ;Needed to receive Messages
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
_SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_SYSCOMMAND, $hWndLocal)
GUIRegisterMsg($WM_COMMAND, "_Filter")
GUIRegisterMsg($WM_SYSCOMMAND, "_Filter")

; Keep running while target exists
While WinExists($hWndTarget)

    If $sMenuSelection <> "" Then
        $sMenuSelection = StringReplace($sMenuSelection, "&", "")
        MsgBox(0, "New Menu", "You selected " & $sMenuSelection)
        $sMenuSelection = ""
    EndIf

    If $sButtonPressed <> "" Then
        Switch $sButtonPressed
            Case $aCmdID_Button[0][0]
                _CreateExtraGui()
            Case Else
                MsgBox(0, "New Menu", "You selected " & $sButtonPressed)
        EndSwitch

        $sButtonPressed = ""
    EndIf

    Sleep(10)

WEnd


_CleanAndQuit()

Func _CreateExtraGui()
    GUICreate("")
    GUISetState()
EndFunc


; Process Callback
Func _Filter($hGUI, $iMsg, $wParam, $lParam)

    Switch $iMsg
        Case $WM_COMMAND
            $iCmdID = _WinAPI_LoWord($wParam)
            For $i = 0 To 5
                If $aCmdID_Menu[$i][1] = $iCmdID Then
                    $sMenuSelection = $aCmdID_Menu[$i][0]
                EndIf
            Next
            For $i = 0 To 5
                If $aCmdID_Button[$i][1] = $iCmdID Then
                    $sButtonPressed = $aCmdID_Button[$i][0]
                EndIf
            Next
        Case $WM_SYSCOMMAND
            $iCmdID = $wParam
            ConsoleWrite("yeah : " & $iCmdID & @CRLF)
            Return 0
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Filter


Func _CleanAndQuit()
    For $x = 0 To UBound($aCmdID_Button)-1
        _WinAPI_DestroyWindow($aCmdID_Button[$x][1])
    Next
    ; Uninstall Filter
    DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal)
    DllClose($hDll_hook)

    Exit
EndFunc

Func _InsertMenu()

    Local $hItem1, $hItem2


    $hMenu = _GUICtrlMenu_GetMenu($hWndTarget)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, $aCmdID_Menu[0][0], $aCmdID_Menu[0][1])
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, $aCmdID_Menu[1][0], $aCmdID_Menu[1][1])

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, $aCmdID_Menu[2][0], $aCmdID_Menu[2][1], $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, $aCmdID_Menu[3][0], $aCmdID_Menu[3][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, $aCmdID_Menu[4][0], $aCmdID_Menu[4][1])
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, $aCmdID_Menu[5][0], $aCmdID_Menu[5][1])

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMenu, 4, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_Insertmenu

Func _AddButtons()

    Local $hButton

    For $i = 0 To 5
        $hButton = _WinAPI_CreateWindowEx("", "Button", $aCmdID_Button[$i][0], BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), _
                490, 10 + ($i * 40), 80, 30, $hWndTarget, $aCmdID_Button[$i][1])
        _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True)
    Next

EndFunc

Well thanks for any future support :x

hench

Share this post


Link to post
Share on other sites
arktikk

I didnt even know this was possible! Thats really inspiring Melba!

Your first script using hook.dll for the notepad menu worked flawlessly, except I wasnt seeing any messages whenever I clicked on an item under the new menu.

Also, I tried running the calculator scripts and it just showed the normal calc...without any extra addons the script was supposed to produce.

I'd be really grateful if you could maybe revise your script so that I could study it. :)

I used picaso's script and got the button to draw, but nothing happened when I clicked the button, it didn't even get highlighted when I hovered over it.

Share this post


Link to post
Share on other sites
arktikk

Sorry, my post was directed toward Melba23. :)

I do have hook.dll in the same folder as the scripts Im trying, and I tried both of your scripts as well, hench, and neither worked for me... it just launched the normal calculator.

Wish I could figure out how these scripts work lol.

Edited by arktikk

Share this post


Link to post
Share on other sites
Melba23

arktikk,

You will no doubt be unsurprised to hear that the 2 examples work for me without problem, so I cannot see how I might "revise" the scripts for you. ;)

However, my system protection software (Comodo Defence+) does ask me each time I run the scripts if I want to install the Hook.DLL as a "global hook" - if I block this the added menus and buttons do not work. Perhaps your system is blocking this silently and so preventing the DLL from doing its work? :)

Look at the Install Filter(s) section of the scripts ans run some errorchecking to see if you get valid returns from the commands - perhaps something like this:

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
    If $hDll_hook = -1 Then MsgBox(0, "Error",  "DllOpen failed!")
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
    If @error Then MsgBox(0, "Error",  "Install Filter WndProc failed!")
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
    If @error Then MsgBox(0, "Error",  "Install Filter GetMessage failed!")

That should at least give you a hint as to what is going wrong. :idiot:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
ResNullius

I do have hook.dll in the same folder as the scripts Im trying, and I tried both of your scripts as well, hench, and neither worked for me... it just launched the normal calculator.

Are you running Windows 7 by chance?

If so, the Calculator window class has changed to "CalcFrame", so you need to replace all instances of "[CLASS:SciCalc]" in the example with "[CLASS:CalcFrame]" to target the correct window.

Share this post


Link to post
Share on other sites
Melba23

ResNullius,

Nice to hear from you again - long time no see! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
arktikk

arktikk,

You will no doubt be unsurprised to hear that the 2 examples work for me without problem, so I cannot see how I might "revise" the scripts for you. ;)

However, my system protection software (Comodo Defence+) does ask me each time I run the scripts if I want to install the Hook.DLL as a "global hook" - if I block this the added menus and buttons do not work. Perhaps your system is blocking this silently and so preventing the DLL from doing its work? :)

Look at the Install Filter(s) section of the scripts ans run some errorchecking to see if you get valid returns from the commands - perhaps something like this:

; Install Filter(s)
$hDll_hook = DllOpen("hook.dll") ;helper dll
    If $hDll_hook = -1 Then MsgBox(0, "Error",  "DllOpen failed!")
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
    If @error Then MsgBox(0, "Error",  "Install Filter WndProc failed!")
DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok
    If @error Then MsgBox(0, "Error",  "Install Filter GetMessage failed!")

That should at least give you a hint as to what is going wrong. :D

M23

I tried this with no error messages. :idiot:

Are you running Windows 7 by chance?

If so, the Calculator window class has changed to "CalcFrame", so you need to replace all instances of "[CLASS:SciCalc]" in the example with "[CLASS:CalcFrame]" to target the correct window.

I am running Win7(x64)! I tried this, combined with Melba's error debug, and I got all 3 error messages, but the window resized and I saw 3 autoit buttons on the calc! I tried removing the debugging and clicking the buttons, and nothing happened.

Thanks so far, you two :idiot:

Edited by arktikk

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.