File:  [OS/2 SDKs] / pmsdk / samples / petzold / chap06 / checker3.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

/*--------------------------------------------------------------
   CHECKER3.C -- Mouse Hit-Test Demo Program with Child Windows
  --------------------------------------------------------------*/

#define INCL_WIN
#define INCL_GPI

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

#define DIVISIONS 5

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

CHAR szChildClass [] = "Checker3.Child" ;

int main (void)
     {
     static CHAR szClientClass [] = "Checker3" ;
     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, 0) ;

     WinRegisterClass (hab, szChildClass, ChildWndProc, CS_SIZEREDRAW,
                                                        sizeof (USHORT)) ;

     hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
                                     &flFrameFlags, szClientClass,
                                     "Mouse Hit-Test Program No. 3",
                                     0L, NULL, 0, &hwndClient) ;

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

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

VOID DrawLine (HPS hps, LONG x1, LONG y1, LONG x2, LONG y2)
     {
     POINTL ptl ;

     ptl.x = x1 ;  ptl.y = y1 ;  GpiMove (hps, &ptl) ;
     ptl.x = x2 ;  ptl.y = y2 ;  GpiLine (hps, &ptl) ;
     }

MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     static HWND hwndChild [DIVISIONS][DIVISIONS] ;
     SHORT       xBlock, yBlock, x, y ;

     switch (msg)
          {
          case WM_CREATE:
               for (x = 0 ; x < DIVISIONS ; x++)
                    for (y = 0 ; y < DIVISIONS ; y++)

                         hwndChild [x][y] =
                              WinCreateWindow (
                                        hwnd,          /* Parent window   */
                                        szChildClass,  /* Window class    */
                                        NULL,          /* Window text     */
                                        WS_VISIBLE,    /* Window style    */
                                        0, 0, 0, 0,    /* Size & position */
                                        hwnd,          /* Owner window    */
                                        HWND_BOTTOM,   /* Placement       */
                                        y << 8 | x,    /* Child window ID */
                                        NULL,          /* Control data    */
                                        NULL) ;        /* Pres. Params    */
               return 0 ;

          case WM_SIZE:
               xBlock = SHORT1FROMMP (mp2) / DIVISIONS ;
               yBlock = SHORT2FROMMP (mp2) / DIVISIONS ;

               for (x = 0 ; x < DIVISIONS ; x++)
                    for (y = 0 ; y < DIVISIONS ; y++)

                         WinSetWindowPos (hwndChild [x][y], NULL,
                              x * xBlock, y * yBlock, xBlock, yBlock,
                              SWP_MOVE | SWP_SIZE) ;      
               return 0 ;

          case WM_BUTTON1DOWN:
          case WM_BUTTON1DBLCLK:
               WinAlarm (HWND_DESKTOP, WA_WARNING) ;
               return 1 ;

          case WM_ERASEBACKGROUND:
               return 1 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }

MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     HPS    hps ;
     RECTL  rcl ;

     switch (msg)
          {
          case WM_CREATE:
               WinSetWindowUShort (hwnd, 0, 0) ;
               return 0 ;

          case WM_BUTTON1DOWN:
          case WM_BUTTON1DBLCLK:
               WinSetWindowUShort (hwnd, 0, !WinQueryWindowUShort (hwnd, 0)) ;
               WinInvalidateRect (hwnd, NULL, FALSE) ;
               return 1 ;

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

               WinQueryWindowRect (hwnd, &rcl) ;

               WinDrawBorder (hps, &rcl, 1, 1, CLR_NEUTRAL, CLR_BACKGROUND,
                                   DB_STANDARD | DB_INTERIOR) ;

               if (WinQueryWindowUShort (hwnd, 0))
                    {
                    DrawLine (hps, rcl.xLeft,  rcl.yBottom,
                                   rcl.xRight, rcl.yTop) ;
                    DrawLine (hps, rcl.xLeft,  rcl.yTop,
                                   rcl.xRight, rcl.yBottom) ;
                    }
               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.