winclass.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build windows
  2. package wintray
  3. import (
  4. "unsafe"
  5. "golang.org/x/sys/windows"
  6. )
  7. // Contains window class information.
  8. // It is used with the RegisterClassEx and GetClassInfoEx functions.
  9. // https://msdn.microsoft.com/en-us/library/ms633577.aspx
  10. type wndClassEx struct {
  11. Size, Style uint32
  12. WndProc uintptr
  13. ClsExtra, WndExtra int32
  14. Instance, Icon, Cursor, Background windows.Handle
  15. MenuName, ClassName *uint16
  16. IconSm windows.Handle
  17. }
  18. // Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
  19. // https://msdn.microsoft.com/en-us/library/ms633587.aspx
  20. func (w *wndClassEx) register() error {
  21. w.Size = uint32(unsafe.Sizeof(*w))
  22. res, _, err := pRegisterClass.Call(uintptr(unsafe.Pointer(w)))
  23. if res == 0 {
  24. return err
  25. }
  26. return nil
  27. }
  28. // Unregisters a window class, freeing the memory required for the class.
  29. // https://msdn.microsoft.com/en-us/library/ms644899.aspx
  30. func (w *wndClassEx) unregister() error {
  31. res, _, err := pUnregisterClass.Call(
  32. uintptr(unsafe.Pointer(w.ClassName)),
  33. uintptr(w.Instance),
  34. )
  35. if res == 0 {
  36. return err
  37. }
  38. return nil
  39. }