Jump to content

Application menu, how do I get in?


Recommended Posts

I know, it's probably really simple, but I've searched and searched and nothing's coming up anywhere! I just want to put a few items in the application menu, you know, the one in the top-left of all windows.

How to do it?

-mu

Edited by mr.underperson
Link to comment
Share on other sites

I believe he means the menu that shows up when you click the icon on the titlebar of a window or when you rightclick the titlebar.

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Small sample:

#include <GUIConstants.au3>

Global Const $MF_BYPOSITION = 0x00000400
Global Const $MF_SEPARATOR  = 0x00000800
Global Const $MF_CHECKED    = 0x00000008
Global Const $MF_POPUP      = 0x00000010

Global Const $WM_SYSCOMMAND = 0x0112

Dim $nTPChecked             = 0

Dim $hGUI = GUICreate("Test")
GUISetState()
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")


$nItem1     = CreateSystemMenuItem("Info about this...", -1, FALSE, 0)
CreateSystemMenuItem("", -1, FALSE, 1)

CreateSystemMenuItem("")
$hTPMenu    = CreateSystemMenuItem("Transparency", -1, TRUE)
Dim $arTransItems[10]
For $i = 0 To 9
    $arTransItems[$i] = CreateSystemMenuItem($i * 10 & "%", $hTPMenu)
    If $i = 0 Then
        $nTPChecked = $arTransItems[$i]
        CheckMenuItem($hTPMenu, $nTPChecked, $MF_CHECKED)
    EndIf
Next

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Exit


; ******** Functions ********

Func GetSystemMenu($hWnd, $bRevert)
    Local $hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", _
                                                "hwnd", $hWnd, _
                                                "int", $bRevert)
    Return $hMenu[0]
EndFunc


Func InsertMenu($hMenu, $nPosition, $nFlags, $nIDNewItem, $lpNewItem)
    Local $nResult = DllCall("user32.dll", "int", "InsertMenu", _
                                                "hwnd", $hMenu, _
                                                "int", $nPosition, _
                                                "int", $nFlags, _
                                                "int", $nIDNewItem, _
                                                "str", $lpNewItem)
    Return $nResult[0]
EndFunc


Func CreatePopupMenu()
    Local $hMenu = DllCall("user32.dll", "hwnd", "CreatePopupMenu")
    Return $hMenu[0]
EndFunc


Func CheckMenuItem($hMenu, $nID, $nFlags)
    DllCall("user32.dll", "int", "CheckMenuItem", _
                                "hwnd", $hMenu, _
                                "int", $nID, _
                                "int", $nFlags)
EndFunc


Func CreateSystemMenuItem($sText, $hMenu = -1, $bIsPopup = FALSE, $nPos = 0xFFFFFFFF); 0xFFFFFFFF means "insert at the end"

    If $hMenu = -1 Then $hMenu = GetSystemMenu($hGUI, 0)
    
    Local $nID      = GUICtrlCreateDummy()
    Local $nFlags   = 0
    
    If $sText = "" Then
        $nFlags = $MF_SEPARATOR
    ElseIf $bIsPopup Then
        $nID = CreatePopupMenu()
        $nFlags = $MF_POPUP
    EndIf   
    
    $nFlags = BitOr($MF_BYPOSITION, $nFlags)
    
    $nResult = InsertMenu($hMenu, $nPos, $nFlags, $nID, $sText)
    
    Return $nID
EndFunc


Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    $nID = BitAnd($wParam, 0x0000FFFF)

    Switch $nID
        Case $arTransItems[0] To $arTransItems[9]
            SetTransparency($nID)
            
        Case $nItem1
            Msgbox(0, "Info", "SystemMenu sample.")
    EndSwitch
EndFunc


Func SetTransparency($nID)
    For $i = 0 To 9
        If $arTransItems[$i] = $nID Then ExitLoop
    Next
    
    WinSetTrans($hGUI, "", 255 * (100 - $i * 10) / 100)
    
    If $nTPChecked <> $nID Then CheckMenuItem($hTPMenu, $nTPChecked, 0)
    
    CheckMenuItem($hTPMenu, $nID, $MF_CHECKED)
    
    $nTPChecked = $nID
EndFunc
Edited by Holger
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...