// MyNewAlbumDlg.cpp : implementation file // #include "stdafx.h" #include "myAlbum.h" #include "MyNewAlbumDlg.h" #include "MyAlbumDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMyNewAlbumDlg dialog CMyNewAlbumDlg::CMyNewAlbumDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyNewAlbumDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyNewAlbumDlg) m_music = _T(""); m_name = _T(""); m_photo = _T(""); //}}AFX_DATA_INIT m_totleNum = 0; } void CMyNewAlbumDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyNewAlbumDlg) DDX_Control(pDX, IDC_LIST1, m_list); DDX_Text(pDX, IDC_MUSIC, m_music); DDX_Text(pDX, IDC_NAME, m_name); DDX_Text(pDX, IDC_PHOTO, m_photo); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMyNewAlbumDlg, CDialog) //{{AFX_MSG_MAP(CMyNewAlbumDlg) ON_BN_CLICKED(IDC_QUITE, OnQuite) ON_BN_CLICKED(IDC_PATHMUSIC, OnPathmusic) ON_BN_CLICKED(IDC_PATHPHOTO, OnPathphoto) ON_WM_CANCELMODE() ON_WM_DELETEITEM() ON_WM_PAINT() ON_EN_KILLFOCUS(IDC_NAME, OnKillfocusName) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyNewAlbumDlg message handlers void CMyNewAlbumDlg::OnQuite() { // TODO: Add your control notification handler code here OnCancel(); } BOOL CMyNewAlbumDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here DWORD dwStyle = m_list.GetExtendedStyle(); //获取当前扩展样式 dwStyle |= LVS_EX_FULLROWSELECT; //选中某行使整行高亮(report风格时) dwStyle |= LVS_EX_GRIDLINES; //网格线(report风格时) //dwStyle |= LVS_EX_CHECKBOXES; //item前生成checkbox控件 m_list.SetExtendedStyle(dwStyle); //设置扩展风格 m_list.InsertColumn(0,"编号",LVCFMT_LEFT,40); m_list.InsertColumn(1,"路径",LVCFMT_LEFT,220); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CMyNewAlbumDlg::OnPathmusic() { // TODO: Add your control notification handler code here CString fileter = "WAV Files (*.wav)|*.wav"; CFileDialog dlg(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,fileter,this); char buf[256]; ::GetCurrentDirectory(256,(char *)buf); if(dlg.DoModal() == IDOK) { m_music = dlg.GetPathName(); UpdateData(false); } ::SetCurrentDirectory(buf); } void CMyNewAlbumDlg::OnPathphoto() { // TODO: Add your control notification handler code here CString fileter = "JPG Files(*.jpg;*.jpeg)|*.jpg;*.jpeg|BITMAP Files (*.bmp)|*.bmp|(*.*)|*.*||"; CFileDialog dlg(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,fileter); char buf[256]; ::GetCurrentDirectory(256,(char *)buf); if(dlg.DoModal() == IDOK) { m_photo = dlg.GetPathName(); UpdateData(false); CString str; str.Format("%d",m_totleNum + 1); m_list.InsertItem(m_totleNum,str); m_list.SetItemText(m_totleNum,1,m_photo); m_path[m_totleNum] = m_photo; UpdateData(false); wchar_t *wImage; int len; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_photo, -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_photo, -1, wImage, len); m_image[m_totleNum] = Image::FromFile(wImage); delete []wImage; m_totleNum++; Invalidate(); } ::SetCurrentDirectory(buf); } void CMyNewAlbumDlg::OnPaint() { CPaintDC dc(this); // device context for painting CDC dcMemory; dcMemory.CreateCompatibleDC(NULL); CRect bkRect; GetClientRect(&bkRect); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, bkRect.Width(), bkRect.Height()); COLORREF color = GetSysColor(COLOR_3DFACE); SelectObject(dcMemory.GetSafeHdc(), bitmap) ; dcMemory.FillSolidRect(bkRect,color); Graphics g(dcMemory.m_hDC); Image bk_image(L"背景\\bg001.bmp"); g.DrawImage(&bk_image,bkRect.left,bkRect.top,bkRect.Width(),bkRect.Height()); for(int i = 0; i < m_totleNum; i++) { g.DrawImage(m_image[i],305 + ((i%5)*120),55 + (i / 5)*120,100,100); } dc.BitBlt(0,0,bkRect.Width(),bkRect.Height(),&dcMemory,0,0,SRCCOPY); CDialog::OnPaint(); } void CMyNewAlbumDlg::OnCancelMode() { CDialog::OnCancelMode(); // TODO: Add your message handler code here } void CMyNewAlbumDlg::OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct) { // TODO: Add your message handler code here and/or call default CDialog::OnDeleteItem(nIDCtl, lpDeleteItemStruct); } void CMyNewAlbumDlg::OnOK() { // TODO: Add extra validation here CDialog::OnOK(); } void CMyNewAlbumDlg::OnKillfocusName() { // TODO: Add your control notification handler code here UpdateData(); }