rotate_dlg.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:8k
源码类别:

图形图象

开发平台:

Visual C++

  1. /********************************************************************
  2. rotate_dlg.cpp - ISee图像浏览器—图像处理模块图像旋转处理实现代码文件
  3.     版权所有(C) VCHelp-coPathway-ISee workgroup 2000 all member's
  4.     这一程序是自由软件,你可以遵照自由软件基金会出版的GNU 通用许可证
  5. 条款来修改和重新发布这一程序。或者用许可证的第二版,或者(根据你
  6. 的选择)用任何更新的版本。
  7.     发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特定
  8. 目地的隐含的担保。更详细的情况请参阅GNU通用许可证。
  9.     你应该已经和程序一起收到一份GNU通用许可证(GPL)的副本。如果还没有,
  10. 写信给:
  11.     The Free Software Foundation, Inc.,  675  Mass Ave,  Cambridge,
  12.     MA02139,  USA
  13. 如果你在使用本软件时有什么问题或建议,用以下地址可以与我们取得联
  14. 系:
  15. http://isee.126.com
  16. http://www.vchelp.net
  17. 或:
  18. iseesoft@china.com
  19. 作者:临风
  20.    e-mail:ringphone@sina.com
  21.    功能实现:图像旋转设置对话框处理
  22. 文件版本:
  23. Build 00617
  24. Date  2000-6-17
  25. ********************************************************************/
  26. #include "p_win.h"
  27. #include "..publicgol_proc.h"
  28. #include "filter.h"
  29. #include "draw.h"
  30. #include "rotate.h"
  31. #include "resource.h"
  32. void DrawButton(HWND hWnd,LPDRAWITEMSTRUCT lpInfo);
  33. BOOL CALLBACK WINAPI RotateProc(HWND hWnd,UINT uMsg,UINT wParam,LONG lParam);
  34. void Clear();
  35. HWND hBtWnd[5]; //按钮句柄
  36. HBITMAP hbm;
  37. UINT nInButton=0,nOldButton=0,nPushedButton=0;
  38. BOOL bPushed=FALSE;
  39. RECT rc[5];
  40. //启动图像旋转处理设置对话框
  41. int DoRotate(LPIMAGEPROCSTR lpInfo)
  42. {
  43.    return DialogBox(lpInfo->hInst,MAKEINTRESOURCE(IDD_ROTATE),lpInfo->hParentWnd,(DLGPROC)RotateProc);
  44. }
  45. //对话框处理循环
  46. BOOL CALLBACK WINAPI RotateProc(HWND hWnd,UINT uMsg,UINT wParam,LONG lParam)
  47. {
  48. switch(uMsg)
  49.    {
  50.     case WM_INITDIALOG:
  51.          hbm=LoadBitmap(lpProcInfo->hInst,MAKEINTRESOURCE(IDB_BKG));
  52.          hBtWnd[0]=GetDlgItem(hWnd,IDC_TURNLEFT);
  53. hBtWnd[1]=GetDlgItem(hWnd,IDC_TURNRIGHT);
  54.          hBtWnd[2]=GetDlgItem(hWnd,IDC_HFLIP);
  55.          hBtWnd[3]=GetDlgItem(hWnd,IDC_VFLIP);
  56.          hBtWnd[4]=GetDlgItem(hWnd,IDC_PREVIEW);
  57.          SendMessage(hWnd,WM_MOVE,0,0); //初始化rc
  58.          InitDraw();
  59.          lpProcInfo->result=PR_NULL; //设置操作初值,处理成功将改写该值
  60.          break;
  61.       case WM_PAINT:
  62.        PaintDlgBk(hWnd);
  63.          break;
  64.       case WM_MOVE:
  65.        GetWindowRect(hBtWnd[0],&rc[0]);
  66.          GetWindowRect(hBtWnd[1],&rc[1]);
  67.          GetWindowRect(hBtWnd[2],&rc[2]);
  68.          GetWindowRect(hBtWnd[3],&rc[3]);
  69.          GetWindowRect(hBtWnd[4],&rc[4]);
  70.          break;
  71.       case WM_DRAWITEM:   //绘制按钮
  72.        DrawButton(hWnd,(LPDRAWITEMSTRUCT)lParam);
  73.          break;
  74.       case WM_LBUTTONDOWN:    //以下的鼠标处理消息实现按钮的按下及弹起处理
  75.        bPushed=TRUE;
  76.          nPushedButton=nInButton;
  77.          SetDlgItemText(hWnd,nInButton,"OK"); //该函数目的为发送WM_DRAWITEM消息
  78.          break;
  79.       case WM_LBUTTONUP:
  80.        bPushed=FALSE;
  81.          if(nInButton==nPushedButton)
  82.          {
  83.           SetDlgItemText(hWnd,nInButton,"OK");
  84.           nPushedButton=0;
  85.          switch(nInButton)
  86.           {
  87.            case IDC_TURNLEFT:
  88.               TurnLeft();
  89.                   SetDlgItemText(hWnd,IDC_PREVIEW,"OK");
  90.                 break;
  91.             case IDC_TURNRIGHT:
  92.               TurnRight();
  93.                   SetDlgItemText(hWnd,IDC_PREVIEW,"OK");
  94.                 break;
  95.              case IDC_HFLIP:
  96.              HFlip();
  97.                   SetDlgItemText(hWnd,IDC_PREVIEW,"OK");
  98.                 break;
  99.             case IDC_VFLIP:
  100.               VFlip();
  101.                   SetDlgItemText(hWnd,IDC_PREVIEW,"OK");
  102.                 break;
  103.           }
  104.          }
  105.          nPushedButton=0;
  106.          break;
  107.       case WM_MOUSEMOVE:
  108.       {
  109.        POINT pt;
  110.          GetCursorPos(&pt);
  111.          if(pt.x>rc[0].left && pt.x<rc[0].right && pt.y>rc[0].top && pt.y<rc[0].bottom)
  112.          {
  113.           nInButton=IDC_TURNLEFT;
  114.             if(nInButton!=nOldButton)
  115.             {
  116.              SetDlgItemText(hWnd,nOldButton,"OK");
  117.              if(nPushedButton==nInButton || !bPushed)
  118.                 SetDlgItemText(hWnd,nInButton,"OK");
  119.             }
  120.          }
  121.          else if(pt.x>rc[1].left && pt.x<rc[1].right && pt.y>rc[1].top && pt.y<rc[1].bottom)
  122.          {
  123.           nInButton=IDC_TURNRIGHT;
  124.             if(nInButton!=nOldButton)
  125.             {
  126.              SetDlgItemText(hWnd,nOldButton,"OK");
  127.              if(nPushedButton==nInButton || !bPushed)
  128.                 SetDlgItemText(hWnd,nInButton,"OK");
  129.             }
  130.          }
  131.          else if(pt.x>rc[2].left && pt.x<rc[2].right && pt.y>rc[2].top && pt.y<rc[2].bottom)
  132.          {
  133.           nInButton=IDC_HFLIP;
  134.             if(nInButton!=nOldButton)
  135.             {
  136.                SetDlgItemText(hWnd,nOldButton,"OK");
  137.              if(nPushedButton==nInButton || !bPushed)
  138.                 SetDlgItemText(hWnd,nInButton,"OK");
  139.             }
  140.          }
  141.          else if(pt.x>rc[3].left && pt.x<rc[3].right && pt.y>rc[3].top && pt.y<rc[3].bottom)
  142.          {
  143.           nInButton=IDC_VFLIP;
  144.             if(nInButton!=nOldButton)
  145.             {
  146.              SetDlgItemText(hWnd,nOldButton,"OK");
  147.              if(nPushedButton==nInButton || !bPushed)
  148.                 SetDlgItemText(hWnd,nInButton,"OK");
  149.             }
  150.          }
  151.          else
  152.          {
  153.           nInButton=0;
  154.             if(nInButton!=nOldButton)
  155.             {
  156.              SetDlgItemText(hWnd,nOldButton,"OK");
  157.                nOldButton=0;
  158.             }
  159.          }
  160.          break;
  161.       }
  162.       case WM_COMMAND:
  163.        switch(LOWORD(wParam))
  164.          {
  165.           case IDOK:
  166.              Clear();
  167.                EndDialog(hWnd,Output_Rotate());
  168.                return TRUE;
  169.             case IDCANCEL:
  170.              Clear();
  171.                EndDialog(hWnd,PROCERR_FALSE);
  172.                return FALSE;
  173.             case IDHELP:
  174.              ShowCopyright();
  175.                break;
  176.          }
  177.          break;
  178.       case WM_CLOSE:
  179.        Clear();
  180.          EndDialog(hWnd,PROCERR_FALSE);
  181.          return FALSE;
  182.    }
  183.    return FALSE;
  184. }
  185. //绘制按钮及预览图像
  186. void DrawButton(HWND hWnd,LPDRAWITEMSTRUCT lpInfo)
  187. {
  188. if(lpInfo->CtlType==ODT_STATIC)
  189.    {
  190.     HDC hmemdc;
  191.       hmemdc=CreateCompatibleDC(lpInfo->hDC);
  192.       SelectObject(hmemdc,hbm);
  193.       BitBlt(lpInfo->hDC,0,0,48,48,hmemdc,0,0,SRCCOPY);
  194.       DeleteDC(hmemdc);
  195.       HICON hicon;
  196.       switch(lpInfo->CtlID)
  197.       {
  198.        case IDC_TURNLEFT:
  199.        hicon=LoadIcon(lpProcInfo->hInst,MAKEINTRESOURCE(IDI_TURNLEFT));
  200.             break;
  201.          case IDC_TURNRIGHT:
  202.        hicon=LoadIcon(lpProcInfo->hInst,MAKEINTRESOURCE(IDI_TURNRIGHT));
  203.             break;
  204.          case IDC_HFLIP:
  205.        hicon=LoadIcon(lpProcInfo->hInst,MAKEINTRESOURCE(IDI_HFLIP));
  206.             break;
  207.          case IDC_VFLIP:
  208.        hicon=LoadIcon(lpProcInfo->hInst,MAKEINTRESOURCE(IDI_VFLIP));
  209.             break;
  210.          case IDC_PREVIEW:
  211.           DrawPreView(hWnd,lpInfo);
  212.             return;
  213.       }
  214.       DrawIconEx(lpInfo->hDC,0,0,hicon,48,48,0,NULL,DI_NORMAL);
  215.       DestroyIcon(hicon);
  216.       if(bPushed && nInButton==lpInfo->CtlID && nInButton==nPushedButton)
  217.       {
  218.        DrawEdge(lpInfo->hDC,&lpInfo->rcItem,BDR_SUNKENINNER,BF_RECT);
  219.          nOldButton=nInButton;
  220.       }
  221.       else if(nInButton==lpInfo->CtlID)
  222.       {
  223.        DrawEdge(lpInfo->hDC,&lpInfo->rcItem,BDR_RAISEDINNER,BF_RECT);
  224.          nOldButton=nInButton;
  225.       }
  226.    }
  227. }
  228. //清理内存,准备退出
  229. void Clear()
  230. {
  231.    EndDraw();
  232. DeleteObject(hbm);
  233.    Del(lpBakData);
  234.    Del(lpPreViewData);
  235. }