// myAlbumDlg.cpp : implementation file // #include "stdafx.h" #include "myAlbum.h" #include "myAlbumDlg.h" #include #include "mybookdlg.h" #include "MyNewAlbumDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define PI 3.1415 ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About Bitmap pageUndersideImage(936,491); 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() ///////////////////////////////////////////////////////////////////////////// // CMyAlbumDlg dialog CMyAlbumDlg::CMyAlbumDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyAlbumDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyAlbumDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_step = 0; m_x = 20; m_numAlbum = 1; m_curAlbum = 0; m_album[0].name = "主人相册"; m_album[0].str_music = "音乐\\bk001.wav"; m_album[0].num_photo = 16; for(int i = 0; i < m_album[0].num_photo; i++) { m_album[0].str_photo[i].Format("photo\\%c.jpg", 'a' + i); } } void CMyAlbumDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyAlbumDlg) DDX_Control(pDX, IDC_COMBO1, m_comb); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMyAlbumDlg, CDialog) //{{AFX_MSG_MAP(CMyAlbumDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON1, OnAlbum) ON_BN_CLICKED(IDC_NEW, OnNew) ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyAlbumDlg message handlers BOOL CMyAlbumDlg::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 SetTimer(1,100,NULL); m_bmBack.DeleteObject(); m_brBack.DeleteObject(); m_bmBack.LoadBitmap(IDB_BK001); m_brBack.CreatePatternBrush(&m_bmBack); wchar_t *wImage; int len; for(int i = 0; i < m_album[m_curAlbum].num_photo; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_album[m_curAlbum].str_photo[i], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_album[m_curAlbum].str_photo[i], -1, wImage, len); m_image[i] = Image::FromFile(wImage); delete []wImage; } for(i = 0; i < m_numAlbum; i++) { m_comb.InsertString(i,m_album[i].name); } m_comb.SetCurSel(0); return TRUE; // return TRUE unless you set the focus to a control } // 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 CMyAlbumDlg::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); if (IsIconic()) { 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 { Graphics g(dcMemory.m_hDC); Image bk_image(L"背景\\bg001.jpg"); g.DrawImage(&bk_image,bkRect.left,bkRect.top,bkRect.Width(),bkRect.Height()); for(int i = 0; i < m_album[m_curAlbum].num_photo; i++) { g.DrawImage(m_image[i],205 + ((i%6)*120),55 + (i / 6)*120,100,100); } dc.BitBlt(0,0,bkRect.Width(),bkRect.Height(),&dcMemory,0,0,SRCCOPY); CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CMyAlbumDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMyAlbumDlg::OnTimer(UINT nIDEvent) { CDialog::OnTimer(nIDEvent); } BOOL CMyAlbumDlg::OnEraseBkgnd(CDC* pDC) { // return true; return CDialog::OnEraseBkgnd(pDC); } HBRUSH CMyAlbumDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_DLG) return m_brBack; return hbr; } void CMyAlbumDlg::OnButton2() { // TODO: Add your control notification handler code here OnOK(); } void CMyAlbumDlg::OnAlbum() { // TODO: Add your control notification handler code here // OnOK(); CMyBookDlg dlg; for(int i = 0; i <= m_album[m_curAlbum].num_photo; i++) { dlg.m_strImage[i] = m_album[m_curAlbum].str_photo[i]; } dlg.m_photoNum = m_album[m_curAlbum].num_photo - 1; dlg.m_strMusic = m_album[m_curAlbum].str_music; dlg.SetPage(); dlg.DoModal(); } void CMyAlbumDlg::OnNew() { // TODO: Add your control notification handler code here CMyNewAlbumDlg dlg; if(dlg.DoModal() == IDOK) { if(dlg.m_name == ""|| dlg.m_totleNum < 4 ) { MessageBox("要填写相册名称,相册的相片数不得少于4!\r\n请重新设置!"); OnNew(); } m_numAlbum++; m_album[m_numAlbum -1].name = dlg.m_name; m_album[m_numAlbum -1].str_music = dlg.m_music; m_album[m_numAlbum -1].num_photo = dlg.m_totleNum; for(int i = 0; i < m_album[m_numAlbum- 1 ].num_photo; i++) { m_album[m_numAlbum -1 ].str_photo[i] = dlg.m_path[i]; } m_comb.InsertString(m_numAlbum - 1,m_album[m_numAlbum - 1].name); UpdateData(false); } } void CMyAlbumDlg::OnSelchangeCombo1() { // TODO: Add your control notification handler code here m_curAlbum = m_comb.GetCurSel(); wchar_t *wImage; int len; for(int i = 0; i < m_album[m_curAlbum].num_photo; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_album[m_curAlbum].str_photo[i], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_album[m_curAlbum].str_photo[i], -1, wImage, len); m_image[i] = Image::FromFile(wImage); delete []wImage; } Invalidate(); }