用VC写了个颜色选取框,仿Office风格,没用MFC什么的框架,调用很简单指定显示位置POINT和默认颜色就可以 ,如:
POINT pt;
pt.x = 100; pt.y = 100;
CColorPicker *clrpk = new CColorPicker(&pt, HexClr(0xFF0000));
效果图:
代码:
ColorPicker.h
#define
HexClr(rgb) ((DWORD)(rgb>>16)|(rgb&0xFF00)|((rgb&0xFF)<<16))
#define COLORPICKERWINNAME "ColorPickerWin"
#define WM_COLORSELECTED WM_USER+2938
static DWORD ColorMap[ 5 ][ 8 ] =
... {
...{ HexClr(0x000000), HexClr(0x993300), HexClr(0x333300), HexClr(0x003300), HexClr(0x003366), HexClr(0x000080), HexClr(0x333399), HexClr(0x333333)},
...{ HexClr(0x800000), HexClr(0xFF6600), HexClr(0x808000), HexClr(0x008000), HexClr(0x008080), HexClr(0x0000FF), HexClr(0x666699), HexClr(0x808080)},
...{ HexClr(0xFF0000), HexClr(0xFF9900), HexClr(0x99CC00), HexClr(0x008080), HexClr(0x33CCCC), HexClr(0x3366FF), HexClr(0x800080), HexClr(0x999999)},
...{ HexClr(0xFF00FF), HexClr(0xFFCC00), HexClr(0xFFFF00), HexClr(0x00FF00), HexClr(0x00FFFF), HexClr(0x00CCFF), HexClr(0x993366), HexClr(0xC0C0C0)},
...{ HexClr(0xFF99CC), HexClr(0xFFCC99), HexClr(0xFFFF99), HexClr(0xCCFFCC), HexClr(0xCCFFFF), HexClr(0x99CCFF), HexClr(0xCC99FF), HexClr(0xFFFFFF)}
} ;
class CColorPicker
... {
public:
HINSTANCE m_hInstance; //debug
CColorPicker(POINT *pt, DWORD DefaultColor);
~CColorPicker();
HWND GetHwnd();
DWORD GetColor();
void OnPaint();
void OnLButtonDown(long x, long y);
void OnLButtonUp(long x, long y);
void OnMouseMove(long x, long y);
private:
HWND m_hwnd;
DWORD m_Color;
byte m_HotRow, m_HotCol;
bool m_bCustomColor;
bool m_bMouseDown;
void CreateColorPicker(POINT *pt);
void Draw(HDC hdc, byte row, byte col, bool hot, byte correction);
void ReDraw(byte row, byte col, bool hot);
} ;
#define COLORPICKERWINNAME "ColorPickerWin"
#define WM_COLORSELECTED WM_USER+2938
static DWORD ColorMap[ 5 ][ 8 ] =
... {
...{ HexClr(0x000000), HexClr(0x993300), HexClr(0x333300), HexClr(0x003300), HexClr(0x003366), HexClr(0x000080), HexClr(0x333399), HexClr(0x333333)},
...{ HexClr(0x800000), HexClr(0xFF6600), HexClr(0x808000), HexClr(0x008000), HexClr(0x008080), HexClr(0x0000FF), HexClr(0x666699), HexClr(0x808080)},
...{ HexClr(0xFF0000), HexClr(0xFF9900), HexClr(0x99CC00), HexClr(0x008080), HexClr(0x33CCCC), HexClr(0x3366FF), HexClr(0x800080), HexClr(0x999999)},
...{ HexClr(0xFF00FF), HexClr(0xFFCC00), HexClr(0xFFFF00), HexClr(0x00FF00), HexClr(0x00FFFF), HexClr(0x00CCFF), HexClr(0x993366), HexClr(0xC0C0C0)},
...{ HexClr(0xFF99CC), HexClr(0xFFCC99), HexClr(0xFFFF99), HexClr(0xCCFFCC), HexClr(0xCCFFFF), HexClr(0x99CCFF), HexClr(0xCC99FF), HexClr(0xFFFFFF)}
} ;
class CColorPicker
... {
public:
HINSTANCE m_hInstance; //debug
CColorPicker(POINT *pt, DWORD DefaultColor);
~CColorPicker();
HWND GetHwnd();
DWORD GetColor();
void OnPaint();
void OnLButtonDown(long x, long y);
void OnLButtonUp(long x, long y);
void OnMouseMove(long x, long y);
private:
HWND m_hwnd;
DWORD m_Color;
byte m_HotRow, m_HotCol;
bool m_bCustomColor;
bool m_bMouseDown;
void CreateColorPicker(POINT *pt);
void Draw(HDC hdc, byte row, byte col, bool hot, byte correction);
void ReDraw(byte row, byte col, bool hot);
} ;
#include
<
stdafx.h
>
#include " ColorPicker.h "
WNDPROC ColorPickerWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
... {
CColorPicker* lpColorPicker = (CColorPicker*)GetWindowLong(hwnd, GWL_USERDATA);
if (!lpColorPicker) return (WNDPROC)DefWindowProc(hwnd, msg, wParam, lParam);
/*========================================================================
作者: 彭国辉
DATE: 2007-12-25
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton( at )sohu.com
#include " ColorPicker.h "
WNDPROC ColorPickerWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
... {
CColorPicker* lpColorPicker = (CColorPicker*)GetWindowLong(hwnd, GWL_USERDATA);
if (!lpColorPicker) return (WNDPROC)DefWindowProc(hwnd, msg, wParam, lParam);
/*========================================================================
作者: 彭国辉
DATE: 2007-12-25
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton( at )sohu.com
文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
=========================================================================*/
switch (msg)
... {
=========================================================================*/
switch (msg)
... {