控件实战技巧笔记

来源:互联网 发布:地方门户 php 编辑:程序博客网 时间:2024/04/29 11:58
// Test00001Dlg.cpp : implementation file
//


#include "stdafx.h"
#include "Test00001.h"
#include "Test00001Dlg.h"




#ifdef _DEBUG
#define new DEBUG_NEW
#endif




// CAboutDlg dialog used for App About


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


// Dialog Data
enum { IDD = IDD_ABOUTBOX };


protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation
protected:
DECLARE_MESSAGE_MAP()
};


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


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


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()




// CTest00001Dlg dialog








CTest00001Dlg::CTest00001Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest00001Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CTest00001Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, m_ComBox);
DDX_Control(pDX, IDC_LIST1, m_ListBox);




DDX_Control(pDX, IDC_LIST_NUMBER, m_UserList);
DDX_Control(pDX, IDC_LIST3, m_DataList);
DDX_Control(pDX, IDC_TREE2, m_Orginfo);
}


BEGIN_MESSAGE_MAP(CTest00001Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CTest00001Dlg::OnBnClickedOk)
// ON_CBN_SELCHANGE(IDC_COMBO1, &CTest00001Dlg::OnCbnSelchangeCombo1)
ON_BN_CLICKED(IDC_BUTTON_SEL, &CTest00001Dlg::OnBnClickedButtonSel)
ON_BN_CLICKED(IDC_BUTTON2, &CTest00001Dlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON_SelBtn, &CTest00001Dlg::OnBnClickedButtonSelbtn)
ON_BN_CLICKED(IDC_BUTTON_MUSICOPEN, &CTest00001Dlg::OnBnClickedButtonMusicopen)
ON_BN_CLICKED(IDC_BUTTON_LOGIN, &CTest00001Dlg::OnBnClickedButtonLogin)
END_MESSAGE_MAP()




// CTest00001Dlg message handlers


BOOL CTest00001Dlg::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
m_ListBox.InsertString(0,_T("海定区"));
m_ListBox.InsertString(1,_T("朝阳区"));
m_ListBox.InsertString(2,_T("通州区"));
m_ListBox.InsertString(3,_T("东城区"));
m_ListBox.InsertString(4,_T("西城区"));
m_ListBox.InsertString(5,_T("石景山区"));
//Listctrl显示数据和图标;
m_ImageList.Create(32,32,ILC_COLOR32|ILC_MASK,1,0);
m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1)));
m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2)));
m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3)));
m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4)));
m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5)));






m_UserList.SetImageList(&m_ImageList,LVSIL_NORMAL);//项列表视图中添加数据;关联图像图标;
m_UserList.InsertItem(0,_T("lisi"),0);
m_UserList.InsertItem(1,_T("zhangsan"),1);
m_UserList.InsertItem(2,_T("wangwu"),2);
m_UserList.InsertItem(3,_T("zhaoliu"),3);
m_UserList.InsertItem(4,_T("zhouqi"),4);




//TreeCtrl显示图标和子树;
m_Orginfo.SetImageList(&m_ImageList,LVSIL_NORMAL);
HTREEITEM hProvice = m_Orginfo.InsertItem(_T("北京市"),0,0);//添加根节点;
HTREEITEM hTwon = m_Orginfo.InsertItem(_T("海定区"),1,1,hProvice);
HTREEITEM hhTwon = m_Orginfo.InsertItem(_T("复兴路"),2,2,hTwon);
m_Orginfo.InsertItem(_T("朝阳区"),1,1,hProvice);
m_Orginfo.InsertItem(_T("东城区"),1,1,hProvice);
m_Orginfo.InsertItem(_T("西城区"),1,1,hProvice);
m_Orginfo.InsertItem(_T("昌平区"),1,1,hProvice);
m_Orginfo.InsertItem(_T("大兴区"),1,1,hProvice);
m_Orginfo.InsertItem(_T("五棵松"),2,2,hTwon);
m_Orginfo.InsertItem(_T("八角"),2,2,hTwon);
m_Orginfo.InsertItem(_T("古城"),2,2,hTwon);
m_Orginfo.InsertItem(_T("玉泉"),2,2,hTwon);
m_Orginfo.InsertItem(_T("老山"),2,2,hTwon);
m_Orginfo.InsertItem(_T("永定路东"),3,3,hhTwon);
m_Orginfo.InsertItem(_T("永定路西"),3,3,hhTwon);
m_Orginfo.InsertItem(_T("永定路南"),3,3,hhTwon);
m_Orginfo.InsertItem(_T("永定路北"),3,3,hhTwon);
m_Orginfo.SetTextColor(RGB(0,0,255));














