home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12546.ZIP / CLIENT.C < prev    next >
Text File  |  1990-03-19  |  4KB  |  177 lines

  1. //-------------------------
  2. //-CLIENT.C----------------
  3. //-------------------------
  4.  
  5. #define INCL_PM
  6. #define INCL_WIN
  7. #define INCL_DOS
  8.  
  9. #include <os2.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include "client.h"
  14.  
  15. // TRACER step 1 - include tracer.h
  16. #include "tracer.h"
  17.  
  18. // TRACER step 2 - declare TRACER VARIABLES
  19. TRACERVARIABLES
  20.  
  21. //----------------------------------------------
  22. //-main()---------------------------------------
  23. //----------------------------------------------
  24.  
  25. int cdecl main( )
  26. {
  27.     QMSG      qmsg;
  28.     ULONG     ctldata;
  29.  
  30.     hAB = WinInitialize( NULL );
  31.  
  32.     hmqClient = WinCreateMsgQueue( hAB, 0 );
  33.  
  34.     if ( !WinRegisterClass( hAB,
  35.                            (PCH)szPClass,
  36.                            (PFNWP)ClientWndProc,
  37.                            CS_SIZEREDRAW,
  38.                            0) )
  39.         return( 0 );
  40.  
  41.     ctldata = FCF_TITLEBAR      | FCF_SYSMENU       |
  42.               FCF_SIZEBORDER    | FCF_MINMAX        |
  43.               FCF_ICON          | FCF_SHELLPOSITION |
  44.               FCF_TASKLIST ;
  45.  
  46.     hPanelFrm = WinCreateStdWindow( HWND_DESKTOP,
  47.                                      WS_DISABLED,
  48.                                      &ctldata,
  49.                                      (PCH)szPClass,
  50.                                      NULL,
  51.                                      0L,
  52.                                      (HMODULE)NULL,
  53.                                      CLIENTICON,
  54.                                      (HWND FAR *)&hPanelWnd );
  55.  
  56.     WinEnableWindow( hPanelFrm, TRUE );
  57.     WinShowWindow( hPanelFrm, TRUE );
  58.  
  59.     while( WinGetMsg( hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
  60.         WinDispatchMsg( hAB, (PQMSG)&qmsg );
  61.  
  62.     WinDestroyWindow( hPanelFrm );
  63.     WinDestroyMsgQueue( hmqClient );
  64.     WinTerminate( hAB );
  65. }
  66.  
  67. //----------------------------------------------
  68. //-ClientWndProc()------------------------------
  69. //----------------------------------------------
  70.  
  71. MRESULT EXPENTRY ClientWndProc( HWND hWnd, USHORT msg,
  72.                                 MPARAM mp1, MPARAM mp2 )
  73.  
  74. {
  75.     switch (msg)
  76.     {
  77.     case WM_CREATE:
  78.  
  79.          // TRACER step 3 - attach to TRACER
  80.          TRACERHELLO
  81.  
  82.          return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  83.          break;
  84.  
  85.     // TRACER step 4 - obtain system resources - Don't forget break;
  86.     TRACERATTACH
  87.  
  88.     break;
  89.  
  90.     case WM_CLOSE:
  91.  
  92.          // TRACER step 5
  93.          TRACER("Posting QUIT");
  94.          WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  95.  
  96.          break;
  97.  
  98.     case WM_SETFOCUS:
  99.  
  100.          // TRACER step 5
  101.          TRACER("Setting Focus");
  102.          return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  103.  
  104.          break;
  105.  
  106.     case WM_ENABLE:
  107.  
  108.          return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  109.  
  110.          break;
  111.  
  112.     case WM_BUTTON1DOWN:
  113.  
  114.          sprintf( szTraceBuf, "WM_BUTTON1DOWN hit at %ld",
  115.                         WinGetCurrentTime( hAB ) );
  116.  
  117.          TRACER( szTraceBuf );
  118.  
  119.          break;
  120.  
  121.     case WM_PAINT:
  122.  
  123.          ClientPaint( hWnd, msg, mp1, mp2 );
  124.  
  125.          break;
  126.  
  127.     case WM_ERASEBACKGROUND:
  128.  
  129.          return( TRUE );
  130.  
  131.          break;
  132.  
  133.     default:
  134.          return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  135.          break;
  136.  
  137.     }
  138.     return(0L);
  139. }
  140.  
  141. //----------------------------------------------
  142. //-ClientPaint()--------------------------------
  143. //----------------------------------------------
  144.  
  145. void FAR PASCAL ClientPaint( HWND hWnd, USHORT msg,
  146.                              MPARAM mp1, MPARAM mp2 )
  147. {
  148.  
  149. int         aiCharWidth;
  150. HPS         hPS;
  151. FONTMETRICS fm;
  152. RECTL       rRect;
  153. CHARBUNDLE  cb;
  154. POINTL      pt;
  155.  
  156.     hPS = WinBeginPaint( hWnd, (HPS)NULL, (PWRECT)NULL );
  157.  
  158.     // TRACER step 5
  159.     TRACER("ClientPaint()");
  160.  
  161.     GpiErase( hPS );
  162.  
  163.     GpiQueryFontMetrics( hPS, (LONG)sizeof fm , &fm);
  164.     aiCharWidth = (SHORT)fm.lAveCharWidth;
  165.  
  166.     WinQueryWindowRect( hWnd, &rRect );
  167.     pt.x = (rRect.xRight / 2) -
  168.             ((strlen(szMessage) / 2) * aiCharWidth);
  169.     pt.y = (rRect.yTop / 2);
  170.  
  171.     cb.lColor = CLR_BLACK;
  172.     GpiSetAttrs( hPS, PRIM_CHAR, CBB_COLOR, 0L, (PBUNDLE)&cb );
  173.  
  174.     GpiCharStringAt( hPS, &pt, (LONG)strlen( szMessage ), szMessage );
  175.     WinEndPaint( hPS );
  176. }
  177.