XFORM.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /******************************************************************************
  2. *       This is a part of the Microsoft Source Code Samples. 
  3. *       Copyright (C) 1993-1997 Microsoft Corporation.
  4. *       All rights reserved. 
  5. *       This source code is only intended as a supplement to 
  6. *       Microsoft Development Tools and/or WinHelp documentation.
  7. *       See these sources for detailed information regarding the 
  8. *       Microsoft samples programs.
  9. ******************************************************************************/
  10. /*-------------------------------------------------------------------------*
  11. | XFORM MODULE
  12. *---------------------------------------------------------------------------*/
  13. #include <windows.h>
  14. #include "gdidemo.h"
  15. #include "xform.h"
  16. VOID ResetXForm(HWND);
  17. VOID DrawXForm(HWND);
  18. /*---------------------------------------------------------------------------*
  19. | CREATE XFORM WINDOW PROCEDURE
  20. *---------------------------------------------------------------------------*/
  21. HWND FAR CreateXFormWindow(HWND hWndClient, int nItem)
  22. {
  23.     HANDLE          hInstance;
  24.     MDICREATESTRUCT mcs;
  25.     static char buffer[256];
  26.     hInstance = GETINSTANCE(hWndClient);
  27.     LoadString (hInstance, XFORMTITLE, buffer, 256);
  28.     /*
  29.     ** Initialize the MDI create struct for creation of the
  30.     ** test window.
  31.     */
  32.     mcs.szClass = XFORMCLASS;
  33.     mcs.szTitle = buffer;
  34.     mcs.hOwner  = hInstance;
  35.     mcs.x       = CW_USEDEFAULT;
  36.     mcs.y       = CW_USEDEFAULT;
  37.     mcs.cx      = CW_USEDEFAULT;
  38.     mcs.cy      = CW_USEDEFAULT;
  39.     mcs.style   = 0l;
  40.     mcs.lParam  = (LONG)nItem;
  41.     return((HWND)SendMessage(hWndClient,WM_MDICREATE,0,(LONG)(LPMDICREATESTRUCT)&mcs));
  42. }
  43. /*---------------------------------------------------------------------------*
  44. | XFORM WINDOW PROCEDURE
  45. *---------------------------------------------------------------------------*/
  46. LONG APIENTRY XFormProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam)
  47. {
  48.     switch(wMsg)
  49.     {
  50.         case WM_CREATE:
  51.             XFormCreateProc(hWnd);
  52.             break;
  53.         case WM_MOVE:
  54.             ResetXForm(hWnd);
  55.             break;
  56.         case WM_TIMER:
  57.             DrawXForm(hWnd);
  58.             break;
  59.         case WM_COMMAND:
  60.             XFormCommandProc(hWnd,wParam,lParam);
  61.             break;
  62.         case WM_PAINT:
  63.             XFormPaintProc(hWnd);
  64.             break;
  65.         case WM_DESTROY:
  66.             XFormDestroyProc(hWnd);
  67.             break;
  68.         default:
  69.             return(DefMDIChildProc(hWnd,wMsg,wParam,lParam));
  70.     }
  71.     return(0l);
  72. }
  73. /*---------------------------------------------------------------------------*
  74. | XFORM CREATE PROCEDURE
  75. *---------------------------------------------------------------------------*/
  76. BOOL XFormCreateProc(HWND hWnd)
  77. {
  78.     PXFORMDATA pxd;
  79. #ifndef NOT_IMPLEMENTED
  80.     RECT       rect;
  81.     int        dx,dy;
  82. #endif
  83.     if(AllocWindowInfo(hWnd,sizeof(XFORMDATA)))
  84.     {
  85.         if(pxd = (PXFORMDATA)LockWindowInfo(hWnd))
  86.         {
  87. #ifndef NOT_IMPLEMENTED
  88.             GetClientRect(hWnd,&rect);
  89.             dx = (rect.right + rect.left) >> 4;
  90.             dy = (rect.bottom + rect.top) >> 4;
  91.             pxd->pObject[0].x = dx << 1;
  92.             pxd->pObject[0].y = 0;
  93.             pxd->pObject[1].x = dx;
  94.             pxd->pObject[1].y = dy;
  95.             pxd->pObject[2].x = 0;
  96.             pxd->pObject[2].y = dy;
  97.             pxd->pObject[3].x = dx << 1;
  98.             pxd->pObject[3].y = 0;
  99.             pxd->nObject      = 4;
  100.             pxd->xForm.eM11 = (float) 0.866;
  101.             pxd->xForm.eM12 = (float) 0.5;
  102.             pxd->xForm.eM21 = (float)-0.5;
  103.             pxd->xForm.eM22 = (float) 0.866;
  104.             pxd->xForm.eDx  = (float) 0;
  105.             pxd->xForm.eDy  = (float) 0;
  106. #endif
  107.             UnlockWindowInfo(hWnd);
  108.             SetTimer(hWnd,1,500,NULL);
  109.             return(TRUE);
  110.         }
  111.         FreeWindowInfo(hWnd);
  112.     }
  113.     return(FALSE);
  114. }
  115. /*---------------------------------------------------------------------------*
  116. | XFORM COMMAND PROCEDURE
  117. *---------------------------------------------------------------------------*/
  118. BOOL XFormCommandProc(HWND hWnd, WPARAM wParam, LONG lParam)
  119. {
  120.     hWnd   = hWnd;
  121.     wParam = wParam;
  122.     lParam = lParam;
  123.     return(TRUE);
  124. }
  125. /*---------------------------------------------------------------------------*
  126. | XFORM PAINT PROCEDURE
  127. *---------------------------------------------------------------------------*/
  128. VOID XFormPaintProc(HWND hWnd)
  129. {
  130.     HDC         hDC;
  131.     PAINTSTRUCT ps;
  132.     if(hDC = BeginPaint(hWnd,&ps))
  133.         EndPaint(hWnd,&ps);
  134.     ResetXForm(hWnd);
  135.     return;
  136. }
  137. /*---------------------------------------------------------------------------*
  138. | XFORM DESTROY PROCEDURE
  139. *---------------------------------------------------------------------------*/
  140. VOID XFormDestroyProc(HWND hWnd)
  141. {
  142.     KillTimer(hWnd,1);
  143.     FreeWindowInfo(hWnd);
  144.     return;
  145. }
  146. VOID ResetXForm(HWND hWnd)
  147. {
  148.     PXFORMDATA pxd;
  149.     HDC        hDC;
  150. #ifndef NOT_IMPLEMENTED
  151.     RECT       rect;
  152. #endif
  153.     if(pxd = (PXFORMDATA)LockWindowInfo(hWnd))
  154.     {
  155.         if(hDC = GetDC(hWnd))
  156.         {
  157. #ifndef NOT_IMPLEMENTED
  158.             GetClientRect(hWnd,&rect);
  159.             BitBlt(hDC,0,0,rect.right,rect.bottom,(HDC)0,0,0,0);
  160.             SetViewportOrgEx(hDC,rect.right >> 1,rect.bottom >> 1,NULL);
  161.             SetWorldTransform(hDC,(LPXFORM)&pxd->xForm);
  162.             Polyline(hDC,pxd->pObject,pxd->nObject);
  163.             ModifyWorldTransform(hDC,(LPXFORM)&pxd->xForm,MWT_IDENTITY);
  164.             // I have to put this in since GDI currently doesn't
  165.             // reset the drawing attributes -- 5/24/91
  166.             //
  167.             SetViewportOrgEx(hDC,0,0,NULL);
  168. #endif
  169.             ReleaseDC(hWnd,hDC);
  170.         }
  171.         UnlockWindowInfo(hWnd);
  172.     }
  173.     return;
  174. }
  175. VOID DrawXForm(HWND hWnd)
  176. {
  177.     PXFORMDATA pxd;
  178.     HDC        hDC;
  179. #ifndef NOT_IMPLEMENTED
  180.     XFORM      xForm;
  181.     RECT       rect;
  182. #endif
  183.     if(pxd = (PXFORMDATA)LockWindowInfo(hWnd))
  184.     {
  185.         if(hDC = GetDC(hWnd))
  186.         {
  187. #ifndef NOT_IMPLEMENTED
  188.             GetClientRect(hWnd,&rect);
  189.             SetViewportOrgEx(hDC,rect.right >> 1, rect.bottom >> 1,NULL);
  190.             SetWorldTransform(hDC,(LPXFORM)&pxd->xForm);
  191.             Polyline(hDC,pxd->pObject,pxd->nObject);
  192.             ModifyWorldTransform(hDC,(LPXFORM)&pxd->xForm,MWT_RIGHTMULTIPLY);
  193.             Polyline(hDC,pxd->pObject,pxd->nObject);
  194.             GetWorldTransform(hDC,(LPXFORM)&xForm);
  195.             pxd->xForm.eM11 = xForm.eM11;
  196.             pxd->xForm.eM12 = xForm.eM12;
  197.             pxd->xForm.eM21 = xForm.eM21;
  198.             pxd->xForm.eM22 = xForm.eM22;
  199.             pxd->xForm.eDx  = xForm.eDx;
  200.             pxd->xForm.eDy  = xForm.eDy;
  201.             ModifyWorldTransform(hDC,(LPXFORM)&pxd->xForm,MWT_IDENTITY);
  202.             // I have to put this in since GDI currently doesn't
  203.             // reset the drawing attributes -- 5/24/91
  204.             //
  205.             SetViewportOrgEx(hDC,0,0,NULL);
  206. #endif
  207.             ReleaseDC(hWnd,hDC);
  208.         }
  209.         UnlockWindowInfo(hWnd);
  210.     }
  211.     return;
  212. }