Skip to content

Commit 1828886

Browse files
committed
Added mouse stop sign
1 parent 542684e commit 1828886

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To reset most examples, re-launch and kill the program again
2020
| [mouse_cursor.nim](src/mouse_cursor.nim) | Changes the mouse cursor to a finger via a full transparent window |
2121
| [mouse_invert.nim](src/mouse_invert.nim) | Inverts mouse movement on the x and y axes |
2222
| [mouse_trails.nim](src/mouse_trails.nim) | Creates a trail of mouse icons behind the cursor as it moves |
23+
| [mouse_stop.nim](src/mouse_stop.nim) | Creates a stop sign that follows the mouse cursor and blocks clicks |
2324
| [mouse_trap.nim](src/mouse_trap.nim) | Traps the mouse cursor in the top right corner for 60 seconds |
2425
| [random_capslock.nim](src/random_capslock.nim) | Randomly toggle the Caps Lock every 0-30 seconds |
2526
| [random_close.nim](src/random_close.nim) | Randomly closes the current focussed window every 0-30 seconds |
@@ -51,6 +52,12 @@ nim c -d:mingw --app:gui src/avoid.nim
5152

5253
<br>
5354

55+
#### Mouse Stop
56+
57+
<img src="res/mouse_stop.gif"/>
58+
59+
<br>
60+
5461
#### Avoid
5562

5663
<img src="res/avoid.gif"/>

res/mouse_stop.gif

67.2 KB
Loading

res/stop.bmp

22.1 KB
Binary file not shown.

src/mouse_stop.nim

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)