UiDragPanel 示例(07_UiDragPanel)

UiDragPanel 示例

此示例展示以下控件的使用方法:

07_UiDragPanel_01.png
07_UiDragPanel_02.png

初始化 UiDragPanel

RECT rcClient = MzGetClientRect();
DragPanel.SetPos(rcClient.left, rcClient.top, RECT_WIDTH(rcClient), RECT_HEIGHT(rcClient));
AddUiWin(&DragPanel);

// 指定页面图像对象
DragPanel.SetPageImage(0, &m_PageImages[0], false);
DragPanel.SetPageImage(1, &m_PageImages[1], false);
DragPanel.SetPageImage(2, &m_PageImages[2], false);

设定 UiDragPanel 的页面

// 中间页
DragPanel.SetPage(DragPanel.GetCenterPage(), 0, 
              imgCache[0].GetImageWidth(), imgCache[0].GetImageHeight());
// 设定ImagingHelper
m_PageImages[1].SetImagingHelper(&imgCache[0]);
DragPanel.SetFitPage(DragPanel.GetCenterPage());
// 左页
DragPanel.SetPage(DragPanel.GetCenterPage()->m_pLeft, -1, 0, 0);
// 右页
if (m_nFileCount > 1)
{
              DragPanel.SetPage(DragPanel.GetCenterPage()->m_pRight, 1, 
                            imgCache[1].GetImageWidth(), imgCache[1].GetImageHeight());
              m_PageImages[2].SetImagingHelper(&imgCache[1]);
}
else
              DragPanel.SetPage(DragPanel.GetCenterPage()->m_pLeft, -1, 0, 0);

重写 CMzWndEx::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam) ,处理换新页的消息:

LRESULT CMainWnd::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
              switch (message)
              {
              case MM_MUTITOUCH:
                            {
                                          // 窗口收到MutiTouch消息交给控件处理
            float xOPos = HIWORD(lParam);
            float yOPos = LOWORD(lParam);
                                          DragPanel.OnMutiTouch(xOPos, yOPos, wParam);
                            }
                            break;
              case MZ_WM_UIDRAGPANEL_NEWPAGE:
                            {
                                          // 换新页后会收到此消息,wParam为新页的序号,lParam为页指针
                                          int nNewSerial = wParam;
                                          PanelPage *pNewPage = (PanelPage*)lParam;
                                          if (nNewSerial < m_nFileCount)
                                          {
                                                        DragPanel.SetPage(pNewPage, nNewSerial, 
                                                                      imgCache[nNewSerial].GetImageWidth(), imgCache[nNewSerial].GetImageHeight());
                                                        // 更新页面内容
                                                        m_PageImages[pNewPage->m_nIndex].SetImagingHelper(&imgCache[nNewSerial]);
                                          }
                                          else
                                                        DragPanel.SetPage(pNewPage, -1, 0, 0);
                            }
                            break;
              default:
                            break;
              }
              return CMzWndEx::MzDefWndProc(message, wParam, lParam);
}

完整示例:

#include "CMainWnd.h"

BOOL CMainWnd::OnInitDialog()
{
              if (!CMzWndEx::OnInitDialog())
    {
                            return FALSE;
    }

    // 向触摸屏驱动注册一个窗口通知消息
              RegisterTouchNotify(m_hWnd, MM_MUTITOUCH);

    RECT rcClient = MzGetClientRect();
    DragPanel.SetPos(rcClient.left, rcClient.top, RECT_WIDTH(rcClient), RECT_HEIGHT(rcClient));
              AddUiWin(&DragPanel);

              // 指定页面图像对象
              DragPanel.SetPageImage(0, &m_PageImages[0], false);
              DragPanel.SetPageImage(1, &m_PageImages[1], false);
              DragPanel.SetPageImage(2, &m_PageImages[2], false);
              // 载入图片
              WIN32_FIND_DATA fd;
              HANDLE hFind;
              WCHAR lpFileList[MAX_PATH];
              hFind = FindFirstFile(L"\\Disk\\Photo\\Photo Album\\*.jpg", &fd);
              if (hFind == INVALID_HANDLE_VALUE)
              {
                            FindClose(hFind);
                            return false;
              }
              m_nFileCount = 0;
              while (hFind != INVALID_HANDLE_VALUE)
              {
                            _tcscpy(lpFileList, L"\\Disk\\Photo\\Photo Album\\");
                            _tcscat(lpFileList, fd.cFileName);
                            imgCache[m_nFileCount].LoadImage(lpFileList, true, true);
                            m_nFileCount++;
                            if (!FindNextFile(hFind, &fd) || m_nFileCount > 49)
                            {
                                          FindClose(hFind);
                                          break;
                            }
              }
              // 中间页
              DragPanel.SetPage(DragPanel.GetCenterPage(), 0, 
                            imgCache[0].GetImageWidth(), imgCache[0].GetImageHeight());
              // 设定ImagingHelper
              m_PageImages[1].SetImagingHelper(&imgCache[0]);
              DragPanel.SetFitPage(DragPanel.GetCenterPage());
              // 左页
              DragPanel.SetPage(DragPanel.GetCenterPage()->m_pLeft, -1, 0, 0);
              // 右页
              if (m_nFileCount > 1)
              {
                            DragPanel.SetPage(DragPanel.GetCenterPage()->m_pRight, 1, 
                                          imgCache[1].GetImageWidth(), imgCache[1].GetImageHeight());
                            m_PageImages[2].SetImagingHelper(&imgCache[1]);
              }
              else
                            DragPanel.SetPage(DragPanel.GetCenterPage()->m_pLeft, -1, 0, 0);
              return true;
}

LRESULT CMainWnd::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
              switch (message)
              {
              case MM_MUTITOUCH:
                            {
                                          // 窗口收到MutiTouch消息交给控件处理
                                          float xOPos = HIWORD(lParam);
            float yOPos = LOWORD(lParam);
                                          DragPanel.OnMutiTouch(xOPos, yOPos, wParam);
                            }
                            break;
              case MZ_WM_UIDRAGPANEL_NEWPAGE:
                            {
                                          // 换新页后会收到此消息,wParam为新页的序号,lParam为页指针
                                          int nNewSerial = wParam;
                                          PanelPage *pNewPage = (PanelPage*)lParam;
                                          if (nNewSerial < m_nFileCount)
                                          {
                                                        DragPanel.SetPage(pNewPage, nNewSerial, 
                                                                      imgCache[nNewSerial].GetImageWidth(), imgCache[nNewSerial].GetImageHeight());
                                                        // 更新页面内容
                                                        m_PageImages[pNewPage->m_nIndex].SetImagingHelper(&imgCache[nNewSerial]);
                                          }
                                          else
                                                        DragPanel.SetPage(pNewPage, -1, 0, 0);
                            }
                            break;
              default:
                            break;
              }
              return CMzWndEx::MzDefWndProc(message, wParam, lParam);
}

Generated at Tue Feb 9 15:09:53 2010 for Meizu M8 SDK Documentation by  doxygen 1.6.1