?? combodemodlg.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 + -