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

/****************************** Module Header *******************************/
/* Name: bmap.c                                                             */
/*                                                                          */
/*   Presentation Manager Bit Map Sample Application : BMAP                 */
/*                                                                          */
/*   Created by Microsoft Corp., 1988                                       */
/*                                                                          */
/*   DYNAMIC LINK REFERENCES:                                               */
/*                                                                          */
/*       DevCloseDC                                                         */
/*       DevOpenDC                                                          */
/*       DosExit                                                            */
/*       GpiAssociate                                                       */
/*       GpiBitBlt                                                          */
/*       GpiCreateBitmap                                                    */
/*       GpiCreatePS                                                        */
/*       GpiDeleteBitmap                                                    */
/*       GpiDestroyPS                                                       */
/*       GpiLine                                                            */
/*       GpiLoadBitmap                                                      */
/*       GpiMove                                                            */
/*       GpiPolyLine                                                        */
/*       GpiQueryBoundaryData                                               */
/*       GpiRectVisible                                                     */
/*       GpiResetBoundaryData                                               */
/*       GpiSetBackColor                                                    */
/*       GpiSetBitmap                                                       */
/*       GpiSetColor                                                        */
/*       GpiSetDrawControl                                                  */
/*       WinBeginPaint                                                      */
/*       WinCreateMsgQueue                                                  */
/*       WinCreateStdWindow                                                 */
/*       WinDefWindowProc                                                   */
/*       WinDestroyMsgQueue                                                 */
/*       WinDestroyWindow                                                   */
/*       WinDispatchMsg                                                     */
/*       WinDrawBitmap                                                      */
/*       WinDrawText                                                        */
/*       WinEndPaint                                                        */
/*       WinFillRect                                                        */
/*       WinGetMsg                                                          */
/*       WinGetPS                                                           */
/*       WinInitialize                                                      */
/*       WinInvalidateRect                                                  */
/*       WinLoadString                                                      */
/*       WinMessageBox                                                      */
/*       WinPostMsg                                                         */
/*       WinQuerySysValue                                                   */
/*       WinQueryWindowRect                                                 */
/*       WinQueryWindowText                                                 */
/*       WinRegisterClass                                                   */
/*       WinReleasePS                                                       */
/*       WinSendMsg                                                         */
/*       WinSetPointer                                                      */
/*       WinTerminate                                                       */
/*                                                                          */
/****************************************************************************/
 
/*         Defines to include relevant section of PM Header file            */
#define INCL_GPI
#define INCL_WIN
 
/*         PM Header File                                                   */
#include <os2.h>
 
/*         C Library Header Files                                           */
#include <string.h>
 
/*         Application Header File                                          */
#include "bmap.h"
 
void cdecl far Int3();
 
/*             Global variable declarations                                 */
HAB     hab;                       /* Appl anchor block handle              */
HMQ     hmq;                       /* Appl queue handle                     */
 
/*                  various window dependant globals                        */
HWND    hwndFrame;                 /* bmap window frame handle              */
HWND    hwndClient;                /* client area handle                    */
 
HDC     hdcMem;                    /* memory device context handle          */
HPS     hpsMem;                    /* memory presentation space handle      */
 
/*                Bit map related variables & data                          */
HPOINTER hptrArrow; /* handle of the system arrow pointer                   */
HPOINTER hptrWait ; /* handle of the system wait pointer                    */
HBITMAP hbmMapQ = (HBITMAP)NULL; /* handles of previously generated bit     */
HBITMAP hbmMapR = (HBITMAP)NULL; /* maps held in a resource file            */
HBITMAP hbmMap0 = (HBITMAP)NULL; /* handle of bit map generated in bmap     */
BITMAPINFOHEADER bmapinfo; /* details of the bitmap created each            */
                           /* time 'Save Picture' is selected               */
POINTL  bmarray[5];        /* structure specifying source and target        */
                           /* rectangles for GpiBitBlt calls                */
 
/* parameter used when creating a device context for a memory device        */
PSZ         dcdatablk[9] = {(PSZ)0
                           ,(PSZ)"DISPLAY"
                           ,(PSZ)0
                           ,(PSZ)0
                           ,(PSZ)0
                           ,(PSZ)0
                           ,(PSZ)0
                           ,(PSZ)0
                           ,(PSZ)0
                           };
 
