⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combodemodlg.cpp

📁 WinCe下的字绘Combo控件
💻 CPP
字号:
// ComboDemoDlg.cpp : implementation file
//

#include "stdafx.h"

#include "ComboDemo.h"
#include "ComboDemoDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CComboDemoDlg dialog

CComboDemoDlg::CComboDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CComboDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CComboDemoDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CComboDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CComboDemoDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CComboDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CComboDemoDlg)
	ON_BN_CLICKED(IDC_ADDCLR, OnAddclr)
	ON_WM_DRAWITEM()
	ON_BN_CLICKED(IDC_CHGCLR, OnChgclr)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComboDemoDlg message handlers

BOOL CComboDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	m_clrCombo.SubclassDlgItem(IDC_CLRCOMBO, this);
	//GetDlgItem(IDC_CLRSTATIC)->ModifyStyle(0,SS_OWNERDRAW);

	return TRUE;  // return TRUE  unless you set the focus to a control
}





void CComboDemoDlg::OnAddclr() 
{
	COLORREF g_rgbBackground = RGB(255, 255, 255);
	COLORREF g_rgbCustom[16] = {0};

	CHOOSECOLOR cc = {sizeof(CHOOSECOLOR)};

    cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR;

	//CColorDialog dlg(0, CC_FULLOPEN | CC_ANYCOLOR, this);
	//int iRes=dlg.DoModal();
	CString tmpStr;
	int i=0;
	cc.hwndOwner=GetDlgItem(IDC_CLRCOMBO)->GetSafeHwnd();
	cc.rgbResult = g_rgbBackground;
    cc.lpCustColors = g_rgbCustom;
	if (ChooseColor(&cc)) //commdlg.lib 
    
	{

	COLORREF cr=cc.rgbResult;
		
	tmpStr.Format(L"R: %u, G: %u, B: %u", GetRValue(cr), GetGValue(cr), GetBValue(cr));

	m_clrCombo.SetItemData (m_clrCombo.AddString( (LPCTSTR)tmpStr ),i++);

	}
	else
	{
	}

}

void CComboDemoDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
	if (nIDCtl==IDC_CLRSTATIC)
	{
		CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
		CBrush br(m_crClrStatic);
		CRect rc=lpDrawItemStruct->rcItem;
		pDC->FillRect(&rc, &br);
	}

}

void CComboDemoDlg::OnChgclr() 
{
int nSel=m_clrCombo.GetCurSel();
	COLORREF cr=(COLORREF)m_clrCombo.GetItemData(nSel);

	if (cr!=-1)
	{
		DRAWITEMSTRUCT drawItemStruct;
		drawItemStruct.CtlID=IDC_CLRSTATIC;
		drawItemStruct.hwndItem=GetDlgItem(IDC_CLRSTATIC)->GetSafeHwnd();
		drawItemStruct.hDC=::GetDC(drawItemStruct.hwndItem);
		GetDlgItem(IDC_CLRSTATIC)->GetClientRect(&(drawItemStruct.rcItem));
		m_crClrStatic=cr;

		OnDrawItem(IDC_CLRSTATIC, &drawItemStruct);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -