Jump to content

Recommended Posts

Posted

I know that I can use _GUICtrlMenu_GetSystemMenu to access the context menu that appears when you r-click on the title bar of a specific window. Is there a fast way to do this for all windows?

Thanks.

Posted

I know that I can use _GUICtrlMenu_GetSystemMenu to access the context menu that appears when you r-click on the title bar of a specific window. Is there a fast way to do this for all windows?

The title of this question and the content of it contradict each other. Which do you want to do?

If you want to add items to the windows context menu, this should do it for you:

#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

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

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   ;==>InsertMenu

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

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

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   ;==>CreateSystemMenuItem

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   ;==>WM_SYSCOMMAND

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   ;==>SetTransparency

I'm sure there is a way with WinAPI, but the code is from Holger (with a fix).

  • 1 year later...
Posted

I am looking for exactly this script but this script will only fit in the GUI

I'm looking for is that he has sadapte any Windows application.

Can you help me ? =)

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
  • Recently Browsing   0 members

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