// MyBookDlg.cpp : implementation file // #include "stdafx.h" #include "myAlbum.h" #include "MyBookDlg.h" #include #include "myalbumdlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include //µ¼ÈëÉùÒôÍ·Îļþ #pragma comment(lib,"winmm.lib")//µ¼ÈëÉùÒôÍ·Îļþ¿â #define PI 3.1415 #define WM_MY_TURN (WM_USER + 100) ///////////////////////////////////////////////////////////////////////////// // CMyBookDlg dialog CMyBookDlg::CMyBookDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyBookDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyBookDlg) //}}AFX_DATA_INIT m_photoFrameLeft = 160; m_photoFrameTop = 130; PageInit(); m_bLtnDown = false; m_x = 0; m_strPage[0] = "±³¾°\\003.jpg"; m_strPage[1] = "±³¾°\\004.jpg"; m_strPage[2] = "±³¾°\\003.jpg"; m_strPage[3] = "±³¾°\\004.jpg"; m_strPage[4] = "±³¾°\\000.jpg"; m_strPage[5] = "±³¾°\\005.jpg"; m_curNum = 0; m_turnType = type_head; m_bAuto = false; m_bTOnce = false; m_photoNum = 15; SetPage(); } void CMyBookDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyBookDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMyBookDlg, CDialog) //{{AFX_MSG_MAP(CMyBookDlg) ON_WM_MOVE() ON_BN_CLICKED(IDC_QUITE, OnQuite) ON_WM_CTLCOLOR() ON_WM_PAINT() ON_WM_CANCELMODE() ON_WM_ERASEBKGND() ON_WM_MOUSEMOVE() ON_WM_SETCURSOR() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_TIMER() ON_BN_CLICKED(IDC_START, OnStart) ON_BN_CLICKED(IDC_STOP, OnStop) ON_BN_CLICKED(IDC_HEAD, OnHead) ON_BN_CLICKED(IDC_END, OnEnd) ON_BN_CLICKED(IDC_PRE, OnPre) ON_BN_CLICKED(IDC_NEXT, OnNext) ON_BN_CLICKED(IDC_PLAY, OnPlay) //}}AFX_MSG_MAP ON_MESSAGE(WM_MY_TURN, OnChangePage) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyBookDlg message handlers BOOL CMyBookDlg::OnInitDialog() { CDialog::OnInitDialog(); m_bmBack.DeleteObject(); m_brBack.DeleteObject(); m_brBack.CreatePatternBrush(&m_bmBack); MoveWindow(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW); CPaintDC dc(this); // device context for painting PraparePage(); ::SetTimer(m_hWnd,1,100,NULL); GetClientRect(&m_bkRect); dcMemory.CreateCompatibleDC(NULL); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, m_bkRect.Width(), m_bkRect.Height()); SelectObject(dcMemory.GetSafeHdc(), bitmap) ; CBitmap Bitmap_Pre,Bitmap_Next,Bitmap_Head,Bitmap_End,Bitmap_Start,Bitmap_Stop,Bitmap_Exit,Bitmap_Play; Bitmap_Pre.LoadBitmap(IDB_PRE); Bitmap_Next.LoadBitmap(IDB_NEXT); Bitmap_Head.LoadBitmap(IDB_HEAD); Bitmap_End.LoadBitmap(IDB_END); Bitmap_Start.LoadBitmap(IDB_START); Bitmap_Stop.LoadBitmap(IDB_STOP); Bitmap_Exit.LoadBitmap(IDB_QUITE); Bitmap_Play.LoadBitmap(IDB_PLAY); CButton *pButton_Pre=(CButton*)GetDlgItem(IDC_PRE); HBITMAP hBitmap_Pre=(HBITMAP)Bitmap_Pre.Detach(); pButton_Pre->SetBitmap(hBitmap_Pre); CButton *pButton_Next=(CButton*)GetDlgItem(IDC_NEXT); HBITMAP hBitmap_Next=(HBITMAP)Bitmap_Next.Detach(); pButton_Next->SetBitmap(hBitmap_Next); CButton *pButton_Head=(CButton*)GetDlgItem(IDC_HEAD); HBITMAP hBitmap_Head=(HBITMAP)Bitmap_Head.Detach(); pButton_Head->SetBitmap(hBitmap_Head); CButton *pButton_End=(CButton*)GetDlgItem(IDC_END); HBITMAP hBitmap_End=(HBITMAP)Bitmap_End.Detach(); pButton_End->SetBitmap(hBitmap_End); CButton *pButton_Start=(CButton*)GetDlgItem(IDC_START); HBITMAP hBitmap_Start=(HBITMAP)Bitmap_Start.Detach(); pButton_Start->SetBitmap(hBitmap_Start); CButton *pButton_Stop=(CButton*)GetDlgItem(IDC_STOP); HBITMAP hBitmap_Stop=(HBITMAP)Bitmap_Stop.Detach(); pButton_Stop->SetBitmap(hBitmap_Stop); CButton *pButton_Exit=(CButton*)GetDlgItem(IDC_QUITE); HBITMAP hBitmap_Exit=(HBITMAP)Bitmap_Exit.Detach(); pButton_Exit->SetBitmap(hBitmap_Exit); CButton *pButton_Play=(CButton*)GetDlgItem(IDC_PLAY); HBITMAP hBitmap_Play=(HBITMAP)Bitmap_Play.Detach(); pButton_Play->SetBitmap(hBitmap_Play); // m_bQuite.LoadBitmaps(IDB_BK001); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CMyBookDlg::OnMove(int x, int y) { //CDialog::OnMove(x, y); // MoveWindow(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW); return; // TODO: Add your message handler code here } void CMyBookDlg::OnQuite() { // TODO: Add your control notification handler code here OnOK(); } HBRUSH CMyBookDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_DLG || nCtlColor == CTLCOLOR_BTN ) return m_brBack; return hbr; } void CMyBookDlg::OnCancelMode() { CDialog::OnCancelMode(); // TODO: Add your message handler code here } BOOL CMyBookDlg::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return true; return CDialog::OnEraseBkgnd(pDC); } void CMyBookDlg::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRgn rgnNormal,rgnLeft,rgnRight; rgnNormal.CreateRectRgn(m_photoFrameLeft + m_rectPL.right,m_photoFrameTop,m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop + 600); rgnLeft.CreateRectRgn(m_photoFrameLeft,m_photoFrameTop,m_photoFrameLeft + m_rectPL.right,m_photoFrameTop + 600); rgnRight.CreateRectRgn(m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop,m_photoFrameLeft + 1058,m_photoFrameTop + 600); if(!m_bLtnDown) { if(rgnNormal.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1)); if(!m_bTOnce &&! m_bAuto) m_x = 0; } else if(rgnLeft.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2)); if(!m_bTOnce &&! m_bAuto) m_x += 20; } else if(rgnRight.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2)); if(!m_bTOnce &&! m_bAuto) m_x += 20; } else { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR3)); if(!m_bTOnce &&! m_bAuto) m_x = 0; } } else { if(rgnNormal.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_NORMAL)); } else if(rgnLeft.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_LEFT)); } else if(rgnRight.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_RIGHT)); } else { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR3)); } } CDialog::OnMouseMove(nFlags, point); } BOOL CMyBookDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default return true; return CDialog::OnSetCursor(pWnd, nHitTest, message); } void CMyBookDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_bLtnDown = true; CRgn rgnNormal,rgnLeft,rgnRight; rgnNormal.CreateRectRgn(m_photoFrameLeft + m_rectPL.right,m_photoFrameTop,m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop + 600); rgnLeft.CreateRectRgn(m_photoFrameLeft,m_photoFrameTop,m_photoFrameLeft + m_rectPL.right,m_photoFrameTop + 600); rgnRight.CreateRectRgn(m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop,m_photoFrameLeft + 1058,m_photoFrameTop + 600); if(rgnNormal.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_NORMAL)); } else if(rgnLeft.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_LEFT)); if(!m_bTOnce &&! m_bAuto) m_x += 40; } else if(rgnRight.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_RIGHT)); if(!m_bTOnce &&! m_bAuto) m_x += 40; } CDialog::OnLButtonDown(nFlags, point); } void CMyBookDlg::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_bLtnDown = false; CRgn rgnNormal,rgnLeft,rgnRight; rgnNormal.CreateRectRgn(m_photoFrameLeft + m_rectPL.right,m_photoFrameTop,m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop + 600); rgnLeft.CreateRectRgn(m_photoFrameLeft,m_photoFrameTop,m_photoFrameLeft + m_rectPL.right,m_photoFrameTop + 600); rgnRight.CreateRectRgn(m_photoFrameLeft +529 + m_rectPR.left,m_photoFrameTop,m_photoFrameLeft + 1058,m_photoFrameTop + 600); if(rgnNormal.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1)); if(!m_bTOnce &&! m_bAuto) m_x = 0; } else if(rgnLeft.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2)); if(!m_bTOnce &&! m_bAuto) OnPre(); } else if(rgnRight.PtInRegion(point)) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2)); if(!m_bTOnce &&! m_bAuto) OnNext(); } else { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR3)); if(!m_bTOnce &&! m_bAuto) m_x = 0; } CDialog::OnLButtonUp(nFlags, point); } void CMyBookDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(m_bAuto || m_bTOnce) { m_x+= 20; } CRect rect(m_photoFrameLeft,0, m_photoFrameLeft + 1080,m_photoFrameTop + 600); InvalidateRect(rect); CDialog::OnTimer(nIDEvent); } void CMyBookDlg::PageInit() { m_rectPL.left = 60; m_rectPL.top = 60; m_rectPR.left = 74; m_rectPR.top = 60; m_rectPL.right = m_rectPL.left + 404; m_rectPL.bottom = m_rectPL.top + 450; m_rectPR.right = m_rectPR.left + 404; m_rectPR.bottom = m_rectPR.top + 450; m_rectTL.left = 60; m_rectTL.top = 60; m_rectTR.left = 74; m_rectTR.top = 60; m_rectTL.right = m_rectPL.left + 404; m_rectTL.bottom = m_rectPL.top + 450; m_rectTR.right = m_rectPR.left + 404; m_rectTR.bottom = m_rectPR.top + 450; } void CMyBookDlg::SetPage() { wchar_t *wPage,*wImage; int len; int i = 0; for( i = 0; i < 4; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0); wPage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len); m_pPage[i] = Bitmap::FromFile(wPage); delete []wPage; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[i], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[i], -1, wImage, len); m_pImage[i] = Image::FromFile(wImage); delete []wImage; m_pGPage[i] = Graphics::FromImage(m_pPage[i]); } for( i = 4; i < 6; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0); wPage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len); m_pPage[i] = Bitmap::FromFile(wPage); delete []wPage; } } void CMyBookDlg::PraparePage() { Color clrPen(255,0,0,0); Pen penDraw(clrPen,1 ); SolidBrush solidBrush(Color(255, 255, 255, 255)); m_pGPage[0]->DrawRectangle(&penDraw,m_rectPL.left,m_rectPL.top,m_rectPL.Width(),m_rectPL.Height()); if(m_pImage[0]->GetWidth()/float(m_rectPL.Width()) >= m_pImage[0]->GetHeight()/float(m_rectPL.Height())) { m_rectPL.right = m_rectPL.left + m_rectPL.Width(); int temp_height = (float(m_rectPL.Width())/m_pImage[0]->GetWidth())*m_pImage[0]->GetHeight(); m_rectPL.top += (m_rectPL.Height() - temp_height) / 2; m_rectPL.bottom = m_rectPL.top + temp_height; m_pGPage[0]->DrawImage(m_pImage[0],m_rectPL.left +1 ,m_rectPL.top +1,m_rectPL.Width() -1 ,m_rectPL.Height() -1); } else { m_rectPL.bottom = m_rectPL.top + m_rectPL.Height(); int temp_width = (float(m_rectPL.Height())/m_pImage[0]->GetHeight())*m_pImage[0]->GetWidth(); m_rectPL.left += (m_rectPL.Width() - temp_width) / 2; m_rectPL.right = m_rectPL.left + temp_width; m_pGPage[0]->DrawImage(m_pImage[0],m_rectPL.left +1 ,m_rectPL.top +1,m_rectPL.Width() -1 ,m_rectPL.Height() -1); } m_pGPage[1]->DrawRectangle(&penDraw,m_rectPR.left,m_rectPR.top,m_rectPR.Width(),m_rectPR.Height()); if(m_pImage[1]->GetWidth()/float(m_rectPR.Width()) >= m_pImage[1]->GetHeight()/float(m_rectPR.Height())) { m_rectPR.right = m_rectPR.left + m_rectPR.Width(); int temp_height = (float(m_rectPR.Width())/m_pImage[1]->GetWidth())*m_pImage[1]->GetHeight(); m_rectPR.top += (m_rectPR.Height() - temp_height) / 2; m_rectPR.bottom = m_rectPR.top + temp_height; m_pGPage[1]->DrawImage(m_pImage[1],m_rectPR.left +1 ,m_rectPR.top +1,m_rectPR.Width() -1 ,m_rectPR.Height() -1); } else { m_rectPR.bottom = m_rectPR.top + m_rectPR.Height(); int temp_width = (float(m_rectPR.Height())/m_pImage[1]->GetHeight())*m_pImage[1]->GetWidth(); m_rectPR.left += (m_rectPR.Width() - temp_width) / 2; m_rectPR.right = m_rectPR.left + temp_width; m_pGPage[1]->DrawImage(m_pImage[1],m_rectPR.left +1 ,m_rectPR.top +1,m_rectPR.Width() -1 ,m_rectPR.Height() -1); } m_pGPage[2]->DrawRectangle(&penDraw,m_rectTL.left,m_rectTL.top,m_rectTL.Width(),m_rectTL.Height()); if(m_pImage[2]->GetWidth()/float(m_rectTL.Width()) >= m_pImage[2]->GetHeight()/float(m_rectTL.Height())) { m_rectTL.right = m_rectTL.left + m_rectTL.Width(); int temp_height = (float(m_rectTL.Width())/m_pImage[2]->GetWidth())*m_pImage[2]->GetHeight(); m_rectTL.top += (m_rectTL.Height() - temp_height) / 2; m_rectTL.bottom = m_rectTL.top + temp_height; m_pGPage[2]->DrawImage(m_pImage[2],m_rectTL.left +1 ,m_rectTL.top +1,m_rectTL.Width() -1 ,m_rectTL.Height() -1); } else { m_rectTL.bottom = m_rectTL.top + m_rectTL.Height(); int temp_width = (float(m_rectTL.Height())/m_pImage[2]->GetHeight())*m_pImage[2]->GetWidth(); m_rectTL.left += (m_rectTL.Width() - temp_width) / 2; m_rectTL.right = m_rectTL.left + temp_width; m_pGPage[2]->DrawImage(m_pImage[2],m_rectTL.left +1 ,m_rectTL.top +1,m_rectTL.Width() -1 ,m_rectTL.Height() -1); } m_pGPage[3]->DrawRectangle(&penDraw,m_rectTR.left,m_rectTR.top,m_rectTR.Width(),m_rectTR.Height()); if(m_pImage[3]->GetWidth()/float(m_rectTR.Width()) >= m_pImage[3]->GetHeight()/float(m_rectTR.Height())) { m_rectTR.right = m_rectTR.left + m_rectTR.Width(); int temp_height = (float(m_rectTR.Width())/m_pImage[3]->GetWidth())*m_pImage[3]->GetHeight(); m_rectTR.top += (m_rectTR.Height() - temp_height) / 2; m_rectTR.bottom = m_rectTR.top + temp_height; m_pGPage[3]->DrawImage(m_pImage[3],m_rectTR.left +1 ,m_rectTR.top +1,m_rectTR.Width() -1 ,m_rectTR.Height() -1); } else { m_rectTR.bottom = m_rectTR.top + m_rectTR.Height(); int temp_width = (float(m_rectTR.Height())/m_pImage[3]->GetHeight())*m_pImage[3]->GetWidth(); m_rectTR.left += (m_rectTR.Width() - temp_width) / 2; m_rectTR.right = m_rectTR.left + temp_width; m_pGPage[3]->DrawImage(m_pImage[3],m_rectTR.left +1 ,m_rectTR.top +1,m_rectTR.Width() -1 ,m_rectTR.Height() -1); } } LRESULT CMyBookDlg::OnChangePage(LPARAM lparam, WPARAM wparam) { wchar_t *wPage,*wImage; int len; m_x = 0; switch(m_turnType) { case type_endToleft : m_turnType = type_left; m_curNum = m_photoNum + 2; break; case type_headToright: m_turnType = type_right; m_curNum = -2; break; case type_leftToright: m_curNum -= 3; m_turnType = type_right; break; case type_rightToleft: m_curNum += 3; m_turnType = type_left; } if(m_turnType == type_right || m_turnType == type_head) { for( int i = 0; i < 4; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0); wPage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len); m_pPage[i] = Bitmap::FromFile(wPage); delete []wPage; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum + i + 2], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum + i + 2], -1, wImage, len); m_pImage[i] = Image::FromFile(wImage); delete []wImage; m_pGPage[i] = Graphics::FromImage(m_pPage[i]); } if(m_curNum >= m_photoNum - 3) { m_turnType = type_rightToend; } else { m_curNum += 2; } } else if(m_turnType == type_left || m_turnType == type_end) { for( int i = 0; i < 4; i++) { len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0); wPage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len); m_pPage[i] = Bitmap::FromFile(wPage); delete []wPage; } len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum -1 - 2], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum - 1 - 2], -1, wImage, len); m_pImage[0] = Image::FromFile(wImage); delete []wImage; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum - 2], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum - 2], -1, wImage, len); m_pImage[1] = Image::FromFile(wImage); delete []wImage; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum -3 - 2], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum -3 - 2], -1, wImage, len); m_pImage[2] = Image::FromFile(wImage); delete []wImage; len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum -2 - 2], -1, NULL, 0); wImage = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[m_curNum -2 - 2], -1, wImage, len); m_pImage[3] = Image::FromFile(wImage); delete []wImage; for(i = 0; i < 4; i++) { m_pGPage[i] = Graphics::FromImage(m_pPage[i]); } if(m_curNum <= 3) { m_turnType = type_leftTohead; m_curNum = -2; } else { m_curNum -= 2; } } PraparePage(); return 0; } void CMyBookDlg::LeftTurn() { Graphics g(dcMemory.m_hDC); Image bk_image(L"±³¾°\\bg002.bmp"); Image image(L"001.jpg"); g.DrawImage(&bk_image,m_bkRect.left,m_bkRect.top,m_bkRect.Width(),m_bkRect.Height()); Color clrPen(255,0,0,0); Pen penDraw(clrPen,1 ); SolidBrush solidBrush(Color(255, 255, 255, 255)); double a = 45 + ((45 * m_x) /(m_pPage[0]->GetWidth())); double radians = a * (PI / 180.0); double pageUndersideRotationAngle = -(180 - (2 * a)); double calculated_y = 0; double calculated_x = 0; calculated_y = (m_x)* (tan(radians)); int width = m_pPage[0]->GetWidth(); int height = m_pPage[0]->GetHeight(); if (m_x >= width) { g.DrawImage(m_pPage[2],m_photoFrameLeft,m_photoFrameTop,m_pPage[2]->GetWidth(),m_pPage[2]->GetHeight()); g.DrawImage(m_pPage[3],m_photoFrameLeft + m_pPage[2]->GetWidth(),m_photoFrameTop,m_pPage[3]->GetWidth(),m_pPage[3]->GetHeight()); PostMessage(WM_MY_TURN,0,0); if(m_bTOnce) m_bTOnce = false; } else { g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); GraphicsPath gpLeft,gpRight; if(calculated_y < height) { gpLeft.AddLine( PointF(abs(m_x), height), PointF(0, height)); gpLeft.AddLine( PointF(0, height), PointF(0, (height - (float)calculated_y))); } else { gpLeft.AddLine(PointF(abs(m_x ), height),PointF(0, height)); gpLeft.AddLine(PointF(0, height),PointF(0, 0)); calculated_x = height / tan(radians); gpLeft.AddLine( PointF(0,0), PointF(abs( m_x - (float)calculated_x) , 0)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[2],m_photoFrameLeft,m_photoFrameTop,m_pPage[2]->GetWidth(),m_pPage[2]->GetHeight()); g.SetClip(&oldRegion); Bitmap pageUndersideImage(width,height); if(calculated_y < height) { gpRight.AddLine( PointF(abs(width - m_x), height), PointF(width, height)); gpRight.AddLine( PointF(width , height), PointF(width , (height - (float)calculated_y))); } else { gpRight.AddLine(PointF(abs(float(width) - m_x ), height),PointF(width , height)); gpRight.AddLine(PointF(width , height),PointF(width , 0)); calculated_x = height / tan(radians); gpRight.AddLine( PointF(width , 0), PointF(abs(width - (m_x - (float)calculated_x) ), 0)); } Graphics ug(&pageUndersideImage); ug.SetClip(&gpRight); ug.DrawPath(&penDraw,&gpRight); ug.DrawImage(m_pPage[3], 0,0,m_pPage[3]->GetWidth(),m_pPage[3]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_x, m_photoFrameTop + m_pPage[3]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, int(m_x)-width,-height,width,height ); } PageInit(); } void CMyBookDlg::OnPaint() { CPaintDC dc(this); if(m_turnType == type_left || m_turnType == type_endToleft) { LeftTurn(); } else if(m_turnType == type_right || m_turnType == type_headToright) { RightTurn(); } else { DrawBothEnds(); } dc.BitBlt(0,0,m_bkRect.Width(),m_bkRect.Height(),&dcMemory,0,0,SRCCOPY); } void CMyBookDlg::RightTurn() { Graphics g(dcMemory.m_hDC); Image bk_image(L"±³¾°\\bg002.bmp"); Image image(L"001.jpg"); g.DrawImage(&bk_image,m_bkRect.left,m_bkRect.top,m_bkRect.Width(),m_bkRect.Height()); Color clrPen(255,0,0,0); Pen penDraw(clrPen,1 ); SolidBrush solidBrush(Color(255, 255, 255, 255)); double a = 45 + ((45 * m_x) /(m_pPage[0]->GetWidth())); double radians = a * (PI / 180.0); double pageUndersideRotationAngle = (180 - (2 * a)); double calculated_y = 0; double calculated_x = 0; calculated_y = (m_x)* (tan(radians)); int width = m_pPage[0]->GetWidth(); int height = m_pPage[0]->GetHeight(); if (m_x >= width) { g.DrawImage(m_pPage[2],m_photoFrameLeft,m_photoFrameTop,m_pPage[2]->GetWidth(),m_pPage[2]->GetHeight()); g.DrawImage(m_pPage[3],m_photoFrameLeft + m_pPage[2]->GetWidth(),m_photoFrameTop,m_pPage[3]->GetWidth(),m_pPage[3]->GetHeight()); PostMessage(WM_MY_TURN,0,0); if(m_bTOnce) m_bTOnce = false; } else { g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); GraphicsPath gpLeft,gpRight; int undersideOffset = width; if(calculated_y < height) { gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height), PointF(width + undersideOffset, height)); gpLeft.AddLine( PointF(width + undersideOffset, height), PointF(width + undersideOffset, (height - (float)calculated_y))); } else { gpLeft.AddLine(PointF(abs(width - m_x + undersideOffset), height),PointF(width + undersideOffset, height)); gpLeft.AddLine(PointF(width + undersideOffset, height),PointF(width + undersideOffset, 0)); calculated_x = height / tan(radians); gpLeft.AddLine( PointF(width + undersideOffset, 0), PointF(abs(width - (m_x - (float)calculated_x) + undersideOffset), 0)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[3],m_photoFrameLeft + m_pPage[3]->GetWidth(),m_photoFrameTop,m_pPage[3]->GetWidth(),m_pPage[3]->GetHeight()); g.SetClip(&oldRegion); Bitmap pageUndersideImage(width,height); undersideOffset = width; if(calculated_y < height) { gpRight.AddLine( PointF(abs(width - m_x - undersideOffset), height), PointF(width - undersideOffset, height)); gpRight.AddLine( PointF(width - undersideOffset, height), PointF(width - undersideOffset, (height - (float)calculated_y))); } else { gpRight.AddLine(PointF(abs(float(width) - m_x - undersideOffset), height),PointF(width - undersideOffset, height)); gpRight.AddLine(PointF(width - undersideOffset, height),PointF(width - undersideOffset, 0)); calculated_x = height / tan(radians); gpRight.AddLine( PointF(width - undersideOffset, 0), PointF(abs(width - (m_x - (float)calculated_x) - undersideOffset), 0)); } Graphics ug(&pageUndersideImage); ug.SetClip(&gpRight); ug.DrawPath(&penDraw,&gpRight); ug.DrawImage(m_pPage[2], 0,0,m_pPage[3]->GetWidth(),m_pPage[3]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_pPage[3]->GetWidth()*2 - m_x, m_photoFrameTop + m_pPage[3]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, -int(m_x) ,-height ,width,height ); } PageInit(); } void CMyBookDlg::DrawBothEnds() { Graphics g(dcMemory.m_hDC); Image bk_image(L"±³¾°\\bg002.bmp"); Image image(L"001.jpg"); g.DrawImage(&bk_image,m_bkRect.left,m_bkRect.top,m_bkRect.Width(),m_bkRect.Height()); Color clrPen(255,0,0,0); Pen penDraw(clrPen,1 ); SolidBrush solidBrush(Color(255, 255, 255, 255)); double a = 45 + ((45 * m_x) /(m_pPage[0]->GetWidth())); double radians = a * (PI / 180.0); double pageUndersideRotationAngle = (180 - (2 * a)); double calculated_y = 0; double calculated_x = 0; calculated_y = (m_x)* (tan(radians)); int width = m_pPage[5]->GetWidth(); int height = m_pPage[5]->GetHeight(); if (m_x >= width) { m_x = 0; if(m_turnType == type_head ||m_turnType == type_end) { g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); if(m_turnType == type_head) { m_turnType = type_headToright; PostMessage(WM_MY_TURN,0,0); } else { m_turnType = type_endToleft; PostMessage(WM_MY_TURN,0,0); } } else if(m_turnType == type_leftTohead) { g.DrawImage(m_pPage[4],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); m_turnType = type_head; } else if(m_turnType == type_rightToend) { g.DrawImage(m_pPage[5],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); m_turnType = type_end; } if(m_bTOnce) m_bTOnce =false; } else { if(m_turnType == type_head) g.DrawImage(m_pPage[4],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); else if(m_turnType == type_end) g.DrawImage(m_pPage[5],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); else { if(m_turnType == type_rightToend) g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); else g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[0]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); } if(m_turnType == type_head || m_turnType == type_rightToend) { GraphicsPath gpLeft,gpRight; int undersideOffset = width; if(m_turnType == type_head) //DÒ³ { if(calculated_y < height) { gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height), PointF(width + undersideOffset, height)); gpLeft.AddLine( PointF(width + undersideOffset, height), PointF(width + undersideOffset, (height - (float)calculated_y))); } else { gpLeft.AddLine(PointF(abs(width - m_x + undersideOffset), height),PointF(width + undersideOffset, height)); gpLeft.AddLine(PointF(width + undersideOffset, height),PointF(width + undersideOffset, 0)); calculated_x = height / tan(radians); gpLeft.AddLine( PointF(width + undersideOffset, 0), PointF(abs(width - (m_x - (float)calculated_x) + undersideOffset), 0)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[1]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); g.SetClip(&oldRegion); } else { if(calculated_y < height) { gpLeft.AddLine( PointF(width , 0), PointF( width , height) ); gpLeft.AddLine( PointF( width , height), PointF(abs(width - m_x + undersideOffset), height)); gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height), PointF(width + undersideOffset, (height - (float)calculated_y))); gpLeft.AddLine( PointF(width + undersideOffset, (height - (float)calculated_y)), PointF(width + undersideOffset, 0)); } else { gpLeft.AddLine(PointF(width, 0),PointF( width , height)); gpLeft.AddLine(PointF( width , height) ,PointF(abs(width - m_x + undersideOffset), height)); calculated_x = height / tan(radians); gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height), PointF(abs(width - (m_x - (float)calculated_x) + undersideOffset), 0)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[1]->GetWidth(),m_photoFrameTop,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); g.SetClip(&oldRegion); } //CÒ³ Bitmap pageUndersideImage(width,height); undersideOffset = width; if(calculated_y < height) { gpRight.AddLine( PointF(abs(width - m_x - undersideOffset), height), PointF(width - undersideOffset, height)); gpRight.AddLine( PointF(width - undersideOffset, height), PointF(width - undersideOffset, (height - (float)calculated_y))); } else { gpRight.AddLine(PointF(abs(float(width) - m_x - undersideOffset), height),PointF(width - undersideOffset, height)); gpRight.AddLine(PointF(width - undersideOffset, height),PointF(width - undersideOffset, 0)); calculated_x = height / tan(radians); gpRight.AddLine( PointF(width - undersideOffset, 0), PointF(abs(width - (m_x - (float)calculated_x) - undersideOffset), 0)); } Graphics ug(&pageUndersideImage); ug.SetClip(&gpRight); ug.DrawPath(&penDraw,&gpRight); if(m_turnType == type_rightToend) { ug.DrawImage(m_pPage[5], 0,0,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_pPage[1]->GetWidth()*2 - m_x, m_photoFrameTop + m_pPage[1]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, -int(m_x) ,-height ,width,height ); } else { ug.DrawImage(m_pPage[0], 0,0,m_pPage[1]->GetWidth(),m_pPage[1]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_pPage[1]->GetWidth()*2 - m_x, m_photoFrameTop + m_pPage[1]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, -int(m_x) ,-height ,width,height ); } } else if(m_turnType == type_end || m_turnType == type_leftTohead) { pageUndersideRotationAngle = -(180 - (2 * a)); GraphicsPath gpLeft,gpRight; int undersideOffset = width; if(m_turnType == type_end) //DÒ³ { if(calculated_y < height) { gpLeft.AddLine( PointF(abs(m_x), height), PointF(0, height)); gpLeft.AddLine( PointF(0, height), PointF(0, (height - (float)calculated_y))); } else { gpLeft.AddLine(PointF(abs(m_x ), height),PointF(0, height)); gpLeft.AddLine(PointF(0, height),PointF(0, 0)); calculated_x = height / tan(radians); gpLeft.AddLine( PointF(0,0), PointF(abs( m_x - (float)calculated_x) , 0)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); g.SetClip(&oldRegion); } else { if(calculated_y < height) { gpLeft.AddLine( PointF(0, 0), PointF(0, (height - (float)calculated_y))); gpLeft.AddLine( PointF(0, (height - (float)calculated_y)), PointF(abs(m_x), height)); gpLeft.AddLine( PointF(0, (height - (float)calculated_y)), PointF(m_x, height)); gpLeft.AddLine( PointF(m_x, height), PointF(width, height) ); gpLeft.AddLine( PointF(width, height), PointF(width, 0) ); } else { calculated_x = height / tan(radians); gpLeft.AddLine( PointF(abs( m_x - (float)calculated_x) , 0), PointF(width,0)); gpLeft.AddLine(PointF(width,0),PointF(width, height)); gpLeft.AddLine(PointF(width, height),PointF(abs(m_x), height)); } gpLeft.CloseFigure(); Matrix PathTranslationMatrix; PathTranslationMatrix.Translate((float)m_photoFrameLeft, (float)m_photoFrameTop); gpLeft.Transform(&PathTranslationMatrix); Region oldRegion; g.GetClip(&oldRegion); g.SetClip(&gpLeft); g.DrawPath(&penDraw,&gpLeft); g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); g.SetClip(&oldRegion); } //CÒ³ Bitmap pageUndersideImage(width,height); if(calculated_y < height) { gpRight.AddLine( PointF(abs(width - m_x), height), PointF(width, height)); gpRight.AddLine( PointF(width , height), PointF(width , (height - (float)calculated_y))); } else { gpRight.AddLine(PointF(abs(float(width) - m_x ), height),PointF(width , height)); gpRight.AddLine(PointF(width , height),PointF(width , 0)); calculated_x = height / tan(radians); gpRight.AddLine( PointF(width , 0), PointF(abs(width - (m_x - (float)calculated_x) ), 0)); } Graphics ug(&pageUndersideImage); ug.SetClip(&gpRight); ug.DrawPath(&penDraw,&gpRight); if(m_turnType == type_leftTohead) { ug.DrawImage(m_pPage[4], 0,0,m_pPage[2]->GetWidth(),m_pPage[2]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_x, m_photoFrameTop + m_pPage[2]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, int(m_x)-width,-height,width,height ); } else { ug.DrawImage(m_pPage[1], 0,0,m_pPage[0]->GetWidth(),m_pPage[0]->GetHeight()); Matrix PathTranslationMatrix1; PathTranslationMatrix1.Translate(m_photoFrameLeft + m_x, m_photoFrameTop + m_pPage[2]->GetHeight()); PathTranslationMatrix1.Rotate((float)(pageUndersideRotationAngle )); g.SetTransform(&PathTranslationMatrix1); g.DrawImage(&pageUndersideImage, int(m_x)-width,-height,width,height ); } } } PageInit(); } void CMyBookDlg::OnStart() { // TODO: Add your control notification handler code here m_bAuto = true; } void CMyBookDlg::OnStop() { // TODO: Add your control notification handler code here m_bAuto = false; } void CMyBookDlg::OnHead() { // TODO: Add your control notification handler code here m_x = 0; m_turnType = type_head; m_curNum = -2; m_bAuto = false; m_bTOnce = false; PostMessage(WM_MY_TURN,0,0); } void CMyBookDlg::OnEnd() { // TODO: Add your control notification handler code here m_x = 0; m_turnType = type_end; m_curNum = m_photoNum + 2; m_bAuto = false; m_bTOnce = false; PostMessage(WM_MY_TURN,0,0); } void CMyBookDlg::OnPre() { // TODO: Add your control notification handler code here m_bTOnce = true; m_bAuto = false; switch(m_turnType) { case type_rightToend: m_turnType = type_left; break; case type_left: m_turnType = type_left; break; case type_right: m_turnType = type_rightToleft; PostMessage(WM_MY_TURN,0,0); break; case type_head: m_bTOnce = false; break; case type_end: m_turnType = type_end; } } void CMyBookDlg::OnNext() { // TODO: Add your control notification handler code here m_bTOnce = true; m_bAuto = false; switch(m_turnType) { case type_leftTohead: m_turnType = type_right; break; case type_left: m_turnType = type_leftToright; PostMessage(WM_MY_TURN,0,0); break; case type_right: m_turnType = type_right; break; case type_head: m_turnType = type_head; break; case type_end: m_bTOnce = false; } } void CMyBookDlg::OnPlay() { // TODO: Add your control notification handler code here int a = PlaySound(m_strMusic,NULL,SND_FILENAME | SND_ASYNC); // PlaySound("C:\\WINDOWS\\MediaTWindows XP µÇ¼Òô.wav", NULL, SND_FILENAME | SND_ASYNC); }