|
|
1.1 ! root 1: /****************************** Module Header ******************************\ ! 2: * Module Name: tempnres.c ! 3: * ! 4: * Non-resident portion of Presentation Manager Template Application ! 5: * ! 6: * It illustrates the building of a class record, the registering of ! 7: * that class record with Presentattion Manager and the creation of a window ! 8: * of that class. See TEMPLATE.DEF for the associated module definition ! 9: * file ! 10: * ! 11: * This is a MIDDLE model application, it has three code segments _RES, _INIT ! 12: * and _NRES and one data segment _DATA. ! 13: * ! 14: * For MIDDLE model, procedures that are accessed from another segment ! 15: * must be declared FAR (see template.h). ! 16: * ! 17: * Code that is NOT part of the template but is merely for demo purposes is ! 18: * marked as being for demo purposes and should be replaced/removed when this ! 19: * template is converted to a real application. ! 20: * ! 21: * Created by Microsoft Corp., 1988 ! 22: * ! 23: \***************************************************************************/ ! 24: ! 25: #define INCL_GPI ! 26: #define INCL_WIN ! 27: ! 28: #include <os2.h> ! 29: #include "template.h" ! 30: ! 31: /* min and max macros */ ! 32: #define max(a,b) (((a) > (b)) ? (a) : (b)) ! 33: #define min(a,b) (((a) < (b)) ? (a) : (b)) ! 34: ! 35: HAB hAB; ! 36: HMQ hMsgQ; ! 37: HWND hwndTemplate; ! 38: HWND hwndTemplateFrame; ! 39: ! 40: /************************************************************************\ ! 41: * The following following are variables and definitions that are part of ! 42: * the template only for demo purposes and will be replaced when the ! 43: * template is converted to an application ! 44: \************************************************************************/ ! 45: ! 46: #define RGBBLACK 0L ! 47: #define CCHSTR 15 ! 48: #define CSTR 7 ! 49: #define POSMIN 0 ! 50: #define POSMAX 100 ! 51: #define LINEINC 5 ! 52: #define PAGEINC 25 ! 53: ! 54: CHAR szContent[31]; ! 55: CHAR szStr[CCHSTR+1]; ! 56: CHAR szDefault[CCHSTR+1]; ! 57: CHAR szAppName[10]; ! 58: BOOL bCheckBox = TRUE; ! 59: BOOL fDoAsync = FALSE; ! 60: BOOL fDoFlash = FALSE; ! 61: SHORT fDisplay = IDMCOLOR; ! 62: SHORT cchContent; ! 63: SHORT idRadioButton = IDDRBRIGHT; ! 64: SHORT iSel = 2; ! 65: SHORT posV = 50; ! 66: SHORT posH = 50; ! 67: ! 68: /*********** End of demo purpose variables and definitions ************/ ! 69: ! 70: /***********************************************************************\ ! 71: * ! 72: * Procedures in alphabetical order ! 73: * ! 74: \***********************************************************************/ ! 75: ! 76: ! 77: /******* The code below is for demo purposes only *******/ ! 78: VOID ShowAsyncMessage(hWnd) ! 79: HWND hWnd; ! 80: { ! 81: CHAR szOkAsync[CCHMAXSTRING]; ! 82: CHAR szAsync[CCHMAXSTRING]; ! 83: ! 84: /* we have an outstanding message for user */ ! 85: ! 86: WinStopTimer( hAB, hWnd, IDTASYNC ); ! 87: WinFlashWindow( hWnd, FALSE ); ! 88: WinLoadString(hAB, NULL, IDSOKASYNC, CCHMAXSTRING, (PCH)szOkAsync); ! 89: WinLoadString(hAB, NULL, IDSASYNC, CCHMAXSTRING, (PCH)szAsync); ! 90: WinMessageBox(HWND_DESKTOP, hWnd, (PCH)szOkAsync, (PCH)szAsync, NULL, ! 91: MB_OK|MB_ICONEXCLAMATION ); ! 92: ! 93: if ( fDoAsync ) /* restart timer to get another message */ ! 94: WinStartTimer( hAB, hWnd, IDTASYNC, CMSECASYNC ); ! 95: ! 96: } ! 97: /******* The code above is for demo purposes only *******/ ! 98: ! 99: ! 100: MRESULT EXPENTRY TemplateAboutDlg( hWndDlg, message, mp1, mp2 ) ! 101: HWND hWndDlg; ! 102: USHORT message; ! 103: MPARAM mp1; ! 104: MPARAM mp2; ! 105: { ! 106: switch( message ) ! 107: { ! 108: case WM_COMMAND: /* the user has pressed a button */ ! 109: switch( SHORT1FROMMP( mp1 ) ) /* which button? */ ! 110: { ! 111: case DID_OK: ! 112: case DID_CANCEL: ! 113: WinDismissDlg( hWndDlg, TRUE ); ! 114: break; ! 115: ! 116: default: ! 117: return( FALSE ); ! 118: } ! 119: break; ! 120: ! 121: default: ! 122: return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) ); ! 123: } ! 124: return( FALSE ); ! 125: } ! 126: ! 127: ! 128: ! 129: VOID TemplateCharInput( hWnd, ch, flags, cRepeat ) ! 130: HWND hWnd; ! 131: SHORT ch; ! 132: SHORT flags; ! 133: SHORT cRepeat; ! 134: { ! 135: /* ignore cRepeat if you want to ignore auto-repeated keys */ ! 136: while (cRepeat-- != 0) ! 137: { ! 138: } ! 139: } ! 140: ! 141: ! 142: VOID TemplateCommand(hWnd, id, source, mouse) ! 143: HWND hWnd; ! 144: SHORT id; ! 145: SHORT source; ! 146: BOOL mouse; ! 147: { ! 148: /******* The code below is for demo purposes only *******/ ! 149: ! 150: RECTL rect; ! 151: HPS hPS; ! 152: ! 153: switch( id ) ! 154: { ! 155: case IDMFLASH: ! 156: WinQueryWindowRect( hWnd, (PRECTL)&rect ); ! 157: hPS = WinGetPS(hWnd ); ! 158: WinInvertRect( hPS, (PRECTL)&rect ); ! 159: WinInvertRect( hPS, (PRECTL)&rect ); ! 160: WinReleasePS( hPS ); ! 161: break; ! 162: ! 163: case IDMABOUT: ! 164: WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)TemplateAboutDlg, NULL, ! 165: IDD_ABOUT, NULL ); ! 166: break; ! 167: ! 168: case IDMCOLOR: ! 169: case IDMBLACK: ! 170: if ( fDisplay != id ) ! 171: { ! 172: fDisplay = id; ! 173: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, MM_SETITEMATTR, ! 174: MPFROM2SHORT(IDMCOLOR, TRUE), ! 175: MPFROM2SHORT(MIA_CHECKED, (id == IDMCOLOR ? MIA_CHECKED : NULL)) ); ! 176: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, MM_SETITEMATTR, ! 177: MPFROM2SHORT(IDMBLACK, TRUE), ! 178: MPFROM2SHORT(MIA_CHECKED, (id != IDMCOLOR ? MIA_CHECKED : NULL)) ); ! 179: /* this will cause repaint of entire window */ ! 180: WinInvalidateRect(hWnd, (PRECTL)NULL, TRUE ); ! 181: } ! 182: break; ! 183: ! 184: case IDMSTART: ! 185: /************************************************************\ ! 186: * start a timer, when it goes off: ! 187: * if window has focus then post message box ! 188: * else start flashing window/icon and wait until the ! 189: * window DOES have the focus before posting the message box, ! 190: * i.e, a template for an async message box ! 191: \************************************************************/ ! 192: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, ! 193: MM_SETITEMATTR, MPFROM2SHORT(IDMSTART, TRUE), ! 194: MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED) ); ! 195: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, ! 196: MM_SETITEMATTR, MPFROM2SHORT(IDMEND, TRUE), ! 197: MPFROM2SHORT(MIA_DISABLED, NULL) ); ! 198: fDoAsync = TRUE; ! 199: WinStartTimer( hAB, hWnd, IDTASYNC, CMSECASYNC ); ! 200: break; ! 201: ! 202: case IDMEND: ! 203: WinStopTimer( hAB, hWnd, IDTASYNC ); ! 204: fDoAsync = FALSE; ! 205: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, ! 206: MM_SETITEMATTR, MPFROM2SHORT(IDMSTART, TRUE), ! 207: MPFROM2SHORT(MIA_DISABLED, NULL) ); ! 208: WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, ! 209: MM_SETITEMATTR, MPFROM2SHORT(IDMEND, TRUE), ! 210: MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED) ); ! 211: break; ! 212: ! 213: case IDMDIALOG: ! 214: WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)TemplateDlg, NULL, ! 215: IDD_TEMPLATE, NULL ); ! 216: } ! 217: /******* The code above is for demo purposes only *******/ ! 218: } ! 219: ! 220: ! 221: VOID TemplateCreate(hWnd, lParam) ! 222: HWND hWnd; ! 223: LONG lParam; ! 224: { ! 225: char *pch1; ! 226: char *pch2; ! 227: ! 228: /******* The code below is for demo purposes only *******/ ! 229: ! 230: cchContent = WinLoadString(hAB, NULL, IDSCONTENT, sizeof(szContent), ! 231: (PCH)szContent); ! 232: ! 233: WinLoadString(hAB, NULL, IDSDEFAULT, sizeof(szDefault), (PCH)szDefault); ! 234: ! 235: /* copy default string into szStr */ ! 236: for (pch1 = szStr, pch2 = szDefault; *pch1++ = *pch2++; ) ! 237: ; ! 238: /******* The code above is for demo purposes only *******/ ! 239: } ! 240: ! 241: ! 242: /******* The code below is for demo purposes only *******/ ! 243: ! 244: MRESULT EXPENTRY TemplateDlg( hWndDlg, message, mp1, mp2 ) ! 245: HWND hWndDlg; ! 246: USHORT message; ! 247: MPARAM mp1; ! 248: MPARAM mp2; ! 249: { ! 250: CHAR szWaters[12]; ! 251: SHORT i; ! 252: SHORT pos; ! 253: ! 254: switch( message ) ! 255: { ! 256: case WM_INITDLG: ! 257: WinSetWindowText( WinWindowFromID( hWndDlg, IDDTEXT ), (PCH)szStr ); ! 258: WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_SETCHECK, ! 259: MPFROM2SHORT(bCheckBox, 0), 0L ); ! 260: WinSendDlgItemMsg( hWndDlg, idRadioButton, ! 261: BM_SETCHECK, MPFROM2SHORT(TRUE, 0), 0L ); ! 262: ! 263: for (i = 0; i < CSTR; i++) { ! 264: WinLoadString(hAB, NULL, IDSSTR1+i, 12 , (PCH)szWaters); ! 265: WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_INSERTITEM, ! 266: (MPARAM)-1L, (MPARAM)(PCH)szWaters ); ! 267: } ! 268: WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_SELECTITEM, (MPARAM)iSel, ! 269: (MPARAM)TRUE ); ! 270: ! 271: WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_SETSCROLLBAR, ! 272: MPFROM2SHORT(posH, 0), MPFROM2SHORT(POSMIN, POSMAX) ); ! 273: WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_SETSCROLLBAR, ! 274: MPFROM2SHORT(posV, 0), MPFROM2SHORT(POSMIN, POSMAX) ); ! 275: ! 276: return( FALSE ); ! 277: ! 278: case WM_COMMAND: ! 279: switch( SHORT1FROMMP(mp1) ) ! 280: { ! 281: case IDDDEFAULTS: ! 282: WinSetWindowText( WinWindowFromID( hWndDlg, IDDTEXT ), ! 283: (PCH)szDefault ); ! 284: WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_SETCHECK, ! 285: MPFROM2SHORT(TRUE, 0), 0L ); ! 286: ! 287: i = IDDRBLEFT + (SHORT)WinSendDlgItemMsg(hWndDlg, ! 288: IDDRBLEFT, ! 289: BM_QUERYCHECKINDEX, ! 290: 0L, 0L ); ! 291: WinSendDlgItemMsg( hWndDlg, i, BM_SETCHECK, MPFROMSHORT(FALSE), 0L); ! 292: WinSendDlgItemMsg( hWndDlg, (idRadioButton=IDDRBRIGHT), ! 293: BM_SETCHECK, MPFROMSHORT(TRUE), 0L ); ! 294: ! 295: WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_SELECTITEM, (MPARAM)2L, ! 296: (MPARAM)TRUE); ! 297: WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_SETSCROLLBAR, ! 298: MPFROM2SHORT(50, 0), MPFROM2SHORT(POSMIN, POSMAX) ); ! 299: WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_SETSCROLLBAR, ! 300: MPFROM2SHORT(50, 0), MPFROM2SHORT(POSMIN, POSMAX) ); ! 301: break; ! 302: ! 303: case DID_OK: ! 304: bCheckBox = (SHORT)WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_QUERYCHECK, ! 305: 0L, 0L ); ! 306: idRadioButton = IDDRBLEFT + (SHORT)WinSendDlgItemMsg(hWndDlg, ! 307: IDDRBLEFT, ! 308: BM_QUERYCHECKINDEX, ! 309: 0L, 0L ); ! 310: i = WinQueryWindowText(WinWindowFromID( hWndDlg, IDDTEXT ), CCHSTR, ! 311: (PCH)szStr); ! 312: iSel = (SHORT)WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_QUERYSELECTION, ! 313: 0L, 0L); ! 314: iSel = max(0, min(CSTR-1, iSel)); ! 315: posH = (USHORT)WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_QUERYPOS, 0L, 0L ); ! 316: posV = (USHORT)WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_QUERYPOS, 0L, 0L ); ! 317: WinDismissDlg( hWndDlg, TRUE ); ! 318: break; ! 319: ! 320: case DID_CANCEL: ! 321: WinDismissDlg( hWndDlg, TRUE ); ! 322: break; ! 323: ! 324: default: ! 325: return( FALSE ); ! 326: } ! 327: break; ! 328: ! 329: ! 330: /* scroll bar controls send messages here as WM_HSCROLL instead of WM_COMMAND */ ! 331: ! 332: case WM_HSCROLL: ! 333: case WM_VSCROLL: ! 334: switch ( SHORT1FROMMP(mp1) ) ! 335: { ! 336: case IDDSBH: ! 337: case IDDSBV: ! 338: pos = (USHORT)WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), ! 339: SBM_QUERYPOS, 0L, 0L ); ! 340: switch ( SHORT2FROMMP(mp2) ) ! 341: { ! 342: case SB_LINEUP: /* and SB_LINELEFT */ ! 343: pos -= LINEINC; ! 344: break; ! 345: case SB_LINEDOWN: /* and SB_LINERIGHT */ ! 346: pos += LINEINC; ! 347: break; ! 348: case SB_PAGEUP: /* and SB_PAGELEFT */ ! 349: pos -= PAGEINC; ! 350: break; ! 351: case SB_PAGEDOWN: /* and SB_PAGERIGHT */ ! 352: pos += PAGEINC; ! 353: break; ! 354: case SB_SLIDERPOSITION: ! 355: pos = SHORT1FROMMP(mp2); ! 356: break; ! 357: } ! 358: pos = max(POSMIN, min(POSMAX, pos)); ! 359: WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), ! 360: SBM_SETPOS, MPFROM2SHORT(pos, 0), 0L ); ! 361: break; ! 362: ! 363: default: ! 364: return( FALSE ); ! 365: } ! 366: ! 367: default: ! 368: return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) ); ! 369: ! 370: } ! 371: ! 372: return( FALSE ); ! 373: } ! 374: ! 375: /******* The code above is for demo purposes only *******/ ! 376: ! 377: ! 378: ! 379: VOID TemplateSetFocus( hWnd ) ! 380: HWND hWnd; ! 381: { ! 382: ! 383: if ( fDoFlash ) ! 384: { ! 385: fDoFlash = FALSE; ! 386: ShowAsyncMessage(hWnd); ! 387: } ! 388: ! 389: } ! 390: ! 391: ! 392: ! 393: VOID TemplateHorzScroll( hWnd, code, posNew ) ! 394: HWND hWnd; ! 395: SHORT code; ! 396: SHORT posNew; ! 397: { ! 398: switch( code ) ! 399: { ! 400: case SB_LINEUP: /* line left */ ! 401: break; ! 402: case SB_LINEDOWN: /* line right */ ! 403: break; ! 404: case SB_PAGEUP: /* page left */ ! 405: break; ! 406: case SB_PAGEDOWN: /* page right */ ! 407: break; ! 408: case SB_SLIDERPOSITION: /* position to posNew */ ! 409: break; ! 410: case SB_SLIDERTRACK: ! 411: break; ! 412: } ! 413: } ! 414: ! 415: VOID TemplatePaint( hWnd, hPS ) ! 416: HWND hWnd; ! 417: HPS hPS; ! 418: { ! 419: /* Here the application paints its window. */ ! 420: ! 421: /******* The code below is for demo purposes only *******/ ! 422: ! 423: long cx; ! 424: long cy; ! 425: RECTL rect; ! 426: POINTL pt; ! 427: CHARBUNDLE cb; ! 428: ! 429: WinQueryWindowRect( hWnd, (PRECTL)&rect ); ! 430: cx = (SHORT)(rect.xRight - rect.xLeft) >> 2; ! 431: cy = (SHORT)(rect.yTop - rect.yBottom) >> 2; ! 432: pt.x = 0L; ! 433: pt.y = rect.yTop - 12L; ! 434: ! 435: cb.lColor = CLR_BLACK; ! 436: GpiSetAttrs(hPS, PRIM_CHAR, CBB_COLOR, 0L, (PBUNDLE)&cb); ! 437: ! 438: GpiCharStringAt( hPS, (PPOINTL)&pt, (long)cchContent, (PCH)szContent ); ! 439: ! 440: /***********************************************************\ ! 441: * The vertical and horizontal lines on this rectangle are ! 442: * "one" pixel wide and on displays that do NOT have a 1:1 ! 443: * aspect ratio, the lines will NOT be the same thickness ! 444: \***********************************************************/ ! 445: ! 446: pt.x = rect.xLeft + cx; ! 447: pt.y = rect.yTop - cy; ! 448: GpiSetCurrentPosition( hPS, (PPOINTL)&pt ); ! 449: pt.x = rect.xRight - cx; ! 450: pt.y = rect.yBottom + cy; ! 451: GpiBox( hPS, 2L, (PPOINTL)&pt, 0L, 0L); ! 452: ! 453: /***********************************************************\ ! 454: * Now we drawn a "rectangle" with uniformly thick lines ! 455: \***********************************************************/ ! 456: cx = cx >> 1; ! 457: cy = cy >> 1; ! 458: ! 459: GpiSetLineWidthGeom( hPS, 2L ); ! 460: pt.x = rect.xLeft + cx; ! 461: pt.y = rect.yTop - cy; ! 462: GpiSetCurrentPosition( hPS, (PPOINTL)&pt ); ! 463: pt.x = rect.xRight - cx; ! 464: GpiLine( hPS, (PPOINTL)&pt ); ! 465: pt.y = rect.yBottom + cy; ! 466: GpiLine( hPS, (PPOINTL)&pt ); ! 467: pt.x = rect.xLeft + cx; ! 468: GpiLine( hPS, (PPOINTL)&pt ); ! 469: pt.y = rect.yTop - cy; ! 470: GpiLine( hPS, (PPOINTL)&pt ); ! 471: ! 472: /******* The code above is for demo purposes only *******/ ! 473: } ! 474: ! 475: ! 476: ! 477: /******* The code below is for demo purposes only *******/ ! 478: ! 479: VOID TemplateQueryQuit( hWnd ) ! 480: HWND hWnd; ! 481: { ! 482: CHAR szOkClose[CCHMAXSTRING]; ! 483: CHAR szClose[CCHMAXSTRING]; ! 484: ! 485: WinLoadString(hAB, NULL, IDSOKCLOSE, CCHMAXSTRING , (PCH)szOkClose); ! 486: WinLoadString(hAB, NULL, IDSCLOSE, CCHMAXSTRING , (PCH)szClose ); ! 487: WinAlarm( HWND_DESKTOP, WA_WARNING ); ! 488: if ( WinMessageBox(HWND_DESKTOP, hWnd, (PCH)szOkClose, (PCH)szClose, ! 489: NULL, MB_OKCANCEL|MB_ICONQUESTION ) == DID_OK ) ! 490: WinPostMsg( hWnd, WM_QUIT, 0L, 0L ); ! 491: } ! 492: ! 493: /******* The code above is for demo purposes only *******/ ! 494: ! 495: ! 496: /******* The code below is for demo purposes only *******/ ! 497: ! 498: VOID TemplateTimer( hWnd, id ) ! 499: HWND hWnd; ! 500: USHORT id; ! 501: { ! 502: WinStopTimer( hAB, hWnd, IDTASYNC ); ! 503: if ( WinQueryFocus(HWND_DESKTOP, FALSE ) == hWnd ) ! 504: ShowAsyncMessage( hWnd ); ! 505: else ! 506: { ! 507: fDoFlash = TRUE; ! 508: WinFlashWindow( hWnd, TRUE ); ! 509: } ! 510: } ! 511: ! 512: /******* The code above is for demo purposes only *******/ ! 513: ! 514: ! 515: ! 516: VOID TemplateVertScroll( hWnd, code, posNew ) ! 517: HWND hWnd; ! 518: SHORT code; ! 519: USHORT posNew; ! 520: { ! 521: switch( code ) ! 522: { ! 523: case SB_LINEUP: ! 524: break; ! 525: case SB_LINEDOWN: ! 526: break; ! 527: case SB_PAGEUP: ! 528: break; ! 529: case SB_PAGEDOWN: ! 530: break; ! 531: case SB_SLIDERPOSITION: ! 532: break; ! 533: case SB_SLIDERTRACK: ! 534: break; ! 535: } ! 536: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.