Sign in to follow this  
Followers 0
Rawox

Porting C# to AutoIt?

8 posts in this topic

So, I found this post on StackOverflow: http://stackoverflow.com/questions/1557904/adding-a-custom-context-menu-item-to-windows-form-title-bar

Is it possible to port this into AutoIt? I don't have enough skills for this but I would love to make this.

Thanks in advance,

Rawox

Share this post


Link to post
Share on other sites



Rawox,

Do you want to do this to a GUI you are creating in AutoIt (easy) or another non-AutoIt GUI (a bit more difficult)? ;)

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

#3 ·  Posted (edited)

Directly-ish translating it will be:

#include<GUIMenu.au3>
#include<WindowsConstants.au3>

Form1()

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func Form1()
    $hGUI = GUICreate("test")
    GUISetState()
    GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

    Local $hMenu = _GUICtrlMenu_GetSystemMenu($hGUI, False)
    If $hMenu <> 0 Then
        _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Test Item", 1000)
        _GUICtrlMenu_DrawMenuBar($hGUI)
    EndIf
EndFunc

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case 1000
            ConsoleWrite("Click!" & @CRLF)
    EndSwitch
EndFunc

Mat

Edit @M23... The link wanted it on a form you've made. The above is something I never realised was so easy :) It went straight to the toolbox after writing... You learn something new everyday - Even when you go to school ;)

Edited by Mat

Share this post


Link to post
Share on other sites

Mat,

A+ for you! ;)

And for an external non-AutoIt GUI? :)

M23

P.S. I am cheating here - if you search, you should find a solution I have already posted. ;)


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

Ah... Seen yours now ;)

http://www.autoitscript.com/forum/index.php?showtopic=56536&view=findpost&p=747017

AWESOME!!

Now just to turn it into a UDF...

Share this post


Link to post
Share on other sites

I meant for a non AutoIt-GUI btw! Thanks again Melba and Mat for some really useful resources!

And Mat, are u really going to turn this into an UDF?

Share this post


Link to post
Share on other sites

I meant for a non AutoIt-GUI btw! Thanks again Melba and Mat for some really useful resources!

And Mat, are u really going to turn this into an UDF?

Not now... Not later... One day... Maybe...

I'll try and fail I guess, that stuffs way over my head.

Share this post


Link to post
Share on other sites

Rawox,

Her is my script for adding to the system menu of a non-AutoIt GUI - it also adds to the menu and inserts some additional buttons:

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

Opt('MustDeclareVars', 1)

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

Global $hWndTarget, $sMenuSelection = "", $sButtonPressed = ""
Global $aCmdID_Menu[4][2] = [["Item &1", 0x2000],["Item &2", 0x2001],["Item &3", 0x2002],["Item &4", 0x2003]]
Global $aCmdID_Button[4][2] = [["Button 1", 0x3000],["Button 2", 0x3001],["Button 3", 0x3002],["Button 4", 0x3003]]

_Main()

Func _Main()

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

    ; Insert menu
    _InsertMenu()

    ; Add to system menu
    Local $hSystemMenu = _GUICtrlMenu_GetSystemMenu($hWndTarget)
    _GUICtrlMenu_GetItemCount($hSystemMenu)
    _GUICtrlMenu_AppendMenu($hSystemMenu, $MF_SEPARATOR, 0, "")
    _GUICtrlMenu_AppendMenu($hSystemMenu, $MF_STRING, 0x3000, "New Sysmenu Item")

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

    ; Add buttons
    _AddButtons()

    ; Get Calc thread ID
    Local $iPIDTarget = WinGetProcess($hWndTarget)
    Local $iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget)

    ; Install Filters
    Local $hDll_hook = DllOpen("hook.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

    ; Create a GUI to receive the messages
    Local $hWndLocal = GUICreate("")
    ; Get messages routed through the GUI
    _SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal)
    _SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_SYSCOMMAND, $hWndLocal)
    ; Register WM_COMMAND
    GUIRegisterMsg($WM_COMMAND, "_Filter")
    GUIRegisterMsg($WM_SYSCOMMAND, "_Filter")

    ; Keep running until Calc is closed
    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 Filters
    DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok
    DllClose($hDll_hook)

    Exit

EndFunc

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

    #forceref $hGUI, $lParam

    If $iMsg = $WM_COMMAND Then
        Local $iCmdID = _WinAPI_LoWord($wParam)
        For $i = 0 To UBound($aCmdID_Menu) - 1
            If $aCmdID_Menu[$i][1] = $iCmdID Then
                $sMenuSelection = $aCmdID_Menu[$i][0]
            EndIf
        Next
        For $i = 0 To UBound($aCmdID_Button) - 1
            If $aCmdID_Button[$i][1] = $iCmdID Then
                $sButtonPressed = $aCmdID_Button[$i][0]
            EndIf
        Next
    EndIf

    If $iMsg = $WM_SYSCOMMAND Then
        If _WinAPI_LoWord($wParam) = 0x3000 Then
            $sMenuSelection = "SysMenu"
        EndIf
    EndIf

EndFunc   ;==>_Filter

Func _InsertMenu()

    ; Create additional menu
    Local $hMenu_Add = _GUICtrlMenu_CreateMenu()
    For $i = 0 To UBound($aCmdID_Menu) - 1
        ; Get count of current items to add at end
        Local $iMenuItems = _GUICtrlMenu_GetItemCount($hMenu_Add)
        _GUICtrlMenu_InsertMenuItem($hMenu_Add, $iMenuItems + 1, $aCmdID_Menu[$i][0], $aCmdID_Menu[$i][1])
    Next
    ; Get handle of menu in Calc
    Local $hTargetMenu = _GUICtrlMenu_GetMenu($hWndTarget)
    ; Get count of current items and insert at next-to-last (before Help)
    Local $iMenuItems = _GUICtrlMenu_GetItemCount($hTargetMenu)
    _GUICtrlMenu_InsertMenuItem($hTargetMenu, $iMenuItems - 1, "&AutoIt", 0, $hMenu_Add)
    _GUICtrlMenu_DrawMenuBar($hWndTarget)

EndFunc   ;==>_InsertMenu

Func _AddButtons()

    Local $hButton

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

EndFunc   ;==>_AddButtons

You will need the DLL from picsaso's post here to make it work. ;)

Have fun! :)

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

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