最好能给个思路,提供源代码的话再给散100分。
解决方案 »
- 为什么啊?这3D编辑器外观是2条线框?
- 请问谁用过 duilib ??
- mciSendCommand函数播放AVI出错
- 做了个基于对话框程序 ,创建了一个子线程 用于接收数据如何通过 postmessage将 得到数据发送给对话框啊?
- VC++中资源resource文件夹下的右键的插入和引入有什么区别?麻烦点拨一下。
- 请问strcpy();这个函数?
- 用CWebBrowser2如何处理弹窗问题,还有一个代理问题,100分,不够再开贴加
- 在listctrl中sortItems所用的排序算法是什么啊?
- 我用InstallShield for vc++6.0 将程序进行打包制作,可是为什么没有生成相应的应用程序?还是不能移植,请指点!
- 小问题,急!小问题,急!
- 什么时候用FREELIBRARY合适
- 急!!在线请教串口通信方面的问题!(利用串口将音乐从电脑下载到手机上面)!100分!!
#if !defined(AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__INCLUDED_)
#define AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ColorPicker.h : header file
///////////////////////////////////////////////////////////////////////////////
// CColorPicker windowclass CColorPicker : public CWnd
{
// Construction
public:
CColorPicker();
UINT m_nStyle;
// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColorPicker)
public:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
//}}AFX_VIRTUAL// Implementation
public:
COLORREF GetColor();
virtual ~CColorPicker(); // Generated message map functions
protected:
//{{AFX_MSG(CColorPicker)
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
COLORREF color[25];
COLORREF m_color;
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__INCLUDED_)
//#include "stdafx.h"#include "ColorPicker.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CColorPickerCColorPicker::CColorPicker()
{m_color=RGB(0,0,0);color[0]=RGB(0,0,0);
color[1]=RGB(128,0,0);
color[2]=RGB(0,128,0);
color[3]=RGB(128,128,0);
color[4]=RGB(0,0,128);
color[5]=RGB(128,0,128);
color[6]=RGB(0,128,128);
color[7]=RGB(192,192,192);
color[8]=RGB(192,220,192);
color[9]=RGB(166,202,240);
color[10]=RGB(255,251,240);
color[11]=RGB(160,160,164);
color[12]=RGB(128,128,128);
color[13]=RGB(255,0,0);
color[14]=RGB(0,255,0);
color[15]=RGB(255,255,0);
color[16]=RGB(0,0,255);
color[17]=RGB(255,0,0);
color[18]=RGB(255,0,255);
color[19]=RGB(0,255,255);
color[20]=RGB(255,255,255);
}CColorPicker::~CColorPicker()
{
}
BEGIN_MESSAGE_MAP(CColorPicker, CWnd)
//{{AFX_MSG_MAP(CColorPicker)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorPicker message handlersBOOL CColorPicker::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_nStyle = dwStyle;
if (CWnd::Create(AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, AfxGetApp()->LoadStandardCursor(IDC_ARROW), (HBRUSH)GetStockObject(LTGRAY_BRUSH), NULL),
NULL,
dwStyle&~ WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
rect,
pParentWnd,
nID))
return TRUE;
return FALSE; return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}void CColorPicker::OnPaint()
{
CPaintDC dc(this); // device context for painting
CBitmap bmp;
CDC mDC;
CRect rect;
CBrush br;
// CBrush *pr;
int index=0;
this->GetClientRect(&rect);
mDC.CreateCompatibleDC(&dc);
long x1=rect.left+rect.Width()/10,y1=rect.top,x2=rect.right-rect.Width()/10,y2=rect.bottom;
bmp.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
if(bmp.GetSafeHandle()==NULL){AfxMessageBox("内存不足无法显示图形");return;}//用于判断是否生成位图
mDC.SelectObject(&bmp);
mDC.PatBlt(0,0,rect.Width(),rect.Height(),WHITENESS);
for(int i=x1;i<x2;i+=(x2-x1)/10)
for(int j=y1;j<y2;j+=rect.Height()/2)
{ br.CreateSolidBrush(color[index]);
mDC.SelectObject(&br);
mDC.Rectangle(CRect(i,j,i+rect.Width()/10,j+rect.Height()/2));
index++;
br.DeleteObject();
}
br.CreateSolidBrush(m_color);
mDC.SelectObject(&br);
mDC.Rectangle(CRect(0,0,rect.Width()/11,rect.Height()));
br.DeleteObject();
dc.BitBlt(0,0,rect.Width(),rect.Height(),&mDC,0,0,SRCCOPY);
// TODO: Add your message handler code here
bmp.DeleteObject();
mDC.DeleteDC();//使用内存绘图防止闪烁
// Do not call CWnd::OnPaint() for painting messages
}void CColorPicker::OnLButtonDown(UINT nFlags, CPoint point)
{CRect rect;
//this->ClientToScreen(&point);
this->GetClientRect(&rect);
int step=0;
long x1=rect.left+rect.Width()/10,y1=rect.top,x2=rect.right-rect.Width()/10,y2=rect.bottom;
for(int i=x1;i<x2;i+=(x2-x1)/10)
for(int j=y1;j<y2;j+=rect.Height()/2)
{
if(point.x>i&&point.x<i+(x2-x1)/10
&&point.y>j&&point.y<j+rect.Height()/2)
{
m_color=color[step];//+(step)*519500;
}
step++;
}
this->Invalidate(); CWnd::OnLButtonDown(nFlags, point);
}void CColorPicker::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CColorDialog dlg;
if(dlg.DoModal() == IDOK)
{m_color = dlg.GetColor();}
this->Invalidate();
CWnd::OnLButtonDblClk(nFlags, point);
}COLORREF CColorPicker::GetColor()
{return m_color;}
BOOL CColorPicker::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return false;
//return CWnd::OnEraseBkgnd(pDC);
}
用按钮,上面的程序对你会有一些帮助