Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Color Picker TSR
#2
And a slightly less responsive version of the program which makes more use of hardware images and has a smaller memory footprint:

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. Smile
Reply


Messages In This Thread
Color Picker TSR - by SMcNeill - 01-24-2025, 08:55 AM
RE: Color Picker TSR - by SMcNeill - 01-24-2025, 10:37 AM
RE: Color Picker TSR - by Steffan-68 - 01-24-2025, 05:58 PM
RE: Color Picker TSR - by SMcNeill - 01-24-2025, 07:22 PM
RE: Color Picker TSR - by Pete - 01-24-2025, 06:00 PM
RE: Color Picker TSR - by Pete - 01-24-2025, 07:31 PM



Users browsing this thread: 2 Guest(s)