Environment: Win32 API (no MFC)
This is a GPL/LGPL color picker demo based on a custom color selector. I coded it as a part of a Win32 server that I use in my graphics apps. It’s pure Win32 API C++ and it should compile with VC++ 6.0. For your convenience, there are precompiled binaries in the ‘bin’ folder.
To Implement the Picker
- Build ‘server_win.lib’ and ‘server_util.lib’ (with the appropriate DLLs).
- Include ‘server_win.h’ and ‘server_util.h’ into your source code.
- Make a reference to the picker’s global instance:
- Call the picker where you want it to appear:
"c_colorpick& <yourpicker> = colorpick;"
"COLORREF rgb = <yourpicker>.getcolor(<handle to owner window>);"
The function above returns -1 when ‘Cancel’ is pressed.
To Get the Picker’s Settings
- Declare an instance of color-info structure:
- When the picker returns, obtain the above values by calling:
- Then you can save these values into a file so that all settings can be loaded when the app starts again. How it could be done is shown in the “bool writeini()” function in ‘colpick_main.cpp’.
This structure will hold the color space type, palette saturation range, and custom colors.
To Initialize the Picker to the Last-Saved Settings
- Load the file you`ve saved in the previous section and fill in the <yourinfo> structure.
- Before you call the picker, make a call:
- Your picker should be initialized. (For details, look at “bool readini()” and “WinMain()” in ‘colpick_main.cpp’.)
When using numeric input of HSL or HSV, the entered value sometimes skips down by 1. For example, if you insert 180, the value skips to 179. This is probably due to running the entered value through the whole conversion routine; that might be inexact.