// ColorPick.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "ColorPick.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
#include "math.h"
HBITMAP hBitMap = NULL;
DWORD HSV2RGB(float h, float s, float v)
{
DWORD dwRGB = 0x00000000;
float r , g , b;
float i, f, p, q, t;
r = g = b = 0.0f;
if ( s == 0.0f )
{
if ( v != 0.0f )
{
DWORD channel = static_cast<DWORD>(v * 255);
dwRGB = channel << 16 | channel << 8 | channel;
}
}
else
{
if ( h == 360.0f )
{
h = 0.0f;
}
h /= 60.0f;
i = floor(h);
f = h - i;
p = v * ( 1.0f - s );
q = v * ( 1.0f - ( s * f ) );
t = v * ( 1.0f - ( s * ( 1.0f - f) ) );
if ( i == 0.0f )
{
r = v;
g = t;
b = p;
}
else if ( i == 1.0f )
{
r = q;
g = v;
b = p;
}
else if ( i == 2.0f )
{
r = p;
g = v;
b = t;
}
else if ( i == 3.0f )
{
r = p;
g = q;
b = v;
}
else if ( i == 4.0f )
{
r = t;
g = p;
b = v;
}
else if ( i == 5.0f )
{
r = v;
g = p;
b = q;
}
dwRGB = RGB(static_cast<DWORD>(r * 255), static_cast<DWORD>(g * 255), static_cast<DWORD>(b * 255));
}
return dwRGB;
}
void DrawHSIRect(HDC hDc, RECT& Rect)
{
float fStep;
int i;
fStep = 360.0f / 255.0f;
for ( i = 0; i < 256; i++ )
{
for (int t = Rect.top; t < Rect.bottom; t++)
::SetPixel(hDc, Rect.left + i, t, HSV2RGB(fStep * i, 1.0f, 1.0f));
}