Advertisement
Guest User

Nim

a guest
Nov 20th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.13 KB | Source Code | 0 0
  1. import wNim
  2. import winim/lean
  3.  
  4. const
  5.   NOTIFY_FOR_THIS_SESSION: DWORD = 0
  6.   WM_WTSSESSION_CHANGE: DWORD = 0x2b1
  7.   WTS_SESSION_LOCK: DWORD = 0x7
  8.   WTS_SESSION_UNLOCK: DWORD = 0x8
  9.   WTS_SESSION_REMOTE_CONTROL: DWORD = 0x9
  10.  
  11. {.push stdcall, dynlib: "wtsapi32".}
  12. proc WTSRegisterSessionNotification*(hwnd: HANDLE, dwFlags: DWORD): bool
  13.   {.importc: "WTSRegisterSessionNotification".}
  14. proc WTSUnRegisterSessionNotification*(hwnd: HANDLE): bool
  15.   {.importc: "WTSUnRegisterSessionNotification".}
  16. {.pop.}
  17.  
  18. when isMainModule:
  19.   let
  20.     app = App()
  21.     frm = Frame(title="Frame", size=(640, 480))
  22.     sn = WTSRegisterSessionNotification(frm.getHandle, NOTIFY_FOR_THIS_SESSION)
  23.  
  24.   frm.WM_WTSSESSION_CHANGE do (ev: wEvent):
  25.     echo ev.getWindow.handle
  26.     case ev.getwParam
  27.     of WTS_SESSION_LOCK: echo "lock"
  28.     of WTS_SESSION_UNLOCK: echo "unlock"
  29.     of WTS_SESSION_REMOTE_CONTROL: echo "remote control"
  30.     else: echo "unknown"
  31.  
  32.   frm.center
  33.   frm.show
  34.  
  35.   if not sn:
  36.     echo "Error: can not register WTS Session Notification"
  37.   else:
  38.     defer:
  39.       discard WTSUnRegisterSessionNotification(frm.getHandle)
  40.     app.mainLoop
Tags: Nim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement