Jump to content

Recommended Posts

Posted

Hi, I would like to do one of the following:

  • add a menu item to the top left menu of a window.. you know the maxmize/move/etc. menu
  • or: have a hidden menu that appears when ALT is held down, much like vista explorer does

can someone point me in the right direction? thanks

Posted

ycomp

add a menu item to the top left menu of a window.. you know the maxmize/move/etc. menu

Try this:

#include <GuiConstantsEx.au3>
#include <GuiMenu.au3>

Global Enum $id_URL = 1000, $id_About

$hGui = GUICreate("Menu test", 300, 200)

$hMenu = _GUICtrlMenu_GetSystemMenu($hGui)

_GUICtrlMenu_AppendMenu($hMenu, $MF_SEPARATOR, 0, 0)
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_URL, "Go to address...")
_GUICtrlMenu_AppendMenu($hMenu, $MF_STRING, $id_About, "About")

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $idFrom
    
    $idFrom = BitAND($wParam, 0xFFFF)
    
    Switch $idFrom
        Case $id_URL
            ShellExecute("http://www.autoitscript.com/forum")
        Case $id_About
            MsgBox(64, "About", "Autoit v " & @AutoItVersion)
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
Posted

make a menu wich is only shown on ALT:

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <Misc.au3>
Opt('MustDeclareVars', 1)

Global $iMemo
Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout

_Main()

Func _Main()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain

    ; Create GUI
    $hGUI = GUICreate("Menu", 400, 300)

    ; Create File menu
    $hFile = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
    _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
    _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
;~     _GUICtrlMenu_SetMenu ($hGUI, $hMain)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Loop until user exits
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Local $HiddenMenu = 0
    ; Loop until user exits
    Do
        If $HiddenMenu And _IsPressed(12) Then
            _GUICtrlMenu_SetMenu ($hGUI,$hMain)
            $HiddenMenu = 0
        ElseIf Not $HiddenMenu And Not _IsPressed(12) Then
            _GUICtrlMenu_SetMenu ($hGUI,0)
            $HiddenMenu = 1
        EndIf
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch _WinAPI_LoWord ($iwParam)
        Case $idNew
            MemoWrite("New")
        Case $idOpen
            MemoWrite("Open")
        Case $idSave
            MemoWrite("Save")
        Case $idExit
            Exit
        Case $idCut
            MemoWrite("Cut")
        Case $idCopy
            MemoWrite("Copy")
        Case $idPaste
            MemoWrite("Paste")
        Case $idAbout
            MemoWrite("About")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

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

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

cool... you guys are great.. ALT thing works perfectly.. but the sysmenu also will be useful for the project. thanks

Posted

Question 1:

I would like to hook my Form (or maybe my ListView) to intercept ALT keypress... but only if ALT keypress is pressed on my form.. (or maybe my Listview)

Can I use GUIRegisterMsg to do this? or some other way?

Question 2:

while I am on the subject of keypresses... is there a way to intercept a key only for my application? Instead of intercepting globally?

This is for another thing I'm working on, it is independent of Question 1

thanks

Posted

The ALT-Keypress are made in the menu: Put an & before the letter to use for ALT-Combinations. Example:

-Menu:
&File
-> &Save
-ALT:
[ALT]+[F]+[S]

Question2: in the BEta, you can use GUISetAccelerators

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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
×
×
  • Create New...