File:  [OS/2 SDKs] / pmsdk / samples / petzold / chap06 / web.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:28:13 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: pmsdk-1988, HEAD
Microsoft OS/2 SDK PM 08-08-1988

/*--------------------------------------
   WEB.C -- Mouse Movement Demo Program 
  --------------------------------------*/

#define INCL_WIN
#define INCL_GPI

#include <os2.h>
#include <stddef.h>

MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;

int main (void)
     {
     static CHAR szClientClass [] = "Web" ;
     HAB         hab ;
     HMQ         hmq ;
     HWND        hwndFrame, hwndClient ;
     QMSG        qmsg ;
     ULONG       flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
     ULONG       flFrameStyle = WS_VISIBLE ;

     hab = WinInitialize (0) ;
     hmq = WinCreateMsgQueue (hab, 0) ;

     WinRegisterClass (hab, szClientClass, ClientWndProc,
					   CS_SIZEREDRAW | CS_SYNCPAINT, 0) ;

     hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
                                     &flFrameFlags, szClientClass,
                                     "Mouse Movement Demo",
				     0L, NULL, 0, &hwndClient) ;

     while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
          WinDispatchMsg (hab, &qmsg) ;

     WinDestroyWindow (hwndFrame) ;
     WinDestroyMsgQueue (hmq) ;
     WinTerminate (hab) ;
     
     return 0 ;
     }

VOID DrawWeb (HPS hps, POINTL *pptlPointerPos, POINTL *pptlClient)
     {
     POINTL ptl ;

          /*--------------------------------------
             Lower Left to Pointer to Upper Right
            --------------------------------------*/

     ptl.x = 0 ;
     ptl.y = 0 ;
     GpiMove (hps, &ptl) ;
     GpiLine (hps, pptlPointerPos) ;
     GpiLine (hps, pptlClient) ;

          /*--------------------------------------
             Upper Left to Pointer to Lower Right
            --------------------------------------*/

     ptl.x = 0 ;
     ptl.y = pptlClient->y ;

     GpiMove (hps, &ptl) ;
     GpiLine (hps, pptlPointerPos) ;

     ptl.x = pptlClient->x ;
     ptl.y = 0 ;

     GpiLine (hps, &ptl) ;

          /*-----------------------------------------
             Lower Middle to Pointer to Upper Middle
            -----------------------------------------*/

     ptl.x = pptlClient->x / 2 ;
     ptl.y = 0 ;

     GpiMove (hps, &ptl) ;
     GpiLine (hps, pptlPointerPos) ;

     ptl.y = pptlClient->y ;

     GpiLine (hps, &ptl) ;

          /*----------------------------------------
             Middle Left to Pointer to Middle Right
            ----------------------------------------*/

     ptl.x = 0 ;
     ptl.y = pptlClient->y / 2 ;

     GpiMove (hps, &ptl) ;
     GpiLine (hps, pptlPointerPos) ;

     ptl.x = pptlClient->x ;

     GpiLine (hps, &ptl) ;
     }

MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     static POINTL ptlClient, ptlPointerPos ;
     HPS           hps ;

     switch (msg)
          {
          case WM_SIZE:
               ptlClient.x = SHORT1FROMMP (mp2) ;
               ptlClient.y = SHORT2FROMMP (mp2) ;
               return 0 ;
     
          case WM_MOUSEMOVE:
               hps = WinGetPS (hwnd) ;

               GpiSetMix (hps, FM_INVERT) ;
               DrawWeb (hps, &ptlPointerPos, &ptlClient) ;

               ptlPointerPos.x = MOUSEMSG(&msg)->x ;
               ptlPointerPos.y = MOUSEMSG(&msg)->y ;

               DrawWeb (hps, &ptlPointerPos, &ptlClient) ;

               WinReleasePS (hps) ;
               return 1 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULL, NULL) ;
               GpiErase (hps) ;

	       GpiSetMix (hps, FM_INVERT) ;
               DrawWeb (hps, &ptlPointerPos, &ptlClient) ;

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.