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

/*-------------------------------------------------
   RESOURCE.C -- Uses an Icon and Pointer Resource
  -------------------------------------------------*/

#define INCL_WIN
#define INCL_GPI

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

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

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

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

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

     hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
                                     &flFrameFlags, szClientClass,
                                     "Icon and Pointer Resources",
                                     0L, NULL, ID_RESOURCE, &hwndClient) ;

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

     WinDestroyWindow (hwndFrame) ;
     WinDestroyMsgQueue (hmq) ;
     WinTerminate (hab) ;

     return 0 ;
     }

MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     static HPOINTER hIcon, hPtr ;
     static SHORT    cxClient, cyClient, xIcon, yIcon ;
     HPS             hps ;
     RECTL           rcl ;

     switch (msg)
          {
          case WM_CREATE:
               hIcon = WinLoadPointer (HWND_DESKTOP, NULL, ID_RESOURCE) ;
               hPtr  = WinLoadPointer (HWND_DESKTOP, NULL, IDP_CIRCLE) ;

               xIcon = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CXICON) ;
               yIcon = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYICON) ;
               return 0 ;

          case WM_SIZE:
               cxClient = SHORT1FROMMP (mp2) ;
               cyClient = SHORT2FROMMP (mp2) ;
               return 0 ;

          case WM_MOUSEMOVE:
               WinSetPointer (HWND_DESKTOP, hPtr) ;
               return 1 ;

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

               WinQueryWindowRect (hwnd, &rcl) ;
               WinFillRect (hps, &rcl, CLR_CYAN) ;

               WinDrawPointer (hps, 0, 0, hIcon, DP_NORMAL) ;
               WinDrawPointer (hps, 0, cyClient - yIcon, hIcon, DP_NORMAL) ;
               WinDrawPointer (hps, cxClient - yIcon, 0, hIcon, DP_NORMAL) ;
               WinDrawPointer (hps, cxClient - xIcon, cyClient - yIcon, hIcon,
                                                       DP_NORMAL) ;

               WinDrawPointer (hps, cxClient / 3, cyClient / 2, hIcon,
                                                       DP_HALFTONED) ;
               WinDrawPointer (hps, 2 * cxClient / 3, cyClient / 2, hIcon,
                                                       DP_INVERTED) ;
               WinEndPaint (hps) ;
               return 0 ;

          case WM_DESTROY:
               WinDestroyPointer (hIcon) ;
               WinDestroyPointer (hPtr) ;
               return 0 ;

          default:
               return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
          }
     return 0 ;
     }

unix.superglobalmegacorp.com

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