17.9.3 电子相册浏览模块的设计与实现(3)
在对话框的构造函数中对这些变量进行初始化:
- 01 CMyBookDlg::CMyBookDlg(CWnd* pParent /*=NULL*/)
- 02 : CDialog(CMyBookDlg::IDD, pParent)
- 03 {
- 04 m_photoFrameLeft = 160; //相册距对话框左侧160个像素
- 05 m_photoFrameTop = 130; //相册距对话框上侧130个像素
- 06 PageInit(); //相册页面初始化
- 07 m_bLtnDown = false; //鼠标左键未按下
- 08 m_x = 0; //转动轴点距边0个像素
- 09 m_strPage[0] = "背景\\003.jpg"; //指定页面1的路径
- 10 m_strPage[1] = "背景\\004.jpg"; //指定页面2的路径
- 11 m_strPage[2] = "背景\\003.jpg"; //指定页面3的路径
- 12 m_strPage[3] = "背景\\004.jpg"; //指定页面4的路径
- 13 m_strPage[4] = "背景\\000.jpg"; //指定封面的路径
- 14 m_strPage[5] = "背景\\005.jpg"; //指定封底的路径
- 15 m_curNum = 0; //当前翻动的相片序号为0
- 16 m_turnType = type_head; //翻动类型为封面
- 17 m_bAuto = false; //未自动播放
- 18 m_bTOnce = false; //未一次性翻页
- 19 SetPage(); //设置页面
- 20 }
【代码解析】
还有一些变量是在相册控制模块跳到浏览模块时直接初始化的,详见源码。
(3)在(2)中调用了PageInit()这个函数,它主要实现4个页面相片边框的初始化工作:
- 01 void CMyBookDlg::PageInit()
- 02 {
- 03 //页面1相片边框
- 04 m_rectPL.left = 60;
- 05 m_rectPL.top = 60;
- 06 m_rectPLm_rectPL.right = m_rectPL.left + 404;
- 07 m_rectPLm_rectPL.bottom = m_rectPL.top + 450;
- 08 //页面2相片边框
- 09 m_rectPR.left = 74;
- 10 m_rectPR.top = 60;
- 11 m_rectPRm_rectPR.right = m_rectPR.left + 404;
- 12 m_rectPRm_rectPR.bottom = m_rectPR.top + 450;
- 13 //页面3相片边框
- 14 m_rectTL.left = 60;
- 15 m_rectTL.top = 60;
- 16 m_rectTL.right = m_rectPL.left + 404;
- 17 //页面4相片边框
- 18 m_rectTR.left = 74;
- 19 m_rectTR.top = 60;
- 20 m_rectTR.right = m_rectPR.left + 404;
- 21 m_rectTR.bottom = m_rectPR.top + 450;
- 22 }
(4)在(2)中还调用了SetPage()函数,在该函数中载入了4个参与翻动的页面及封面封底的图像,并定义了4个Graphics型变量进行页面翻动操作。
- 01 void CMyBookDlg::SetPage()
- 02 {
- 03 wchar_t *wPage,*wImage;
- 04 int len;
- 05 int i = 0;
- 06 for( i = 0; i < 4; i++)
- 07 { //载入4个翻动页面
- 08 len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0);
- 09 wPage = new wchar_t[len];
- 10 MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len);
- 11 m_pPage[i] = Bitmap::FromFile(wPage);
- 12 delete []wPage;
- 13 //载入4个参与翻动的相片
- 14 len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[i], -1, NULL, 0);
- 15 wImage = new wchar_t[len];
- 16 MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strImage[i], -1, wImage, len);
- 17 m_pImage[i] = Image::FromFile(wImage);
- 18 delete []wImage;
- 19 //定义4个翻动页面的Graphics型变量
- 20 m_pGPage[i] = Graphics::FromImage(m_pPage[i]);
- 21 }
- 22 for( i = 4; i < 6; i++)
- 23 { //载入相册封面和封底
- 24 len = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, NULL, 0);
- 25 wPage = new wchar_t[len];
- 26 MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1, wPage, len);
- 27 m_pPage[i] = Bitmap::FromFile(wPage);
- 28 delete []wPage;
- 29 }
- 30 }