01-24-2025, 10:37 AM
And a slightly less responsive version of the program which makes more use of hardware images and has a smaller memory footprint:
This uses about 0.2% of a CPU on my machine, according to task manager, so for something checking mouse and keyboard input 10 times per second and responding to it in the background, that seems like a decent amount to me. Feel free to tweak the _LIMIT if that's unacceptable on your system. Mem usage holds steady around 30mb or so...
So 30mb of ram and 0.2% CPU on a single core to always have a color picker handy. That doesn't sound bad.
Code: (Select All)
Dim WinMse As POINTAPI
Type POINTAPI: As Long X_Pos, Y_Pos: End Type
Declare Dynamic Library "User32"
Function GetWindowLongA& (ByVal hwnd As Long, ByVal nIndex As Long)
Function SetWindowLongA& (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Function GetAsyncKeyState% (ByVal vkey As Long)
Function GetCursorPos (lpPoint As POINTAPI)
End Declare
software_screen = _NewImage(_FontWidth * 10, _FontHeight, 32)
Screen software_screen
GWL_STYLE = -16
ws_border = &H800000
WS_VISIBLE = &H10000000
_Title "Color Picker"
hwnd& = _WindowHandle
winstyle& = GetWindowLongA&(hwnd&, GWL_STYLE)
_Delay .2
a& = SetWindowLongA&(hwnd&, GWL_STYLE, winstyle& And WS_VISIBLE)
show = -1
swaptimer# = Timer(0.001) + 1
_DisplayOrder _Hardware
hardware_screen = _CopyImage(software_screen, 33)
Do
If Timer(0.001) > swaptimer# Then
If GetAsyncKeyState(&H11) _Andalso GetAsyncKeyState(&H12) _Andalso GetAsyncKeyState(&H4B) Then
show = Not show
swaptimer# = (Timer(0.001) + 1) Mod 86400
If show Then _ScreenShow Else _ScreenHide
End If
End If
_Limit 10
z = GetCursorPos(WinMse)
If x <> WinMse.X_Pos _Andalso y <> WinMse.Y_Pos Then
_ScreenMove WinMse.X_Pos + 1, WinMse.Y_Pos + 1
tempimage = _ScreenImage
_Source tempimage: kolor$ = Hex$(Point(WinMse.X_Pos, WinMse.Y_Pos)): _Source 0
_FreeImage tempimage
If kolor$ <> oldkolor$ Then
_FreeImage hardware_screen
Cls , 0, software_screen
_PrintString (0, 0), kolor$, software_screen
hardware_screen = _CopyImage(software_screen, 33)
End If
_PutImage , hardware_screen
_Display
oldkolor$ = kolor$
End If
x = WinMse.X_Pos: y = WinMse.Y_Pos
Loop
This uses about 0.2% of a CPU on my machine, according to task manager, so for something checking mouse and keyboard input 10 times per second and responding to it in the background, that seems like a decent amount to me. Feel free to tweak the _LIMIT if that's unacceptable on your system. Mem usage holds steady around 30mb or so...
So 30mb of ram and 0.2% CPU on a single core to always have a color picker handy. That doesn't sound bad.