1
+ import winim
2
+
3
+
4
+ const stopImage = slurp(" ../res/stop.bmp" )
5
+ var pixelArrayOffset = ord(stopImage[10 .. 13 ][0 ])
6
+
7
+ # Window Stuff
8
+ var
9
+ hInstance = GetModuleHandle(nil )
10
+ hwnd: HWND
11
+ msg: MSG
12
+ wndclass: WNDCLASS
13
+ bmpBackground = CreateBitmap(75 , 75 , 1 , 32 , & stopImage[pixelArrayOffset..^ 1 ])
14
+ timerID = 1337
15
+
16
+
17
+ # Handle Message Pump
18
+ proc WindowProc(hwnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} =
19
+ case message
20
+ of WM_DESTROY:
21
+ KillTimer(hwnd, timerID)
22
+ PostQuitMessage(0 )
23
+ return 0
24
+
25
+ of WM_TIMER:
26
+ var point: POINT
27
+ GetCursorPos(& point)
28
+ SetWindowPos(hwnd, HWND_TOPMOST, (point.x - 37 ), (point.y - 37 ), 0 , 0 , (SWP_NOSIZE or SWP_NOZORDER))
29
+ return 0
30
+
31
+ else :
32
+ return DefWindowProc(hwnd, message, wParam, lParam)
33
+
34
+
35
+ # Boilerplate to create window
36
+ wndclass.style = CS_HREDRAW or CS_VREDRAW
37
+ wndclass.lpfnWndProc = WindowProc
38
+ wndclass.hInstance = hInstance
39
+ wndclass.hbrBackground = CreatePatternBrush(bmpBackground)
40
+ wndclass.lpszClassName = " MouseStopSign"
41
+ RegisterClass(wndclass)
42
+
43
+ hwnd = CreateWindowExW(WS_EX_TOPMOST or WS_EX_LAYERED, " MouseStopSign" , " Mouse Stop Sign" , WS_POPUP or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 0 , 0 , 0 , 0 , hInstance, NULL)
44
+ SetLayeredWindowAttributes(hWnd, RGB(0 , 0 , 0 ), 255 , LWA_ALPHA or LWA_COLORKEY)
45
+
46
+ ShowWindow(hwnd, SW_SHOW)
47
+ UpdateWindow(hwnd)
48
+ SetWindowPos(hwnd, HWND_TOPMOST, 0 , 0 , 75 , 75 , SWP_SHOWWINDOW)
49
+
50
+ # Run timer to repeatedly set window position
51
+ SetTimer(hwnd, timerID, 50 , NULL)
52
+
53
+ while GetMessage(msg, 0 , 0 , 0 ) != 0 :
54
+ TranslateMessage(msg)
55
+ DispatchMessage(msg)
0 commit comments