//Listctrl表格显示数据;
m_DataList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);//设置扩展风格;
m_DataList.InsertColumn(0,_T("姓名"),LVCFMT_LEFT,50);//添加一列;
m_DataList.InsertColumn(1,_T("总成绩"),LVCFMT_LEFT,50);
m_DataList.InsertItem(0,_T("小米"),0);//添加一行;
m_DataList.SetItemText(0,1,_T("99"));//设置列文本;
m_DataList.InsertItem(1,_T("晓明"),1);
m_DataList.SetItemText(1,1,_T("98"));
m_DataList.InsertItem(2,_T("小ling"),2);
m_DataList.SetItemText(2,1,_T("97"));
m_DataList.InsertItem(3,_T("xiaoxiao"),3);
m_DataList.SetItemText(3,1,_T("96"));








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


void CTest00001Dlg::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 CTest00001Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting


SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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();
CDC *pDC = GetDC();//获取对话框窗口设备的上下文;
CPoint pt;
pt.x=300;
pt.y=500;
for (int i=0;i< 5;i++)
{
pt.x+=100;
m_ImageList.Draw(pDC,i,pt,ILD_NORMAL);
}
ReleaseDC(pDC);
}
}


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




void CTest00001Dlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here


//CBook Book;
//Book.DoModal();//创建模式对话框




//m_Book.Create(IDD_DIALOG1,this);创建非正常运行的模式对话框
//m_Book.ShowWindow(SW_SHOW);


//if(IsWindow(m_Book.m_hWnd))
//{


// m_Book.Create(IDD_DIALOG1,NULL);创建正常运行的模式对话框
//}
//m_Book.ShowWindow(SW_SHOW);





//MessageBox(_T("嗬嗬嗬嗬"));
//ModifyStyleEx(0,WS_EX_TOOLWINDOW,0);//将对话框设置为工具栏风格;
//ModifyStyleEx(0,WS_EX_ACCEPTFILES,0);




SetWindowText(_T("个人爱好选择"));
CString szHabitList,szHabit;
for (int i = IDC_CHECK_FOOTBALL;i< IDC_CHECK_PINGQIU+1;i++)
{
CButton *pBtn=static_cast<CButton *>(GetDlgItem(i));
if (pBtn !=NULL)
{
if (pBtn->GetCheck()==BST_CHECKED)
{
pBtn->GetWindowText(szHabit);
szHabitList +=szHabit + _T("\r\n");
}
}
}
MessageBox(szHabitList,_T("你的爱好是"));


//OnOK();
}




void CTest00001Dlg::OnBnClickedButtonSel()
{
// TODO: Add your control notification handler code here
for (int i = IDC_RADIO_EXCELLENT;i<IDC_RADIO_FAIL+1;i++)
{
CButton *pBtn=static_cast<CButton *>(GetDlgItem(i));
if (pBtn!=NULL)
{
if (pBtn->GetCheck()==BST_CHECKED)
{
CString szText;
pBtn->GetWindowText(szText);
MessageBox(_T("等级:")+szText,_T("提示"));
break;
}
}
}
}


void CTest00001Dlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
/*CString szText;
m_ComBox.GetWindowText(szText);
MessageBox(_T("你选择的数据是:")+szText);*/
CString szText;
//m_ComBox.SetCurSel(2);
int n_index=m_ComBox.GetCurSel();
m_ComBox.GetLBText(n_index,szText);
MessageBox(_T("你选择的数据是:")+szText);
}


void CTest00001Dlg::OnBnClickedButtonSelbtn()
{
// TODO: Add your control notification handler code here


int nItemCount = m_ListBox.GetCount();
CString szContent,szTmpData;
szContent=_T("");
for (int i = 0;i < nItemCount;i++)
{
if (m_ListBox.GetCheck(i)==BST_CHECKED)
{
m_ListBox.GetText(i,szTmpData);//在列表框中选择复选框中的内容;
szContent+=szTmpData+_T("\r\n");
}
}
if (!szContent.IsEmpty())
{
MessageBox(szContent,_T("你选择的地区是:"));
}
}


void CTest00001Dlg::OnBnClickedButtonMusicopen()
{
// TODO: Add your control notification handler code here


//CFileDialog flDlg(TRUE,"","",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"mp3|*.mp3;avi|*.avi;dat|.*dat|");
//if (flDlg.DoModal()==IDOK)
//{
//CString szNameSong=flDlg.GetPathName();
// m_Per.SetUrl(szNameSong);
MessageBox(_T("你选择的歌曲目录是:"));
//}
}


void CTest00001Dlg::OnBnClickedButtonLogin()
{
// TODO: Add your control notification handler code here
int nSel= m_UserList.GetSelectionMark();
if (nSel!=-1)
{
CString szUser=m_UserList.GetItemText(nSel,0);
MessageBox(_T("hhxxhh"));
}
}
0 0
原创粉丝点击