Skip to content

Instantly share code, notes, and snippets.

@szkrd
Last active January 31, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szkrd/a2eaac8028d56e35ce37609bdf47f342 to your computer and use it in GitHub Desktop.
Save szkrd/a2eaac8028d56e35ce37609bdf47f342 to your computer and use it in GitHub Desktop.
Calling a dll with autoit
Func ToggleTaskbarAutohide($hide = False)
; this is the message id (from nf-shellapi-shappbarmessage documentation page at microsoft.com)
Local Static $ABM_SETSTATE = 0xA
; these two are message payloads, probably defined as constants in the dll / c lib itself
; a list could be found here: https://stackoverflow.com/a/44746235
Local Static $ABS_AUTOHIDE = 1, $ABS_ALWAYSONTOP = 2
; appbardata will be filled with the results (or prefilled with the input),
; the SHAppBarMessage documentation tells us how it looks:
; https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shappbarmessage
; cbSize hWnd cbMsg uEdge ┌─ rc (rect) ──┐ lParam
; one based: 1 2 3 4 5 6 7 8 9
Local $appBarData = DllStructCreate("DWORD;HWND;UINT;UINT;LONG;LONG;LONG;LONG;LPARAM")
Local $appBarDataPtr = DllStructGetPtr($appBarData)
Local $startMenuHandle = WinGetHandle("[CLASS:Shell_TrayWnd]")
DllStructSetData($appBarData, 1, DllStructGetSize($appBarData)) ; slot 1 must be the size of the data
DllStructSetData($appBarData, 2, $startMenuHandle) ; slot 2 must be the handle of the control
DllStructSetData($appBarData, 9, $hide ? $ABS_AUTOHIDE : $ABS_ALWAYSONTOP) ; 9th is the lparam, which we need
; Local $abmState = DllCall("Shell32\SHAppBarMessage", "DWORD", "ABM_GETSTATE")
; dll return type function paramtype1 param1 paramtype2 param2
; dword dwMessage pointer data
DllCall("shell32.dll", "UINT_PTR", "SHAppBarMessage", "DWORD", $ABM_SETSTATE, "PTR", $appBarDataPtr)
EndFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment