Created
May 10, 2024 13:38
-
-
Save Stehfyn/18584ce480374b55c72f9f1c17d4ba6c to your computer and use it in GitHub Desktop.
sysmenu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <GUIConstants.au3> | |
| Global Const $MF_BYPOSITION = 0x00000400 | |
| Global Const $MF_SEPARATOR = 0x00000800 | |
| Global Const $MF_CHECKED = 0x00000008 | |
| Global Const $MF_POPUP = 0x00000010 | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_RegisterWindowMessage.htm