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

📄 controltestdlg.cpp

📁 《VC++ 编程技巧与示例 .rar》各个示例代码绝对可用
💻 CPP
字号:
// ControlTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ControlTest.h"
#include "ControlTestDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlTestDlg dialog

CControlTestDlg::CControlTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CControlTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CControlTestDlg)
	m_Male="男士";
	m_bUseList=FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_ImageAdded=FALSE;
	m_ImageList=new CImageList;

}


CControlTestDlg::~CControlTestDlg()
{
	if(m_ImageList)
	{
		delete m_ImageList;
	}
}

void CControlTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CControlTestDlg)
	DDX_Control(pDX, IDC_USELIST, m_UseList);
	DDX_Control(pDX, IDC_EDIT_NAME, m_Name);
	DDX_Control(pDX, IDC_EDIT_AGE, m_Age);
	DDX_Control(pDX, IDC_DATETIMEPICKER, m_Date);
	DDX_Control(pDX, IDC_PLAY, m_BtnPlay);
	DDX_Control(pDX, IDC_TREE, m_Tree);
	DDX_Control(pDX, IDC_CAREER, m_Career);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CControlTestDlg, CDialog)
	//{{AFX_MSG_MAP(CControlTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_FEMALE, OnFemale)
	ON_BN_CLICKED(IDC_MALE, OnMale)
	ON_BN_CLICKED(IDC_VIEW_INFO, OnViewInfo)
	ON_BN_CLICKED(IDC_USELIST, OnUselist)
	ON_CBN_EDITCHANGE(IDC_CAREER, OnEditchangeCareer)
	ON_CBN_EDITUPDATE(IDC_CAREER, OnEditupdateCareer)
	ON_CBN_SELCHANGE(IDC_CAREER, OnSelchangeCareer)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlTestDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	// TODO: Add extra initialization here
	CButton * Radio;
	Radio=(CButton *)GetDlgItem(IDC_MALE);
	Radio->SetCheck(1);

//	m_ListCtrlDlg.m_ImageList.Create(IDB_PLAY_UP,32,2,RGB(255,255,255));
	initialtree();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CControlTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CControlTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CControlTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CControlTestDlg::OnPlay() 
{
	// TODO: Add your control notification handler code here
	m_FilmDlg.DoModal();
}

void CControlTestDlg::OnFemale() 
{
	// TODO: Add your control notification handler code here
	m_Male="女士";
}

void CControlTestDlg::OnMale() 
{
	// TODO: Add your control notification handler code here
	m_Male="男士";
}

void CControlTestDlg::OnViewInfo() 
{
	// TODO: Add your control notification handler code here
	CString str;

	if(m_UseList.GetCheck())
	{
		m_Age.GetWindowText(str);
		m_ListBoxDlg.m_Age=str;

		CTime time;
		m_Date.GetTime(time);
		m_ListBoxDlg.m_Date=time;

		m_ListBoxDlg.m_Male=m_Male;

		m_Name.GetWindowText(str);
		m_ListBoxDlg.m_Name=str;
		
		m_ListBoxDlg.m_Career=m_listitem;

		m_ListBoxDlg.m_treeitem=m_treeitem;
		

		m_ListBoxDlg.DoModal();
		m_BtnPlay.EnableWindow(FALSE);
	}
	else
	{
		m_Age.GetWindowText(str);
		m_ListCtrlDlg.m_Age=str;

		CTime time;
		m_Date.GetTime(time);
		m_ListCtrlDlg.m_Date=time;

		m_ListCtrlDlg.m_Male=m_Male;

		m_Name.GetWindowText(str);
		m_ListCtrlDlg.m_Name=str;

		
		m_ListCtrlDlg.m_Career=m_listitem;

		m_ListCtrlDlg.m_treeitem=m_treeitem;

		m_ListCtrlDlg.DoModal();
		m_BtnPlay.EnableWindow();
	}
}

void CControlTestDlg::OnUselist() 
{
	// TODO: Add your control notification handler code here
	if(m_bUseList)
	{
		m_bUseList=!m_bUseList;
		m_UseList.SetCheck(0);
	}
	else
	{
		m_bUseList=!m_bUseList;
		m_UseList.SetCheck(1);
	}
}

void CControlTestDlg::OnEditchangeCareer() 
{
	// TODO: Add your control notification handler code here
	int index=0;
	index=m_Career.GetCurSel();
	m_Career.GetLBText(index,m_listitem);
	
	

}

void CControlTestDlg::OnEditupdateCareer() 
{
	// TODO: Add your control notification handler code here
	int index=0;
	index=m_Career.GetCurSel();
	m_Career.GetLBText(index,m_listitem);
}

void CControlTestDlg::OnSelchangeCareer() 
{
	// TODO: Add your control notification handler code here
	int index=0;
	index=m_Career.GetCurSel();
	m_Career.GetLBText(index,m_listitem);
}

void CControlTestDlg::initialtree()
{
	CString str;
	HTREEITEM hTreeItem;

	if(!m_ImageAdded)
	{
		CBitmap bmp,sbmp;
		bmp.LoadBitmap(IDB_TREEDRAFT);
//		sbmp.LoadBitmap(IDB_SLISTDRAFT);
		m_ImageList->Create(16,16,FALSE,1,0);
		m_ImageList->Add(&bmp,RGB(0,0,0));
//		m_ImageListSmall->Create(16,16,FALSE,1,0);
//		m_ImageListSmall->Add(&sbmp,RGB(0,0,0));
		m_ImageAdded=TRUE;
	}
	m_Tree.SetImageList(m_ImageList,LVSIL_NORMAL);
//	m_ListCtrl.SetImageList(m_ImageListSmall,LVSIL_SMALL);


	str="体育运动";
	hTreeItem=m_Tree.InsertItem(str,0,1);
	str="足球";
	m_Tree.InsertItem(str,2,3,hTreeItem);
	str="排球";
	m_Tree.InsertItem(str,4,5,hTreeItem);
	str="篮球";
	m_Tree.InsertItem(str,6,7,hTreeItem);
	str="文娱运动";
	hTreeItem=m_Tree.InsertItem(str,8,9);
	str="阅读";
	m_Tree.InsertItem(str,10,11,hTreeItem);
	str="听音乐";
	m_Tree.InsertItem(str,12,13,hTreeItem);
	str="舞蹈";
	m_Tree.InsertItem(str,14,15,hTreeItem);
}

void CControlTestDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	HTREEITEM hTreeItem;
	hTreeItem=m_Tree.GetSelectedItem();
	m_treeitem=m_Tree.GetItemText(hTreeItem);
	
	*pResult = 0;
}

⌨️ 快捷键说明

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