After developing applications and web pages for a while, I came to a point where I realized a major gap exists in the typical programming paradigm in that visualizing fine-grained color values in code was almost impossible unless you happen to use a WYSIYYG or RAD environment. And that there are still plenty of circumstances where such an environment will still be used.
Even the notion of HTML's naming colors never really helped because it only applied to basic values (i.e.,
<body bgcolor="white">), or had some obscure name that nobody even knows what it is. Lastly, most developers already know the basic colors, like RGB 255, 255, 255 equals white, RGB 0, 255, 255 equals cyan, etc.
This still begs the question, what if you want to see a color, perhaps coordinate a color in an environment-independent manner that was quick to use and allowed for easy copy and pasting for a pseudo integration mechanism. And, regardless of my editor of choice I would always have a means to do this. Thus, Colorz was born.
What Colorz is, is a tiny program that allows you to use three scrollbars to specify colors in the RGB color space by manipulating the R intensity, the G intensity, and the B intensity of a color while showing you what it looks like and the appropriate values, essentially allowing you to see a color in real-time while you choose it.
Although Colorz was one of the first applications of such a nature out there on the web, realistically, the idea for it is not exclusive to me. As such, my goal was to focus in on just what it is Colorz is supposed to be. With this in mind, the idea was to keep it small and lightweight to deliver just what's needed and nothing more. It has a smaller memory footprint than Notepad so it will not hog system resources.
This program has made my life a little easier numerous times. If it helps me, I hope it'll help someone else out there in cyberspace. And maybe, some will learn from it. Enjoy!
This program demonstrates what is involved in writing a dialog-based application for Windows® using nothing but C and the Windows API. It further explores concepts pertaining to the GDI, with a focus on device contexts and bit block transfers. And, it shows how to manipulate the clipboard.
There was a workaround needed for the "Grab Color" feature. The reason being is that I used the
GetPixel function for it; therefore, if you have coordinates for a non-client area in a window, it returns
-1. This is not a valid color, so I used
BitBlt to rectify the problem by copying the pixel to a static control and then using
GetPixel on the control, thus returning a valid color. The following code demonstrates this technique.
hWndxy = WindowFromPoint(spoint);
hPreview = GetDlgItem(hWnd,IDC_STATIC_PREVIEW);
hDC = GetDC(hWndxy);
rgb = GetPixel(hDC, cursor.x, cursor.y);
if(rgb == -1)
HDC hDCPrev = GetDC(hPreview);
BitBlt(hDCPrev, 0, 0, 1, 1, hDC,
cursor.x, cursor.y, SRCCOPY);
rgb = GetPixel(hDCPrev, 0, 0);
This program uses a function called
MoveWnd to center the window when the program starts. This function originated as
CenterWindow, and was found in an excellent book named "Win32 Programming" by Brent E. Rector and Joseph M. Newcomer. I rewrote the function to fix a couple of things, add extra functionality, and I renamed it in the process.
I wrote the remains of the program from scratch with the assistance of the ever popular MSDN Library and knowledge acquired from "Win32 Programming".