Skip to content

Commit

Permalink
Add constant definitions to shelllink. (#615)
Browse files Browse the repository at this point in the history
* Make the commented-out constants accessible at runtime.
For the values of the constants, see also:
- https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishelllinka-resolve
- https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow

* Add constants for Hotkey.
See also:
https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-gethotkey

* Replace constants in `test_shelllink`.
  • Loading branch information
junkmd committed Sep 15, 2024
1 parent 6709e74 commit d813786
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
27 changes: 16 additions & 11 deletions comtypes/shelllink.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
SLGP_RAWPATH = 0x4

# for SetShowCmd, GetShowCmd
##SW_SHOWNORMAL
##SW_SHOWMAXIMIZED
##SW_SHOWMINNOACTIVE

SW_SHOWNORMAL = 0x01
SW_SHOWMAXIMIZED = 0x03
SW_SHOWMINNOACTIVE = 0x07

# for Resolve
##SLR_INVOKE_MSI
##SLR_NOLINKINFO
##SLR_NO_UI
##SLR_NOUPDATE
##SLR_NOSEARCH
##SLR_NOTRACK
##SLR_UPDATE
SLR_INVOKE_MSI = 0x0080
SLR_NOLINKINFO = 0x0040
SLR_NO_UI = 0x0001
SLR_NOUPDATE = 0x0008
SLR_NOSEARCH = 0x0010
SLR_NOTRACK = 0x0020
SLR_UPDATE = 0x0004

# for Hotkey
HOTKEYF_ALT = 0x04
HOTKEYF_CONTROL = 0x02
HOTKEYF_EXT = 0x08
HOTKEYF_SHIFT = 0x01

# fake these...
ITEMIDLIST = c_int
Expand Down
24 changes: 10 additions & 14 deletions comtypes/test/test_shelllink.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ def test_set_and_get_arguments(self):
self.assertEqual(shortcut.GetArguments(), b"-f")

def test_set_and_get_hotkey(self):
HOTKEYF_ALT = 0x04
HOTKEYF_CONTROL = 0x02
hotkey = shelllink.HOTKEYF_ALT | shelllink.HOTKEYF_CONTROL
shortcut = self._create_shortcut()
shortcut.Hotkey = HOTKEYF_ALT | HOTKEYF_CONTROL
self.assertEqual(shortcut.Hotkey, HOTKEYF_ALT | HOTKEYF_CONTROL)
shortcut.Hotkey = hotkey
self.assertEqual(shortcut.Hotkey, hotkey)

def test_set_and_get_showcmd(self):
SW_SHOWMAXIMIZED = 0x03
shortcut = self._create_shortcut()
shortcut.ShowCmd = SW_SHOWMAXIMIZED
self.assertEqual(shortcut.ShowCmd, SW_SHOWMAXIMIZED)
shortcut.ShowCmd = shelllink.SW_SHOWMAXIMIZED
self.assertEqual(shortcut.ShowCmd, shelllink.SW_SHOWMAXIMIZED)

def test_set_and_get_icon_location(self):
shortcut = self._create_shortcut()
Expand Down Expand Up @@ -113,17 +111,15 @@ def test_set_and_get_arguments(self):
self.assertEqual(shortcut.GetArguments(), "-f")

def test_set_and_get_hotkey(self):
HOTKEYF_ALT = 0x04
HOTKEYF_CONTROL = 0x02
hotkey = shelllink.HOTKEYF_ALT | shelllink.HOTKEYF_CONTROL
shortcut = self._create_shortcut()
shortcut.Hotkey = HOTKEYF_ALT | HOTKEYF_CONTROL
self.assertEqual(shortcut.Hotkey, HOTKEYF_ALT | HOTKEYF_CONTROL)
shortcut.Hotkey = hotkey
self.assertEqual(shortcut.Hotkey, hotkey)

def test_set_and_get_showcmd(self):
SW_SHOWMAXIMIZED = 0x03
shortcut = self._create_shortcut()
shortcut.ShowCmd = SW_SHOWMAXIMIZED
self.assertEqual(shortcut.ShowCmd, SW_SHOWMAXIMIZED)
shortcut.ShowCmd = shelllink.SW_SHOWMAXIMIZED
self.assertEqual(shortcut.ShowCmd, shelllink.SW_SHOWMAXIMIZED)

def test_set_and_get_icon_location(self):
shortcut = self._create_shortcut()
Expand Down

0 comments on commit d813786

Please sign in to comment.