17.9.3 电子相册浏览模块的设计与实现(9)
代码实现如下:
- 01 if(m_turnType == type_right || m_turnType == type_head)
- 02 {
- 03 for( int i = 0; i < 4; i++)
- 04 {
- 05 //载入4张相册页
- 06 len = MultiByteToWideChar(CP_ACP, 0,
- 07 (LPCTSTR)m_strPage[i], -1, NULL, 0);
- 08 wPage = new wchar_t[len];
- 09 MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)m_strPage[i], -1,
- wPage, len);
- 10 m_pPage[i] = Bitmap::FromFile(wPage);
- 11 delete []wPage;
- 12 //载入后两张相片
- 13 len = MultiByteToWideChar(CP_ACP, 0,
- 14 (LPCTSTR)m_strImage[m_curNum + i + 2],
- 15 -1, NULL, 0);
- 16 wImage = new wchar_t[len];
- 17 MultiByteToWideChar(CP_ACP, 0,
- 18 (LPCTSTR)m_strImage[m_curNum + i + 2],
- 19 -1, wImage, len);
- 20 m_pImage[i] = Image::FromFile(wImage);
- 21 delete []wImage;
- 22 m_pGPage[i] = Graphics::FromImage(m_pPage[i]);
- 23 }
- 24 if(m_curNum >= m_photoNum - 3) //判断是否到封底
- 25 {
- 26 m_turnType = type_rightToend;
- 27 }
- 28 else
- 29 {
- 30 m_curNum += 2; //后移
- 31 }
- 32 }
【代码解析】
第5~11行载入4张相册页面,第13~21行载入相册的后两张相片过程如图17.41所示。第24~27行判断是否翻到封底,如是则转换当前翻页状态,否则将当前相片标识后移。
③ 左翻页时计算载入前两张照片
左翻页及封底翻页载入相片的过程与右翻页恰好相反,首先将页面4的相片传递给页面2,将页面3的相片传递给相片1,然后载入前两张照片,分别传递给页面4与页面3。过程如图17.43所示。
|
| (点击查看大图)图17.43 左翻页相册载入相片的过程 |