QB64 Phoenix Edition
Color Picker - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: SMcNeill (https://qb64phoenix.com/forum/forumdisplay.php?fid=29)
+---- Thread: Color Picker (/showthread.php?tid=3409)



Color Picker - SMcNeill - 01-22-2025

One of my most useful little ten minute programs that I've came up with for a while, though this is for Windows Only:

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
Do
_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 Until GetAsyncKeyState(1) Or GetAsyncKeyState(2) Or GetAsyncKeyState(27)
System

Run it. Move the mouse around your screen. I think you can tell fairly quickly and easily what it does for you.


RE: Color Picker - Pete - 01-22-2025

I'm having trouble running it full screen. Big Grin Big Grin Big Grin

I made a few similar Win32 API utilities, but I never thought of a color-picker, nice!

+1

Pete


RE: Color Picker - bplus - 01-22-2025

color picker or color reporter?

It is interesting. Could be handy.


RE: Color Picker - grymmjack - 01-22-2025

Nice color picker @SMcNeill!


RE: Color Picker - SMcNeill - 01-22-2025

What would be nice is if I could minimize it to the icon tray on the lower right corner and then configure it to pop-up/close with a set of hotkeys.  I don't want it minimized and stuck on the task bar, but as an icon in the tray, it'd be a nice TSR tool to make use of whenever I wanted to know the color code for whatever was on the screen. 

Anyone have a clue how to register and minimize to the system tray?  And perhaps a working demo?  I'd love to see it sometime if so.


RE: Color Picker - Pete - 01-22-2025

@SMcNeill

Step 1) Right click the exe file. In the menu, click: Pin to Taskbar.

Step 2) Move it in your Task Bar so it is no more than 10 icons from the left. Let's say it is #8.

Step 3) Hold the Windows key and press the number 8.

That will open it. Unfortunately, I do not believe repeating the Win + 8 will toggle it closed. Sorry.

Pete


RE: Color Picker - SMcNeill - 01-23-2025

(Yesterday, 11:58 PM)Pete Wrote: @SMcNeill

Step 1) Right click the exe file. In the menu, click: Pin to Taskbar.

Step 2) Move it in your Task Bar so it is no more than 10 icons from the left. Let's say it is #8.

Step 3) Hold the Windows key and press the number 8.

That will open it. Unfortunately, I do not believe repeating the Win + 8 will toggle it closed. Sorry.

Pete

I'm not talking about the taskbar itself, but the icon tray in the lower corner:


[Image: image.png]

(Click the image above to expand it.  You can see the icons down in the little pop-up area in the corner.)  <-- That's the functionality I'm talking about.

I'm thinking it'd have to be done via https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyicona

I'm just not certain how to do it without an example to go by that I can build off of.  Tongue


RE: Color Picker - Pete - 01-23-2025

Oh, the system tray. In my Win 10, I need to click the ^ symbol to pull that up...

[Image: maxresdefault.jpg]

You might need third party software to set that up. Here's an article I found:

https://umatechnology.org/how-to-minimize-programs-to-the-windows-system-tray-with-hotkeys/

Might be worth a look if no one comes along with a native way to do it.

Pete