Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Color Picker TSR
#1
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
Width 12, 1 'large enough to hold our color value in hex
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)

Color 15
show = -1

swaptimer# = Timer(0.001) + 1

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 30
z = GetCursorPos(WinMse)
_ScreenMove WinMse.X_Pos + 1, WinMse.Y_Pos + 1
tempimage = _ScreenImage
Cls , 0
_Source tempimage: Print Hex$(Point(WinMse.X_Pos, WinMse.Y_Pos));: _Source 0
_FreeImage tempimage
_Display
Loop

I don't know if TSR is the proper term for this type of program nowadays, but back in the yesteryears of the past these type of tools were called Terminate and Stay Resident programs.

Not that without a title bar and without any easy exit commands, this little program doesn't terminate and quit very easily on you now. You'll probably need to go into task manager to manually stop it, so keep that in mind. If you're not comfortable with manual program stopping then... why the heck are you into programming? Tongue

This works just like before except I've made some important changes here.

1)To start with, this loads and runs and behaves exactly as the other version...
2)..until you hit CTRL-ALT-K (for Kolor Picker), where it will then hide itself and disappear completely off your computer...
3)..until you hit CTRL-ALT-K once again, where the tool will instantly reappear at command and be usable once more.

Configure this to run in your windows startup and from now on, you'll always have a handle little CTRL-ALT-K color picker available for use on your machine!



So why is this here instead of in the other topic?

Basically so folks will take the time to read the fact that this doesn't ever terminate on its own. Start it up and it'll stay in your task list and do its thing forever more unless you manually close it yourself.

For me, this is a system tool which I can make use of to always be able to grab the color code from whatever I see on my monitor. My personal plan is just to pop this into windows startup and then it'll just always be an extended system tool for me. I thought others might like the same (or at least to see how to do the same so they could write similar little programs for themselves.)

For anyone who isn't familiar with how to make a program startup in windows, see the quick write up here: https://www.howtogeek.com/208224/how-to-...in-windows

Any questions, just ask. Wink
Reply
#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
#3
Or you can add the following line to end the program with CTRL + ALT + Q.  Big Grin

Code: (Select All)
If GetAsyncKeyState(&H11) _Andalso GetAsyncKeyState(&H12) _Andalso GetAsyncKeyState(&H51) Then System
Reply
#4
+1 Big Grin 

Pete
Shoot first and shoot people who ask questions, later.
Reply
#5
(01-24-2025, 05:58 PM)Steffan-68 Wrote: Or you can add the following line to end the program with CTRL + ALT + Q.  Big Grin

Code: (Select All)
If GetAsyncKeyState(&H11) _Andalso GetAsyncKeyState(&H12) _Andalso GetAsyncKeyState(&H51) Then System

I'd thought of doing something similar as well, but Windows has so many dang reserved keys and key combos, and then Word and Explorer and everything else has key combos reserved...  In the end, I decided to keep my fingerprint as simple as possible and not not take another key combo for a possible conflict on anyone's system.

The method I tend to use for termination (if I really want to terminate it) is:
1)CTRL-ALT-K to pop up the display with the hex values.
2)At this point there should be an icon down on the task bar representing it.  Right click it and then "End Task".

But with the minimal resources it uses, I don't think I'll ever really need to bother to terminate it completely.  I like the idea of a quick and simple pop-up to get a color value for anything on my screen. 

(I'm still debating a CTRL-ALT-Right Click, or such, to trigger a "copy to clipboard" event for myself, so it'll store that value and I won't have to remember it and type it in elsewhere, but that too is debatable just for the number of already reserved combos and I'm not certain I'd actually want to overwrite my clipboard contents for something so minor.  At most, it's just 8 letters to remember...)
Reply
#6
Alt + F4 is my go to for closing a program. Of course you'd better be certain the window you want to close is active.

Pete
Reply




Users browsing this thread: 3 Guest(s)