home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / report.zip / DEMO.C < prev    next >
Text File  |  1994-09-27  |  9KB  |  252 lines

  1. #define  INCL_BASE
  2. #define  INCL_WIN
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include "report.h"
  9. #include "demo.h"
  10.  
  11. HAB        hab;            /*Handle to the anchor block*/
  12. HMQ        hmq;            /*Handle to the message queue*/
  13. HWND       hwndFrame;      /*handle to the Main Frame Window*/
  14. HWND       hwndClient;     /*handle to the Client Window*/
  15. HWND       hwndReport;
  16. USHORT     usChecked = IDM_100;
  17.  
  18. #define    szFileName  "demo.doc"
  19.  
  20. #define INFO(hwnd,message)  WinMessageBox(HWND_DESKTOP,hwnd,\
  21.                                           message,\
  22.                                           "Information",\
  23.                                            1,\
  24.                                            MB_CANCEL|MB_INFORMATION|\
  25.                                            MB_MOVEABLE)
  26.  
  27. VOID    DoScale(USHORT usScale);
  28. HWND    CreateMainFrame(VOID);
  29. MRESULT EXPENTRY ClientWndProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2);
  30. int     main(void);
  31.  
  32. /*----------------------------------------------------------------------*/
  33.                    /* Main () Creates the Editor Window */
  34. /*----------------------------------------------------------------------*/
  35. main()
  36. {
  37. QMSG qmsg;
  38.  /*Initialize PM*/
  39.  
  40.     hab= WinInitialize(0);
  41.  
  42.  /*Create the Message Queue*/
  43.  
  44.     hmq= WinCreateMsgQueue(hab,100);
  45.  
  46.     RptRegisterClass(hab);
  47.  
  48.     CreateMainFrame();
  49.  
  50.     while (WinGetMsg(hab,
  51.                  &qmsg,
  52.                  (ULONG)NULL,
  53.                  (USHORT)NULL,
  54.                  (USHORT)NULL))
  55.            WinDispatchMsg(hab, &qmsg);
  56.  
  57.    WinDestroyWindow(hwndFrame);
  58.    WinDestroyMsgQueue(hmq);
  59.    WinTerminate(hab);
  60.    return(0);
  61. }
  62.  
  63. /*----------------------------------------------------------------------*/
  64. /* Create Main Frame Window */
  65. /*----------------------------------------------------------------------*/
  66. HWND  CreateMainFrame()
  67. {
  68. ULONG   fulCreate=FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX | FCF_SIZEBORDER |
  69.                   FCF_TASKLIST|FCF_SHELLPOSITION|FCF_NOBYTEALIGN|FCF_MENU;
  70.  
  71.  
  72.         WinRegisterClass(hab,
  73.                          "Main Class",
  74.                          (PFNWP)ClientWndProc,
  75.                           CS_SIZEREDRAW|CS_CLIPCHILDREN|CS_CLIPSIBLINGS,
  76.                           0);
  77.  
  78.  
  79.         hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  80.                                        WS_VISIBLE,
  81.                                        &fulCreate,
  82.                                        (PSZ)"Main Class",
  83.                                        (PSZ)"",
  84.                                        0,
  85.                                        (HMODULE)NULL,
  86.                                        ID_RESOURCE,
  87.                                        &hwndClient);
  88.  
  89.         return (hwndFrame);
  90. }
  91. //------------------------------------------------------------------------//
  92. //                      Client Window Procedure                           //
  93. //------------------------------------------------------------------------//
  94. MRESULT EXPENTRY ClientWndProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  95. {
  96. RECTL        rectl;
  97. HPS          hps;
  98. ULONG        ulPageWidth,ulPageHeight;
  99. CHAR         szBuffer[400]="";
  100.  
  101.       switch(msg)
  102.            {
  103.             case WM_DESTROY:
  104.                  WinDestroyWindow(hwndReport);
  105.                  break;
  106.  
  107.             case WM_CREATE:
  108.                  WinSetPointer(HWND_DESKTOP,
  109.                                WinQuerySysPointer(HWND_DESKTOP,
  110.                                SPTR_WAIT,FALSE));
  111.  
  112.  
  113.                  hwndReport=WinCreateWindow(hwnd,
  114.                                              szReportClass,
  115.                                              (PSZ) "",
  116.                                              WS_VISIBLE,
  117.                                              0,
  118.                                              0,
  119.                                              0,
  120.                                              0,
  121.                                              hwnd,
  122.                                              HWND_TOP,
  123.                                              10,
  124.                                              NULL,
  125.                                              NULL);
  126.  
  127.                  WinSendMsg(hwndReport,
  128.                             RPM_QUERYPAGESIZE,
  129.                             MPFROMP(&ulPageWidth),
  130.                             MPFROMP(&ulPageHeight));
  131.  
  132.                  WinSendMsg(hwndReport,
  133.                             RPM_SETMARGINVIEW,
  134.                             MPFROMSHORT(TRUE),
  135.                             NULL);
  136.  
  137.                  WinSendMsg(hwndReport,
  138.                             RPM_SETFILE,
  139.                             MPFROMP(szFileName),
  140.                             NULL);
  141.  
  142.                  WinSetPointer(HWND_DESKTOP,
  143.                                WinQuerySysPointer(HWND_DESKTOP,
  144.                                SPTR_ARROW,FALSE));
  145.  
  146.                  return(MRFROMSHORT(FALSE));
  147.  
  148.             case WM_CONTROL:
  149.                  if(SHORT1FROMMP(mp1) == 10)
  150.                    {
  151.                     if(SHORT2FROMMP(mp2) == 6)
  152.                       {
  153.                        sprintf(szBuffer,"Notification ID:%d,  Subcode:%d,Line# %d. Please see report.h for more detail.",
  154.                             SHORT2FROMMP(mp1),SHORT1FROMMP(mp2),SHORT2FROMMP(mp2));
  155.                        INFO(hwnd,szBuffer);
  156.                       }
  157.                    }
  158.  
  159.                  break;
  160.  
  161.             //------------------------------------//
  162.             //             WM_PAINT               //
  163.             //------------------------------------//
  164.             case WM_PAINT:
  165.                  hps=WinBeginPaint(hwnd,NULLHANDLE,&rectl);
  166.                  WinFillRect(hps,&rectl,CLR_DARKGRAY);
  167.                  WinEndPaint(hps);
  168.                  return(MRFROMSHORT(FALSE));
  169.  
  170.             //------------------------------------//
  171.             //             WM_SIZE                //
  172.             //------------------------------------//
  173.  
  174.             case WM_SIZE:
  175.  
  176.                  //Make Sure the Report Control's top left corner is
  177.                  //aligned with the frames top left corner.
  178.  
  179.                  WinSetWindowPos(hwndReport,
  180.                                  HWND_TOP,
  181.                                  0,
  182.                                  0,
  183.                                  SHORT1FROMMP(mp2),
  184.                                  SHORT2FROMMP(mp2),
  185.                                  SWP_MOVE|SWP_SIZE);
  186.  
  187.                  return(MRFROMSHORT(FALSE));
  188.  
  189.             //------------------------------------//
  190.             //             WM_COMMAND             //
  191.             //------------------------------------//
  192.             case WM_COMMAND:
  193.                 switch(SHORT1FROMMP(mp1))
  194.                     {
  195.                      case  IDM_PRINT:
  196.                            WinSetPointer(HWND_DESKTOP,
  197.                                          WinQuerySysPointer(HWND_DESKTOP,
  198.                                          SPTR_WAIT,FALSE));
  199.  
  200.                            WinSendMsg(hwndReport,
  201.                                       RPM_PRINT,
  202.                                       NULL,
  203.                                       NULL);
  204.  
  205.                            WinSetPointer(HWND_DESKTOP,
  206.                                          WinQuerySysPointer(HWND_DESKTOP,
  207.                                          SPTR_ARROW,FALSE));
  208.                            break;
  209.  
  210.                      case IDM_100:
  211.                      case IDM_50:
  212.                      case IDM_75:
  213.                      case IDM_150:
  214.                      case IDM_200:
  215.                      case IDM_FITALL:
  216.                           DoScale(SHORT1FROMMP(mp1));
  217.                           break;
  218.                     }
  219.         }
  220.  
  221.   return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  222. }
  223.  
  224. VOID DoScale(USHORT usScale)
  225. {
  226. div_t   divResult;
  227. FIXED   fx;
  228. FIXED   fy;
  229.  
  230.   WinCheckMenuItem(WinWindowFromID(hwndFrame,FID_MENU),usChecked,FALSE);
  231.   WinCheckMenuItem(WinWindowFromID(hwndFrame,FID_MENU),usScale,TRUE);
  232.  
  233.   usChecked = usScale;
  234.  
  235.   if(usScale == IDM_FITALL)
  236.     {
  237.      fx = fy = MAKEFIXED(0,0);
  238.     }
  239.   else
  240.     {
  241.      divResult = div(usScale,100);
  242.      fx        = MAKEFIXED(divResult.quot, (65536 * divResult.rem)/100);
  243.      fy        = MAKEFIXED(divResult.quot, (65536 * divResult.rem)/100);
  244.     }
  245.  
  246.   WinSendMsg(hwndReport,
  247.              RPM_SETVIEWSCALE,
  248.              (MPARAM)fx,
  249.              (MPARAM)fy);
  250.   return;
  251. }
  252.