|
|
1.1 root 1: /****************************** Module Header *******************************/
2: /* Name: bmap.c */
3: /* */
4: /* Presentation Manager Bit Map Sample Application : BMAP */
5: /* */
6: /* Created by Microsoft Corp., 1988 */
7: /* */
8: /* DYNAMIC LINK REFERENCES: */
9: /* */
10: /* DevCloseDC */
11: /* DevOpenDC */
12: /* DosExit */
13: /* GpiAssociate */
14: /* GpiBitBlt */
15: /* GpiCreateBitmap */
16: /* GpiCreatePS */
17: /* GpiDeleteBitmap */
18: /* GpiDestroyPS */
19: /* GpiLine */
20: /* GpiLoadBitmap */
21: /* GpiMove */
22: /* GpiPolyLine */
23: /* GpiQueryBoundaryData */
24: /* GpiRectVisible */
25: /* GpiResetBoundaryData */
26: /* GpiSetBackColor */
27: /* GpiSetBitmap */
28: /* GpiSetColor */
29: /* GpiSetDrawControl */
30: /* WinBeginPaint */
31: /* WinCreateMsgQueue */
32: /* WinCreateStdWindow */
33: /* WinDefWindowProc */
34: /* WinDestroyMsgQueue */
35: /* WinDestroyWindow */
36: /* WinDispatchMsg */
37: /* WinDrawBitmap */
38: /* WinDrawText */
39: /* WinEndPaint */
40: /* WinFillRect */
41: /* WinGetMsg */
42: /* WinGetPS */
43: /* WinInitialize */
44: /* WinInvalidateRect */
45: /* WinLoadString */
46: /* WinMessageBox */
47: /* WinPostMsg */
48: /* WinQuerySysValue */
49: /* WinQueryWindowRect */
50: /* WinQueryWindowText */
51: /* WinRegisterClass */
52: /* WinReleasePS */
53: /* WinSendMsg */
54: /* WinSetPointer */
55: /* WinTerminate */
56: /* */
57: /****************************************************************************/
58:
59: /* Defines to include relevant section of PM Header file */
60: #define INCL_GPI
61: #define INCL_WIN
62:
63: /* PM Header File */
64: #include <os2.h>
65:
66: /* C Library Header Files */
67: #include <string.h>
68:
69: /* Application Header File */
70: #include "bmap.h"
71:
72: void cdecl far Int3();
73:
74: /* Global variable declarations */
75: HAB hab; /* Appl anchor block handle */
76: HMQ hmq; /* Appl queue handle */
77:
78: /* various window dependant globals */
79: HWND hwndFrame; /* bmap window frame handle */
80: HWND hwndClient; /* client area handle */
81:
82: HDC hdcMem; /* memory device context handle */
83: HPS hpsMem; /* memory presentation space handle */
84:
85: /* Bit map related variables & data */
86: HPOINTER hptrArrow; /* handle of the system arrow pointer */
87: HPOINTER hptrWait ; /* handle of the system wait pointer */
88: HBITMAP hbmMapQ = (HBITMAP)NULL; /* handles of previously generated bit */
89: HBITMAP hbmMapR = (HBITMAP)NULL; /* maps held in a resource file */
90: HBITMAP hbmMap0 = (HBITMAP)NULL; /* handle of bit map generated in bmap */
91: BITMAPINFOHEADER bmapinfo; /* details of the bitmap created each */
92: /* time 'Save Picture' is selected */
93: POINTL bmarray[5]; /* structure specifying source and target */
94: /* rectangles for GpiBitBlt calls */
95:
96: /* parameter used when creating a device context for a memory device */
97: PSZ dcdatablk[9] = {(PSZ)0
98: ,(PSZ)"DISPLAY"
99: ,(PSZ)0
100: ,(PSZ)0
101: ,(PSZ)0
102: ,(PSZ)0
103: ,(PSZ)0
104: ,(PSZ)0
105: ,(PSZ)0
106: };
107:
108: USHORT Current_Selection = 0; /* Initial value used in the paint routine */
109:
110: LONG fore_clr; /* fore & back colours used in the display */
111: LONG back_clr; /* of previously generated mono bit maps */
112:
113: /* string variables */
114: CHAR szText[CCHMAXSTRING];
115: CHAR szHelp[CCHMAXSTRING];
116: CHAR szVisible[CCHMAXSTRING];
117: CHAR szWindowTitle[CCHMAXSTRING];
118:
119: /* Gobals to control selection, greying and ticking, in the Bitmap menu */
120: USHORT CurrentTick = 0;
121: USHORT PreviousTick = 0;
122: BOOL Saved = FALSE;
123:
124: RECTL BoundRect; /* bounding rectangle of the simple drawing */
125:
126: /****************************************************************************/
127: /* MAIN: */
128: /* Main Procedure */
129: /****************************************************************************/
130: VOID cdecl main( )
131: {
132: QMSG qmsg;
133:
134: hab = WinInitialize(NULL);
135: hmq = WinCreateMsgQueue( hab, 0 );
136: /************************************************************************/
137: /* Check to see if the queue handle is null. If it is creating the */
138: /* message queue will fail and if you continue you will get invalid */
139: /* selectors. So exit the application */
140: /************************************************************************/
141: if ( !hmq == NULL )
142: {
143: if ( BmapInitApp() )
144: {
145: while( WinGetMsg( hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
146: {
147: WinDispatchMsg( hab, (PQMSG)&qmsg );
148: }
149: }
150: WinDestroyWindow( hwndFrame );
151: WinDestroyMsgQueue( hmq );
152: }
153: WinTerminate( hab );
154: DosExit( 1, 0 );
155: } /* MAIN */
156:
157:
158: /****************************************************************************/
159: /* BMAPWNDPROC: */
160: /* Client Window Procedure */
161: /****************************************************************************/
162: MRESULT EXPENTRY BmapWndProc( hwnd, msg, mp1, mp2 )
163: HWND hwnd;
164: USHORT msg;
165: MPARAM mp1;
166: MPARAM mp2;
167: {
168: RECTL view;
169: RECTL rc;
170: HPS tmphps;
171: switch( msg )
172: {
173: case WM_CLOSE:
174: /****************************************************************/
175: /* message from system to close the Client window. */
176: /****************************************************************/
177: BmapQueryQuit( hwnd );
178: return( FALSE );
179: break;
180:
181: case WM_COMMAND:
182: /****************************************************************/
183: /* A menu item has been selected, or a control is notifying */
184: /* its parent. */
185: /****************************************************************/
186: switch (LOUSHORT(mp1))
187: {
188: case IDMEXIT:
189: /********************************************************/
190: /* EXIT command, menu item or F3 key pressed. */
191: /********************************************************/
192: BmapQueryQuit( hwnd );
193: return( FALSE );
194: break;
195:
196: case IDMRESUME:
197: return( FALSE );
198: break;
199:
200: case IDMEXTHELP:
201: /********************************************************/
202: /* Extended help menu item pressed. */
203: /********************************************************/
204: BmapHelp( hwnd, IDSEXTHELP );
205: break;
206:
207: case IDMHELPINDEX:
208: /********************************************************/
209: /* Help Index menu item pressed. */
210: /********************************************************/
211: BmapHelp( hwnd, IDSHELPINDEX );
212: break;
213:
214: case IDMKEYSHELP:
215: /********************************************************/
216: /* Keys help menu item pressed. */
217: /********************************************************/
218: BmapHelp( hwnd, IDSKEYSHELP );
219: break;
220:
221: case IDMDRAWPIC:
222: /********************************************************/
223: /* Draw Picture menu item pressed. */
224: /* Using GPI drawing orders draw a simple picture on */
225: /* the screen */
226: /********************************************************/
227: Current_Selection = IDMDRAWPIC;
228: WinSetPointer( HWND_DESKTOP, hptrWait );
229: WinInvalidateRect( hwnd
230: , (PRECTL)NULL
231: , FALSE
232: );
233: /* set values used to set ticks in the menu */
234: PreviousTick = CurrentTick;
235: CurrentTick = IDMDRAWPIC;
236: WinSetPointer( HWND_DESKTOP, hptrArrow );
237: return ( FALSE );
238: break;
239:
240: case IDMSAVEPIC:
241: /********************************************************/
242: /* Save Picture menu item pressed. */
243: /* The visible section of the GPI simple picture is */
244: /* saved as a bit map. The pointer is set to timer */
245: /* while this is carried out. Thus preventing the */
246: /* selection of other menu items before the bit blt */
247: /* save completes. */
248: /********************************************************/
249: WinSetPointer( HWND_DESKTOP, hptrWait );
250:
251: /* find the visible area of the ps */
252: WinQueryWindowRect( hwnd, (PRECTL)&rc );
253:
254: tmphps = WinGetPS( hwnd );
255:
256: if ( GpiRectVisible( tmphps, (PRECTL)&BoundRect ) != RVIS_VISIBLE );
257: {
258:
259: view.xLeft = (( BoundRect.xLeft < rc.xLeft ) ? rc.xLeft : BoundRect.xLeft );
260: view.xRight = (( BoundRect.xRight > rc.xRight ) ? rc.xRight : (BoundRect.xRight + 1) );
261: view.yBottom = (( BoundRect.yBottom < rc.yBottom ) ? rc.yBottom : BoundRect.yBottom );
262: view.yTop = (( BoundRect.yTop > rc.yTop ) ? rc.yTop : (BoundRect.yTop + 1) );
263:
264: }
265: /**********************************************************/
266: /* Create a bitmap */
267: /**********************************************************/
268: bmapinfo.cbFix = 12;
269: bmapinfo.cx = (USHORT)(view.xRight - view.xLeft);
270: bmapinfo.cy = (USHORT)(view.yTop - view.yBottom);
271: bmapinfo.cPlanes = 1L;
272: bmapinfo.cBitCount = 24L;
273:
274: if ( hbmMap0 != NULL ) { GpiDeleteBitmap( hbmMap0 ); }
275: hbmMap0 = GpiCreateBitmap( hpsMem
276: , (PBITMAPINFOHEADER)&bmapinfo
277: , 0L
278: , (PBYTE)NULL
279: , (PBITMAPINFO)NULL
280: );
281:
282: /**********************************************************/
283: /* Select the bit map into the memory device context */
284: /**********************************************************/
285: GpiSetBitmap( hpsMem, hbmMap0 );
286:
287: /***** TARGET ***********/
288: bmarray[0].x = 0;
289: bmarray[0].y = 0;
290: bmarray[1].x = view.xRight - view.xLeft + 1;
291: bmarray[1].y = view.yTop - view.yBottom + 1;
292:
293: /***** SOURCE ***********/
294: bmarray[2].x = view.xLeft;
295: bmarray[2].y = view.yBottom;
296: bmarray[3].x = view.xRight + 1;
297: bmarray[3].y = view.yTop + 1;
298:
299: GpiBitBlt( hpsMem
300: , tmphps
301: , 4L
302: , (PPOINTL)bmarray
303: , (LONG)ROP_SRCCOPY
304: , (LONG)BBO_IGNORE
305: );
306: WinReleasePS( tmphps );
307: GpiSetBitmap( hpsMem, (HBITMAP)NULL );
308:
309: Current_Selection = IDMDRAWPIC;
310: Saved = TRUE;
311: PreviousTick = CurrentTick;
312: WinSetPointer( HWND_DESKTOP, hptrArrow );
313: return ( FALSE );
314: break;
315:
316: case IDMBLTPIC:
317: WinSetPointer( HWND_DESKTOP, hptrWait );
318: Current_Selection = IDMBLTPIC;
319: WinInvalidateRect( hwnd
320: , (PRECTL)NULL
321: , FALSE
322: );
323: PreviousTick = CurrentTick;
324: CurrentTick = IDMBLTPIC;
325: WinSetPointer( HWND_DESKTOP, hptrArrow );
326: return ( FALSE );
327: break;
328:
329: case IDMWINDRAW:
330: WinSetPointer( HWND_DESKTOP, hptrWait );
331: Current_Selection = IDMWINDRAW;
332: fore_clr = CLR_RED;
333: back_clr = CLR_BLUE;
334: /* trying out Presman */
335: if ( hbmMapQ == NULL )
336: {
337: hbmMapQ = GpiLoadBitmap( hpsMem
338: , NULL
339: , ID_BITMAP2
340: , 0L
341: , 0L
342: );
343: }
344: WinInvalidateRect( hwnd
345: , (PRECTL)NULL
346: , FALSE
347: );
348:
349: PreviousTick = CurrentTick;
350: CurrentTick = IDMWINDRAW;
351: WinSetPointer( HWND_DESKTOP, hptrArrow );
352: return ( FALSE );
353: break;
354:
355: case IDMGPIBITBLT:
356: WinSetPointer( HWND_DESKTOP, hptrWait );
357: Current_Selection = IDMGPIBITBLT;
358: if ( hbmMapR == NULL )
359: {
360: hbmMapR = GpiLoadBitmap( hpsMem
361: , NULL
362: , ID_BITMAP3
363: , 0L
364: , 0L
365: );
366: }
367: GpiSetBitmap( hpsMem, hbmMapR );
368: WinInvalidateRect( hwnd
369: , (PRECTL)NULL
370: , FALSE
371: );
372: PreviousTick = CurrentTick;
373: CurrentTick = IDMGPIBITBLT;
374: WinSetPointer( HWND_DESKTOP, hptrArrow );
375: return ( FALSE );
376: break;
377:
378: /****************************************************************/
379: /* Unrecognised WM_COMMAND ID's are processed in a default way */
380: /****************************************************************/
381: default:
382: return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
383: } /* WM_COMMAND switch */
384: break; /* WM_COMMAND */
385:
386: case WM_CREATE:
387: /****************************************************************/
388: /* window is initialised */
389: /****************************************************************/
390: WindowInitialization( hwnd );
391: return( FALSE );
392: break;
393:
394: case WM_DESTROY:
395: /****************************************************************/
396: /* Disassociate the two GPI PS's from their respctive DC's and */
397: /* destroy the PS's. Finally destroy the memory DC. */
398: /****************************************************************/
399: WindowDestroy();
400: return( FALSE );
401: break;
402:
403: case WM_ERASEBACKGROUND:
404: /****************************************************************/
405: /* Let frame control erase background for us */
406: /****************************************************************/
407: return ( TRUE );
408: break;
409:
410: case WM_HELP:
411: /****************************************************************/
412: /* F1 pressed help processing would go here. */
413: /****************************************************************/
414: BmapHelp( hwnd, IDSEXTHELP );
415: return ( FALSE );
416: break;
417:
418: case WM_INITMENU:
419: if ( LOUSHORT( mp1 ) == IDMBITMAP )
420: {
421: /***********************************************************/
422: /* selection of menu with no selections made previously */
423: /* grey out save and bitblt options *
424: /***********************************************************/
425: if ( CurrentTick == 0 )
426: {
427: MenuGrey( IDMSAVEPIC, TRUE );
428: MenuGrey( IDMBLTPIC, TRUE );
429: }
430:
431: /* tick drawing method and reset previous method */
432: if ( PreviousTick != CurrentTick )
433: {
434: if ( CurrentTick != 0 )
435: {
436: MenuTick( PreviousTick, FALSE );
437: MenuTick( CurrentTick, TRUE );
438: }
439: }
440:
441: if ( CurrentTick == IDMDRAWPIC )
442: {
443: MenuGrey( IDMSAVEPIC, FALSE );
444: }
445: else
446: {
447: MenuGrey( IDMSAVEPIC, TRUE );
448: }
449:
450: if ( Saved )
451: {
452: MenuGrey( IDMBLTPIC, FALSE );
453: }
454: } /* endif ( LOUSHORT( mp1 ) == IDMBITMAP ) */
455: return ( FALSE );
456: break;
457:
458: case WM_PAINT:
459: /****************************************************************/
460: /* Time for the window to draw itself. */
461: /****************************************************************/
462: BmapPaint( hwnd );
463:
464: return( FALSE );
465: break;
466:
467: default:
468: /****************************************************************/
469: /* Everything else comes here. This call MUST exist */
470: /* in your window proc. */
471: /****************************************************************/
472: return(WinDefWindowProc(hwnd, msg, mp1, mp2));
473: break;
474: } /* switch */
475: } /* BMAPWNDPROC */
476:
477: /****************************************************************************/
478: /* */
479: /* Procedures in alphabetical order */
480: /* */
481: /****************************************************************************/
482:
483: VOID BmapHelp( hwnd, HelpStr )
484: HWND hwnd;
485: USHORT HelpStr;
486: {
487: CHAR szHelpStr[CCHMAXSTRING];
488:
489: /************************************************************************/
490: /* Get the appropriate Help String. */
491: /************************************************************************/
492: WinLoadString(hab, NULL, HelpStr, CCHMAXSTRING, (PSZ)szHelpStr);
493:
494: /************************************************************************/
495: /* Display the help string */
496: /************************************************************************/
497: WinMessageBox( HWND_DESKTOP
498: , hwnd
499: , (PSZ)szHelpStr
500: , (PSZ)szWindowTitle
501: , 0
502: , MB_CUANOTIFICATION | MB_CANCEL | MB_MOVEABLE
503: );
504:
505: } /* BMAPHELP */
506:
507: /****************************************************************************/
508: /* BMAPINITAPP: */
509: /* Initialisation carried out when the window is created. */
510: /* - Register Application Window Class */
511: /* - Creates Standard Window */
512: /* - Loads various strings used by the application */
513: /****************************************************************************/
514: BOOL FAR BmapInitApp( VOID )
515: {
516: CHAR szClassName[10];
517: ULONG ctlData;
518:
519: WinLoadString( hab, NULL, IDSNAME, sizeof(szClassName), (PSZ)szClassName );
520:
521: if ( !WinRegisterClass( hab
522: , (PSZ)szClassName
523: , (PFNWP)BmapWndProc
524: , CS_SIZEREDRAW
525: , 0 ) )
526: return( FALSE );
527:
528: ctlData = FCF_STANDARD;
529: hwndFrame = WinCreateStdWindow( HWND_DESKTOP
530: , WS_VISIBLE | FS_STANDARD
531: , &ctlData
532: , (PSZ)szClassName
533: , (PSZ)NULL
534: , 0L
535: , (HMODULE)NULL
536: , ID_BMAP
537: , (HWND FAR *)&hwndClient
538: );
539:
540: /************************************************************************/
541: /* Get the window title given to the window by the system */
542: /************************************************************************/
543: WinQueryWindowText(hwndFrame, CCHMAXSTRING, (PSZ)szWindowTitle);
544:
545: /************************************************************************/
546: /* Initialise the arrow and wait system pointer handles */
547: /************************************************************************/
548: hptrArrow = WinQuerySysPointer( HWND_DESKTOP
549: , SPTR_ARROW
550: , FALSE
551: );
552: hptrWait = WinQuerySysPointer( HWND_DESKTOP
553: , SPTR_WAIT
554: , FALSE
555: );
556:
557: /************************************************************************/
558: /* Initialise global strings used in the application */
559: /************************************************************************/
560: WinLoadString(hab, NULL, IDSGENERALHELP,CCHMAXSTRING, (PSZ)szHelp);
561: WinLoadString(hab, NULL, IDSTEXTSTR, CCHMAXSTRING, (PSZ)szText);
562: WinLoadString(hab, NULL, IDSVISIBLE, CCHMAXSTRING, (PSZ)szVisible);
563:
564: return( TRUE );
565: } /* BMAPINITAPP */
566:
567:
568: /****************************************************************************/
569: /* BMAPPAINT: */
570: /* The application paints its window */
571: /****************************************************************************/
572: VOID BmapPaint( hwnd )
573: HWND hwnd;
574: {
575: HPS hps;
576: RECTL rect;
577: RECTL txtrect;
578: RECTL PaintArea;
579: LONG Visible;
580:
581: POINTL Pos;
582: POINTL Coords[3];
583: POINTL Straight[4];
584:
585: hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&PaintArea );
586: WinFillRect( hps, (PRECTL)&PaintArea, SYSCLR_WINDOW );
587:
588: WinQueryWindowRect( hwnd, (PRECTL)&rect );
589: switch ( Current_Selection )
590: {
591: case IDMDRAWPIC:
592: /* draw a simple picture make up from gpi drawing orders */
593: /* get bounding rectangle for the simple drawing */
594: GpiResetBoundaryData( hps );
595: GpiSetDrawControl( hps
596: , DCTL_BOUNDARY
597: , DCTL_ON
598: );
599:
600: /* do simple draw */
601: SimplePic( hps );
602: /* assimilate the boundary data */
603: GpiQueryBoundaryData( hps
604: , (PRECTL)&BoundRect
605: );
606:
607: GpiSetDrawControl( hps
608: , DCTL_BOUNDARY
609: , DCTL_OFF
610: );
611:
612: Visible = GpiRectVisible( hps, (PRECTL)&BoundRect );
613: if ( Visible != RVIS_VISIBLE )
614: {
615: WinMessageBox( HWND_DESKTOP
616: , hwnd
617: , (PSZ)szVisible
618: , (PSZ)szWindowTitle
619: , 0
620: , MB_CUANOTIFICATION | MB_CANCEL | MB_MOVEABLE
621: );
622: }
623: break;
624:
625: case IDMBLTPIC:
626: /* do redraw of simple picture */
627: WinFillRect(hps, (PRECTL)&PaintArea, CLR_CYAN);
628: GpiSetBitmap( hpsMem, hbmMap0 );
629:
630: /****************************************************************/
631: /* Set up the source/target rectangle information needed for */
632: /* the Bitblt operation.( in device coordinates ) */
633: /****************************************************************/
634: /***** TARGET ***********/
635: bmarray[0].x = rect.xLeft;
636: bmarray[0].y = rect.yBottom;
637: bmarray[1].x = rect.xRight + 2;
638: bmarray[1].y = rect.yTop + 2;
639:
640:
641:
642: /***** SOURCE ***********/
643: bmarray[2].x = 0;
644: bmarray[2].y = 0;
645:
646: /****************************************************************/
647: /* Bitblt from the memory device to the window on screen */
648: /****************************************************************/
649: GpiBitBlt( hps
650: , hpsMem
651: , 3L
652: , (PPOINTL)bmarray
653: , (LONG)ROP_SRCCOPY
654: , (LONG)BBO_IGNORE
655: );
656:
657: GpiSetBitmap( hpsMem, (HBITMAP)NULL );
658: break;
659:
660: case IDMWINDRAW:
661: /* WinDrawBitmap a bitmap loaded using WinLoadBitmap */
662: fore_clr = CLR_YELLOW;
663: back_clr = CLR_GREEN;
664: WinDrawBitmap( hps
665: , hbmMapQ
666: , (PRECTL)NULL /* whole bit map is draw */
667: , (PPOINTL)&rect
668: , fore_clr /* required for mono bit maps */
669: , back_clr
670: , DBM_STRETCH
671: );
672: break;
673:
674: case IDMGPIBITBLT:
675: /* GpiBitBlt a bitmap loaded using WinLoadBitmap */
676: /****************************************************************/
677: /* Set up the source/target rectangle information needed for */
678: /* the Bitblt operation.( in device coordinates ) */
679: /****************************************************************/
680: /***** TARGET ***********/
681: bmarray[0].x = 0;
682: bmarray[0].y = 0;
683: bmarray[1].x = rect.xRight - rect.xLeft;
684: bmarray[1].y = rect.yTop - rect.yBottom;
685:
686:
687: /***** SOURCE ***********/
688: bmarray[2].x = 0;
689: bmarray[2].y = 0;
690:
691: /****************************************************************/
692: /* Bitblt from the memory device to the window on screen */
693: /****************************************************************/
694: GpiBitBlt( hps
695: , hpsMem
696: , 3L
697: , (PPOINTL)bmarray
698: , (LONG)ROP_SRCCOPY
699: , (LONG)BBO_OR
700: );
701: break;
702:
703: case 0:
704: /* text always shown at the start of the application execution */
705: WinDrawText(hps,
706: strlen(szText),
707: (PSZ)szText,
708: &rect,
709: SYSCLR_WINDOWTEXT,
710: SYSCLR_WINDOW,
711: DT_CENTER | DT_VCENTER);
712: break;
713:
714: default:
715: break;
716: } /* end of switch ( Current_Selection ) */
717:
718: WinEndPaint( hps );
719: } /* BMAPPAINT */
720:
721: /****************************************************************************/
722: /* BMAPQUERYQUIT: */
723: /* The user is required to confirm/dismiss the request to quit the program */
724: /****************************************************************************/
725: VOID BmapQueryQuit( hwnd )
726: HWND hwnd;
727: {
728: CHAR szTerminate[CCHMAXSTRING];
729:
730: WinLoadString(hab, NULL, IDSTERMINATE, CCHMAXSTRING , (PSZ)szTerminate);
731:
732: if ( WinMessageBox( HWND_DESKTOP
733: , hwnd
734: , (PSZ)szTerminate
735: , (PSZ)szWindowTitle
736: , 0
737: , MB_CUAWARNING | MB_YESNO | MB_DEFBUTTON2 | MB_MOVEABLE
738: ) == MBID_YES)
739: {
740: WinPostMsg( hwnd, WM_QUIT, (ULONG)0, (ULONG)0 );
741: }
742: } /* BMAPQUERYQUIT */
743:
744: /****************************************************************************/
745: /* MENUGREY: */
746: /* Enable/Disable menuitem according to option */
747: /****************************************************************************/
748: VOID MenuGrey( item, option )
749: USHORT item;
750: BOOL option;
751: {
752: WinSendMsg( WinWindowFromID( hwndFrame, FID_MENU )
753: , MM_SETITEMATTR
754: , MPFROM2SHORT( item, TRUE)
755: , MPFROM2SHORT( MIA_DISABLED, option ? MIA_DISABLED : ~MIA_DISABLED )
756: );
757: return;
758: } /* MENUGREY */
759:
760: /****************************************************************************/
761: /* MENUTICK: */
762: /* Tick/Untick menuitem according to option */
763: /****************************************************************************/
764: VOID MenuTick( item, option )
765: USHORT item;
766: BOOL option;
767: {
768: WinSendMsg( WinWindowFromID( hwndFrame, FID_MENU )
769: , MM_SETITEMATTR
770: , MPFROM2SHORT( item, TRUE)
771: , MPFROM2SHORT( MIA_CHECKED, option ? MIA_CHECKED : ~MIA_CHECKED )
772: );
773:
774: return;
775: } /* MENUTICK */
776:
777: /****************************************************************************/
778: /* SIMPLEPIC: */
779: /* A selection of GPI drawing commands exercised when 'Draw - Picture' */
780: /* option is selected. */
781: /****************************************************************************/
782: VOID SimplePic( hps )
783: HPS hps;
784: {
785: POINTL Pos;
786: POINTL Coords[4];
787:
788: /* draw a rhomboid */
789: Pos.x = 100;
790: Pos.y = 50;
791: GpiMove( hps
792: , &Pos
793: );
794:
795: Coords[0].x = 50;
796: Coords[0].y = 100;
797: Coords[1].x = 100;
798: Coords[1].y = 150;
799: Coords[2].x = 150;
800: Coords[2].y = 100;
801: /* three green sides */
802: GpiSetColor( hps, CLR_GREEN );
803: GpiPolyLine( hps
804: , 3L
805: , Coords
806: );
807: /* one blue edge */
808: GpiSetColor( hps, CLR_BLUE );
809: GpiLine( hps
810: , &Pos
811: );
812:
813: /* draw a rectangle */
814: Pos.x = 200;
815: Pos.y = 200;
816: GpiMove( hps
817: , &Pos
818: );
819:
820: Coords[0].x = 200;
821: Coords[0].y = 250;
822: Coords[1].x = 250;
823: Coords[1].y = 250;
824: Coords[2].x = 250;
825: Coords[2].y = 200;
826: Coords[3].x = 200;
827: Coords[3].y = 200;
828: /* four red sides */
829: GpiSetColor( hps, CLR_RED );
830: GpiPolyLine( hps
831: , 4L
832: , Coords
833: );
834: } /* SIMPLEPIC */
835:
836: VOID WindowDestroy()
837: {
838: GpiAssociate( hpsMem, (HDC)NULL );
839: GpiDestroyPS( hpsMem );
840: DevCloseDC( hdcMem );
841: }
842:
843: /****************************************************************************/
844: /* Initialisation to be carried out when the window is created. */
845: /****************************************************************************/
846: VOID WindowInitialization(hwnd)
847: HWND hwnd;
848: {
849: SIZEL size;
850:
851: /************************************************************************/
852: /* Get the maximum client area size. Create a window DC for the client */
853: /* area and a normal GPI Presentation Space and associate the two. */
854: /* The GPI PS will be the maximum client area size and be in pels. */
855: /* Create a memory DC compatible with the screen. */
856: /************************************************************************/
857: size.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXFULLSCREEN);
858: size.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYFULLSCREEN);
859:
860: /************************************************************************/
861: /* THE MEMORY DEVICE */
862: /* Get a dc for the memory device */
863: /************************************************************************/
864: hdcMem = DevOpenDC( hab
865: , OD_MEMORY
866: , (PSZ)"*"
867: , 8L
868: , (PDEVOPENDATA)dcdatablk
869: , (HDC)NULL
870: );
871: /************************************************************************/
872: /* NB DO THE DC/PS ASSOCIATE HERE */
873: /* create the memory ps to the dimensions of the full screen */
874: /************************************************************************/
875:
876: hpsMem = GpiCreatePS( hab
877: , hdcMem
878: , (PSIZEL)&size
879: , (LONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC
880: );
881: } /* WINDOWINITIALIZATION */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.