WEB开发网
开发学院软件开发VC C++实现仿Office风格的颜色选取框代码 阅读

C++实现仿Office风格的颜色选取框代码

 2010-08-22 20:47:08 来源:WEB开发网   
核心提示:用VC写了个颜色选取框,仿Office风格用VC写了个颜色选取框,C++实现仿Office风格的颜色选取框代码,仿Office风格,没用MFC什么的框架,调用很简单指定显示位置POINT和默认颜色就可以,如:POINT pt;pt.x = 100; pt.y = 100;CColorPicker *clrpk = ne

用VC写了个颜色选取框,仿Office风格用VC写了个颜色选取框,仿Office风格,没用MFC什么的框架,调用很简单指定显示位置POINT和默认颜色就可以,如:

POINT pt;

pt.x = 100; pt.y = 100;

CColorPicker *clrpk = new CColorPicker(&pt, HexClr(0xFF0000));

效果图:

C++的颜色拾取框

代码:

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);
};

1 2  下一页

Tags:实现 Office 风格

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接