USHORT  Current_Selection = 0;   /* Initial value used in the paint routine */
 
LONG  fore_clr;                  /* fore & back colours used in the display */
LONG  back_clr;                  /* of previously generated mono bit maps   */
 
/*                           string variables                               */
CHAR    szText[CCHMAXSTRING];
CHAR    szHelp[CCHMAXSTRING];
CHAR    szVisible[CCHMAXSTRING];
CHAR    szWindowTitle[CCHMAXSTRING];
 
/* Gobals to control selection, greying and ticking, in the Bitmap menu     */
USHORT CurrentTick = 0;
USHORT PreviousTick = 0;
BOOL Saved = FALSE;
 
RECTL   BoundRect; /* bounding rectangle of the simple drawing              */
 
/****************************************************************************/
/* MAIN:                                                                    */
/* Main Procedure                                                           */
/****************************************************************************/
VOID cdecl main(  )
{
    QMSG   qmsg;
 
    hab = WinInitialize(NULL);
    hmq = WinCreateMsgQueue( hab, 0 );
    /************************************************************************/
    /* Check to see if the queue handle is null. If it is creating the      */
    /* message queue will fail and if you continue you will get invalid     */
    /* selectors. So exit the application                                   */
    /************************************************************************/
    if ( !hmq == NULL )
    {
        if ( BmapInitApp() )
        {
            while( WinGetMsg( hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
            {
                WinDispatchMsg( hab, (PQMSG)&qmsg );
            }
        }
        WinDestroyWindow( hwndFrame );
        WinDestroyMsgQueue( hmq );
    }
    WinTerminate( hab );
    DosExit( 1, 0 );
} /* MAIN */
 
 
/****************************************************************************/
/* BMAPWNDPROC:                                                             */
/* Client Window Procedure                                                  */
/****************************************************************************/
MRESULT EXPENTRY BmapWndProc( hwnd, msg, mp1, mp2 )
HWND    hwnd;
USHORT  msg;
MPARAM  mp1;
MPARAM  mp2;
{
    RECTL view;
    RECTL rc;
    HPS   tmphps;
    switch( msg )
    {
        case WM_CLOSE:
            /****************************************************************/
            /* message from system to close the Client window.              */
            /****************************************************************/
            BmapQueryQuit( hwnd );
            return( FALSE );
            break;
 
        case WM_COMMAND:
            /****************************************************************/
            /* A menu item has been selected, or a control is notifying     */
            /* its parent.                                                  */
            /****************************************************************/
            switch (LOUSHORT(mp1))
            {
                case IDMEXIT:
                    /********************************************************/
                    /* EXIT command, menu item or F3 key pressed.           */
                    /********************************************************/
                    BmapQueryQuit( hwnd );
                    return( FALSE );
                    break;
 
                case IDMRESUME:
                    return( FALSE );
                    break;
 
                case IDMEXTHELP:
                    /********************************************************/
                    /* Extended help menu item pressed.                     */
                    /********************************************************/
                    BmapHelp( hwnd, IDSEXTHELP );
                    break;
 
                case IDMHELPINDEX:
                    /********************************************************/
                    /* Help Index menu item pressed.                        */
                    /********************************************************/
                    BmapHelp( hwnd, IDSHELPINDEX );
                    break;
 
                case IDMKEYSHELP:
                    /********************************************************/
                    /* Keys help menu item pressed.                         */
                    /********************************************************/
                    BmapHelp( hwnd, IDSKEYSHELP );
                    break;
 
                case IDMDRAWPIC:
                    /********************************************************/
                    /* Draw Picture menu item pressed.                      */
                    /* Using GPI drawing orders draw a simple picture on    */
                    /* the screen                                           */
                    /********************************************************/
                    Current_Selection = IDMDRAWPIC;
                    WinSetPointer( HWND_DESKTOP, hptrWait );
                    WinInvalidateRect( hwnd
                                     , (PRECTL)NULL
                                     , FALSE
                                     );
                    /* set values used to set ticks in the menu */
                    PreviousTick = CurrentTick;
                    CurrentTick = IDMDRAWPIC;
                    WinSetPointer( HWND_DESKTOP, hptrArrow );
                    return ( FALSE );
                    break;
 
                case IDMSAVEPIC:
                    /********************************************************/
                    /* Save Picture menu item pressed.                      */
                    /* The visible section of the GPI simple picture is     */
                    /* saved as a bit map.  The pointer is set to timer     */
                    /* while this is carried out.  Thus preventing the      */
                    /* selection of other menu items before the bit blt     */
                    /* save completes.                                      */
                    /********************************************************/
                    WinSetPointer( HWND_DESKTOP, hptrWait );
 
                    /* find the visible area of the ps */
                    WinQueryWindowRect( hwnd, (PRECTL)&rc );
 
                    tmphps = WinGetPS( hwnd );
 
                    if ( GpiRectVisible( tmphps, (PRECTL)&BoundRect ) != RVIS_VISIBLE );
                    {
 
                        view.xLeft   = (( BoundRect.xLeft   < rc.xLeft   ) ? rc.xLeft   : BoundRect.xLeft   );
                        view.xRight  = (( BoundRect.xRight  > rc.xRight  ) ? rc.xRight  : (BoundRect.xRight + 1) );
                        view.yBottom = (( BoundRect.yBottom < rc.yBottom ) ? rc.yBottom : BoundRect.yBottom );
                        view.yTop    = (( BoundRect.yTop    > rc.yTop    ) ? rc.yTop    : (BoundRect.yTop + 1)   );
 
                    }
                    /**********************************************************/
                    /* Create a bitmap                                        */
                    /**********************************************************/
                    bmapinfo.cbFix     = 12;
                    bmapinfo.cx        = (USHORT)(view.xRight - view.xLeft);
                    bmapinfo.cy        = (USHORT)(view.yTop - view.yBottom);
                    bmapinfo.cPlanes   = 1L;
                    bmapinfo.cBitCount = 24L;
 
                    if ( hbmMap0 != NULL ) { GpiDeleteBitmap( hbmMap0 ); }
                    hbmMap0 = GpiCreateBitmap( hpsMem
                                             , (PBITMAPINFOHEADER)&bmapinfo
                                             , 0L
                                             , (PBYTE)NULL
                                             , (PBITMAPINFO)NULL
                                             );
 
                    /**********************************************************/
                    /* Select the bit map into the memory device context      */
                    /**********************************************************/
                    GpiSetBitmap( hpsMem, hbmMap0 );
 
                    /***** TARGET ***********/
                    bmarray[0].x = 0;
                    bmarray[0].y = 0;
                    bmarray[1].x = view.xRight - view.xLeft + 1;
                    bmarray[1].y = view.yTop - view.yBottom + 1;
 
                    /***** SOURCE ***********/
                    bmarray[2].x = view.xLeft;
                    bmarray[2].y = view.yBottom;
                    bmarray[3].x = view.xRight + 1;
                    bmarray[3].y = view.yTop + 1;
 
                    GpiBitBlt( hpsMem
                             , tmphps
                             , 4L
                             , (PPOINTL)bmarray
                             , (LONG)ROP_SRCCOPY
                             , (LONG)BBO_IGNORE
                             );
                    WinReleasePS( tmphps );
                    GpiSetBitmap( hpsMem, (HBITMAP)NULL );
 
                    Current_Selection = IDMDRAWPIC;
                    Saved = TRUE;
                    PreviousTick = CurrentTick;
                    WinSetPointer( HWND_DESKTOP, hptrArrow );
                    return ( FALSE );
                    break;
 
                case IDMBLTPIC:
                    WinSetPointer( HWND_DESKTOP, hptrWait );
                    Current_Selection = IDMBLTPIC;
                    WinInvalidateRect( hwnd
                                     , (PRECTL)NULL
                                     , FALSE
                                     );
                    PreviousTick = CurrentTick;
                    CurrentTick = IDMBLTPIC;
                    WinSetPointer( HWND_DESKTOP, hptrArrow );
                    return ( FALSE );
                    break;
 
                case IDMWINDRAW:
                    WinSetPointer( HWND_DESKTOP, hptrWait );
                    Current_Selection = IDMWINDRAW;
                    fore_clr = CLR_RED;
                    back_clr = CLR_BLUE;
                    /* trying out Presman */
                    if ( hbmMapQ == NULL )
                    {
                        hbmMapQ = GpiLoadBitmap( hpsMem
                                               , NULL
                                               , ID_BITMAP2
                                               , 0L
                                               , 0L
                                               );
                    }
                    WinInvalidateRect( hwnd
                                     , (PRECTL)NULL
                                     , FALSE
                                     );
 
                    PreviousTick = CurrentTick;
                    CurrentTick = IDMWINDRAW;
                    WinSetPointer( HWND_DESKTOP, hptrArrow );
                    return ( FALSE );
                    break;
 
                case IDMGPIBITBLT:
                    WinSetPointer( HWND_DESKTOP, hptrWait );
                    Current_Selection = IDMGPIBITBLT;
                    if ( hbmMapR == NULL )
                    {
                        hbmMapR = GpiLoadBitmap( hpsMem
                                               , NULL
                                               , ID_BITMAP3
                                               , 0L
                                               , 0L
                                               );
                    }
                    GpiSetBitmap( hpsMem, hbmMapR );
                    WinInvalidateRect( hwnd
                                     , (PRECTL)NULL
                                     , FALSE
                                     );
                    PreviousTick = CurrentTick;
                    CurrentTick = IDMGPIBITBLT;
                    WinSetPointer( HWND_DESKTOP, hptrArrow );
                    return ( FALSE );
                    break;
 
                /****************************************************************/
                /* Unrecognised WM_COMMAND ID's are processed in a default way  */
                /****************************************************************/
                default:
                    return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
            } /* WM_COMMAND switch */
            break; /* WM_COMMAND */
 
        case WM_CREATE:
            /****************************************************************/
            /* window is initialised                                        */
            /****************************************************************/
            WindowInitialization( hwnd );
            return( FALSE );
            break;
 
        case WM_DESTROY:
            /****************************************************************/
            /* Disassociate the two GPI PS's from their respctive DC's and  */
            /* destroy the PS's. Finally destroy the memory DC.             */
            /****************************************************************/
            WindowDestroy();
            return( FALSE );
            break;
 
        case WM_ERASEBACKGROUND:
            /****************************************************************/
            /* Let frame control erase background for us                    */
            /****************************************************************/
            return ( TRUE );
            break;
 
        case WM_HELP:
            /****************************************************************/
            /* F1 pressed help processing would go here.                               */
            /****************************************************************/
            BmapHelp( hwnd, IDSEXTHELP );
            return ( FALSE );
            break;
 
        case WM_INITMENU:
            if ( LOUSHORT( mp1 ) == IDMBITMAP )
            {
                /***********************************************************/
                /* selection of menu with no selections made previously    */
                /* grey out save and bitblt options                        *
                /***********************************************************/
                if ( CurrentTick == 0 )
                {
                    MenuGrey( IDMSAVEPIC, TRUE );
                    MenuGrey( IDMBLTPIC, TRUE );
                }
 
                /* tick drawing method and reset previous method            */
                if ( PreviousTick != CurrentTick )
                {
                    if ( CurrentTick != 0 )
                    {
                        MenuTick( PreviousTick, FALSE );
                        MenuTick( CurrentTick, TRUE );
                    }
                }
 
                if ( CurrentTick == IDMDRAWPIC )
                {
                    MenuGrey( IDMSAVEPIC, FALSE );
                }
                else
                {
                    MenuGrey( IDMSAVEPIC, TRUE );
                }
 
                if ( Saved )
                {
                    MenuGrey( IDMBLTPIC, FALSE );
                }
            } /* endif ( LOUSHORT( mp1 ) == IDMBITMAP ) */
            return ( FALSE );
            break;
 
        case WM_PAINT:
            /****************************************************************/
            /* Time for the window to draw itself.                          */
            /****************************************************************/
            BmapPaint( hwnd );
 
            return( FALSE );
            break;
 
        default:
            /****************************************************************/
            /* Everything else comes here.  This call MUST exist            */
            /* in your window proc.                                         */
            /****************************************************************/
            return(WinDefWindowProc(hwnd, msg, mp1, mp2));
            break;
   } /* switch */
} /* BMAPWNDPROC */
 
/****************************************************************************/
/*                                                                          */
/*  Procedures in alphabetical order                                        */
/*                                                                          */
/****************************************************************************/
 
VOID BmapHelp( hwnd, HelpStr )
HWND   hwnd;
USHORT HelpStr;
{
    CHAR szHelpStr[CCHMAXSTRING];
 
    /************************************************************************/
    /* Get the appropriate Help String.                                     */
    /************************************************************************/
    WinLoadString(hab, NULL, HelpStr, CCHMAXSTRING, (PSZ)szHelpStr);
 
    /************************************************************************/
    /* Display the help string                                              */
    /************************************************************************/
    WinMessageBox( HWND_DESKTOP
                 , hwnd
                 , (PSZ)szHelpStr
                 , (PSZ)szWindowTitle
                 , 0
                 , MB_CUANOTIFICATION | MB_CANCEL | MB_MOVEABLE
                 );
 
} /* BMAPHELP */
 
/****************************************************************************/
/* BMAPINITAPP:                                                             */
/* Initialisation carried out when the window is created.                   */
/*  - Register Application Window Class                                     */
/*  - Creates Standard Window                                               */
/*  - Loads various strings used by the application                         */
/****************************************************************************/
BOOL FAR BmapInitApp( VOID )
{
    CHAR szClassName[10];
    ULONG ctlData;
 
    WinLoadString( hab, NULL, IDSNAME, sizeof(szClassName), (PSZ)szClassName );
 
    if ( !WinRegisterClass( hab
                          , (PSZ)szClassName
                          , (PFNWP)BmapWndProc
                          , CS_SIZEREDRAW
                          , 0 ) )
        return( FALSE );
 
    ctlData = FCF_STANDARD;
    hwndFrame = WinCreateStdWindow( HWND_DESKTOP
                                  , WS_VISIBLE | FS_STANDARD
                                  , &ctlData
                                  , (PSZ)szClassName
                                  , (PSZ)NULL
                                  , 0L
                                  , (HMODULE)NULL
                                  , ID_BMAP
                                  , (HWND FAR *)&hwndClient
                                  );
 
    /************************************************************************/
    /* Get the window title given to the window by the system               */
    /************************************************************************/
    WinQueryWindowText(hwndFrame, CCHMAXSTRING, (PSZ)szWindowTitle);
 
    /************************************************************************/
    /* Initialise the arrow and wait system pointer handles                 */
    /************************************************************************/
    hptrArrow = WinQuerySysPointer( HWND_DESKTOP
                                  , SPTR_ARROW
                                  , FALSE
                                  );
    hptrWait = WinQuerySysPointer( HWND_DESKTOP
                                 , SPTR_WAIT
                                 , FALSE
                                 );
 
    /************************************************************************/
    /* Initialise global strings used in the application                    */
    /************************************************************************/
    WinLoadString(hab, NULL, IDSGENERALHELP,CCHMAXSTRING, (PSZ)szHelp);
    WinLoadString(hab, NULL, IDSTEXTSTR,   CCHMAXSTRING, (PSZ)szText);
    WinLoadString(hab, NULL, IDSVISIBLE,   CCHMAXSTRING, (PSZ)szVisible);
 
    return( TRUE );
} /* BMAPINITAPP */
 
 
/****************************************************************************/
/* BMAPPAINT:                                                               */
/* The application paints its window                                        */
/****************************************************************************/
VOID BmapPaint( hwnd )
HWND hwnd;
{
    HPS     hps;
    RECTL   rect;
    RECTL   txtrect;
    RECTL   PaintArea;
    LONG    Visible;
 
    POINTL Pos;
    POINTL Coords[3];
    POINTL Straight[4];
 
    hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&PaintArea );
    WinFillRect( hps, (PRECTL)&PaintArea, SYSCLR_WINDOW );
 
    WinQueryWindowRect( hwnd, (PRECTL)&rect );
    switch ( Current_Selection )
    {
        case IDMDRAWPIC:
            /* draw a simple picture make up from gpi drawing orders        */
            /* get bounding rectangle for the simple drawing                */
            GpiResetBoundaryData( hps );
            GpiSetDrawControl( hps
                             , DCTL_BOUNDARY
                             , DCTL_ON
                             );
 
            /* do simple draw */
            SimplePic( hps );
            /* assimilate the boundary data */
            GpiQueryBoundaryData( hps
                                , (PRECTL)&BoundRect
                                );
 
            GpiSetDrawControl( hps
                             , DCTL_BOUNDARY
                             , DCTL_OFF
                             );
 
            Visible = GpiRectVisible( hps, (PRECTL)&BoundRect );
            if ( Visible != RVIS_VISIBLE )
            {
                WinMessageBox( HWND_DESKTOP
                             , hwnd
                             , (PSZ)szVisible
                             , (PSZ)szWindowTitle
                             , 0
                             , MB_CUANOTIFICATION | MB_CANCEL | MB_MOVEABLE
                             );
            }
            break;
 
        case IDMBLTPIC:
            /* do redraw of simple picture  */
            WinFillRect(hps, (PRECTL)&PaintArea, CLR_CYAN);
            GpiSetBitmap( hpsMem, hbmMap0 );
 
            /****************************************************************/
            /* Set up the source/target rectangle information needed for    */
            /* the Bitblt operation.( in device coordinates )               */
            /****************************************************************/
            /***** TARGET ***********/
            bmarray[0].x = rect.xLeft;
            bmarray[0].y = rect.yBottom;
            bmarray[1].x = rect.xRight + 2;
            bmarray[1].y = rect.yTop + 2;
 
 
 
            /***** SOURCE ***********/
            bmarray[2].x = 0;
            bmarray[2].y = 0;
 
            /****************************************************************/
            /* Bitblt from the memory device to the window on screen        */
            /****************************************************************/
            GpiBitBlt( hps
                     , hpsMem
                     , 3L
                     , (PPOINTL)bmarray
                     , (LONG)ROP_SRCCOPY
                     , (LONG)BBO_IGNORE
                     );
 
            GpiSetBitmap( hpsMem, (HBITMAP)NULL );
            break;
 
        case IDMWINDRAW:
            /* WinDrawBitmap a bitmap loaded using WinLoadBitmap            */
            fore_clr = CLR_YELLOW;
            back_clr = CLR_GREEN;
            WinDrawBitmap( hps
                         , hbmMapQ
                         , (PRECTL)NULL    /* whole bit map is draw         */
                         , (PPOINTL)&rect
                         , fore_clr        /* required for mono bit maps    */
                         , back_clr
                         , DBM_STRETCH
                         );
            break;
 
        case IDMGPIBITBLT:
            /* GpiBitBlt a bitmap loaded using WinLoadBitmap                */
            /****************************************************************/
            /* Set up the source/target rectangle information needed for    */
            /* the Bitblt operation.( in device coordinates )               */
            /****************************************************************/
            /***** TARGET ***********/
            bmarray[0].x = 0;
            bmarray[0].y = 0;
            bmarray[1].x = rect.xRight - rect.xLeft;
            bmarray[1].y = rect.yTop - rect.yBottom;
 
 
            /***** SOURCE ***********/
            bmarray[2].x = 0;
            bmarray[2].y = 0;
 
            /****************************************************************/
            /* Bitblt from the memory device to the window on screen        */
            /****************************************************************/
            GpiBitBlt( hps
                     , hpsMem
                     , 3L
                     , (PPOINTL)bmarray
                     , (LONG)ROP_SRCCOPY
                     , (LONG)BBO_OR
                     );
            break;
 
        case 0:
            /* text always shown at the start of the application execution  */
            WinDrawText(hps,
                        strlen(szText),
                        (PSZ)szText,
                        &rect,
                        SYSCLR_WINDOWTEXT,
                        SYSCLR_WINDOW,
                        DT_CENTER | DT_VCENTER);
            break;
 
        default:
            break;
    } /* end of switch ( Current_Selection ) */
 
    WinEndPaint( hps );
} /* BMAPPAINT */
 
/****************************************************************************/
/* BMAPQUERYQUIT:                                                           */
/* The user is required to confirm/dismiss the request to quit the program  */
/****************************************************************************/
VOID BmapQueryQuit( hwnd )
HWND hwnd;
{
    CHAR    szTerminate[CCHMAXSTRING];
 
    WinLoadString(hab, NULL, IDSTERMINATE, CCHMAXSTRING , (PSZ)szTerminate);
 
    if ( WinMessageBox( HWND_DESKTOP
                      , hwnd
                      , (PSZ)szTerminate
                      , (PSZ)szWindowTitle
                      , 0
                      , MB_CUAWARNING | MB_YESNO | MB_DEFBUTTON2 | MB_MOVEABLE
                      ) == MBID_YES)
    {
        WinPostMsg( hwnd, WM_QUIT, (ULONG)0, (ULONG)0 );
    }
} /* BMAPQUERYQUIT */
 
/****************************************************************************/
/* MENUGREY:                                                                */
/* Enable/Disable menuitem according to option                              */
/****************************************************************************/
VOID MenuGrey( item, option )
USHORT item;
BOOL   option;
{
    WinSendMsg( WinWindowFromID( hwndFrame, FID_MENU )
              , MM_SETITEMATTR
              , MPFROM2SHORT( item, TRUE)
              , MPFROM2SHORT( MIA_DISABLED, option ? MIA_DISABLED : ~MIA_DISABLED )
              );
    return;
} /* MENUGREY */
 
/****************************************************************************/
/* MENUTICK:                                                                */
/* Tick/Untick menuitem according to option                                 */
/****************************************************************************/
VOID MenuTick( item, option )
USHORT item;
BOOL   option;
{
    WinSendMsg( WinWindowFromID( hwndFrame, FID_MENU )
              , MM_SETITEMATTR
              , MPFROM2SHORT( item, TRUE)
              , MPFROM2SHORT( MIA_CHECKED, option ? MIA_CHECKED : ~MIA_CHECKED )
              );
 
    return;
} /* MENUTICK */
 
/****************************************************************************/
/* SIMPLEPIC:                                                               */
/* A selection of GPI drawing commands exercised when 'Draw - Picture'      */
/* option is selected.                                                      */
/****************************************************************************/
VOID SimplePic( hps )
HPS hps;
{
    POINTL Pos;
    POINTL Coords[4];
 
    /* draw a rhomboid */
    Pos.x = 100;
    Pos.y = 50;
    GpiMove( hps
            , &Pos
            );
 
    Coords[0].x =  50;
    Coords[0].y =  100;
    Coords[1].x =  100;
    Coords[1].y =  150;
    Coords[2].x =  150;
    Coords[2].y =  100;
    /* three green sides */
    GpiSetColor( hps, CLR_GREEN );
    GpiPolyLine( hps
               , 3L
               , Coords
               );
    /* one blue edge */
    GpiSetColor( hps, CLR_BLUE );
    GpiLine( hps
           , &Pos
           );
 
    /* draw a rectangle */
    Pos.x = 200;
    Pos.y = 200;
    GpiMove( hps
           , &Pos
           );
 
    Coords[0].x =  200;
    Coords[0].y =  250;
    Coords[1].x =  250;
    Coords[1].y =  250;
    Coords[2].x =  250;
    Coords[2].y =  200;
    Coords[3].x =  200;
    Coords[3].y =  200;
    /* four red sides */
    GpiSetColor( hps, CLR_RED );
    GpiPolyLine( hps
               , 4L
               , Coords
               );
} /* SIMPLEPIC */
 
VOID WindowDestroy()
{
    GpiAssociate( hpsMem, (HDC)NULL );
    GpiDestroyPS( hpsMem );
    DevCloseDC( hdcMem );
}
 
/****************************************************************************/
/* Initialisation to be carried out when the window is created.             */
/****************************************************************************/
VOID WindowInitialization(hwnd)
HWND hwnd;
{
    SIZEL   size;
 
    /************************************************************************/
    /* Get the maximum client area size. Create a window DC for the client  */
    /* area and a normal GPI Presentation Space and associate the two.      */
    /* The GPI PS will be the maximum client area size and be in pels.      */
    /* Create a memory DC compatible with the screen.                       */
    /************************************************************************/
    size.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXFULLSCREEN);
    size.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYFULLSCREEN);
 
    /************************************************************************/
    /*    THE MEMORY DEVICE                                                 */
    /* Get a dc for the memory device                                       */
    /************************************************************************/
    hdcMem = DevOpenDC( hab
                      , OD_MEMORY
                      , (PSZ)"*"
                      , 8L
                      , (PDEVOPENDATA)dcdatablk
                      , (HDC)NULL
                      );
    /************************************************************************/
    /* NB DO THE DC/PS ASSOCIATE HERE                                       */
    /* create the memory ps to the dimensions of the full screen            */
    /************************************************************************/
 
    hpsMem = GpiCreatePS( hab
                        , hdcMem
                        , (PSIZEL)&size
                        , (LONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC
                        );
} /* WINDOWINITIALIZATION */

unix.superglobalmegacorp.com

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