Annotation of mstools/samples/gdidemo/draw.c, revision 1.1

1.1     ! root        1: /*---------------------------------------------------------------------------*\
        !             2: | RANDOM OBJECTS MODULE
        !             3: |
        !             4: | segment: _TEXT (DOS16)
        !             5: | created: 19-Oct-90
        !             6: | history: 19-Oct-90 <chriswil> created.
        !             7: |
        !             8: \*---------------------------------------------------------------------------*/
        !             9: 
        !            10: #include <windows.h>
        !            11: #include "gdidemo.h"
        !            12: #include "draw.h"
        !            13: 
        !            14: /*---------------------------------------------------------------------------*\
        !            15: | CREATE DRAW WINDOW PROCEDURE
        !            16: |
        !            17: | created: 20-May-91
        !            18: | history: 20-May-91 <chriswil> created.
        !            19: |
        !            20: \*---------------------------------------------------------------------------*/
        !            21: HWND FAR CreateDrawWindow(HWND hWndClient, int nItem)
        !            22: {
        !            23:     HANDLE          hInstance;
        !            24:     MDICREATESTRUCT mcs;
        !            25: 
        !            26: 
        !            27:     hInstance = GETINSTANCE(hWndClient);
        !            28: 
        !            29:     /*
        !            30:     ** Initialize the MDI create struct for creation of the
        !            31:     ** test window.
        !            32:     */
        !            33:     mcs.szClass = DRAWCLASS;
        !            34:     mcs.szTitle = DRAWTITLE;
        !            35:     mcs.hOwner = hInstance;
        !            36:     mcs.x       = CW_USEDEFAULT;
        !            37:     mcs.y       = CW_USEDEFAULT;
        !            38:     mcs.cx      = CW_USEDEFAULT;
        !            39:     mcs.cy      = CW_USEDEFAULT;
        !            40:     mcs.style  = 0l;
        !            41:     mcs.lParam  = (LONG)nItem;
        !            42: 
        !            43:     return((HWND)SendMessage(hWndClient,WM_MDICREATE,NULL,(LONG)(LPMDICREATESTRUCT)&mcs));
        !            44: }
        !            45: 
        !            46: 
        !            47: /*---------------------------------------------------------------------------*\
        !            48: | DRAW WINDOW PROCEDURE
        !            49: |
        !            50: | created: 20-May-91
        !            51: | history: 20-May-91 <chriswil> created.
        !            52: |
        !            53: \*---------------------------------------------------------------------------*/
        !            54: LONG APIENTRY DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam)
        !            55: {
        !            56:     switch(wMsg)
        !            57:     {
        !            58:         case WM_CREATE:
        !            59:             DrawCreateProc(hWnd);
        !            60:             break;
        !            61: 
        !            62: 
        !            63:         case WM_COMMAND:
        !            64:             DrawCommandProc(hWnd,wParam,lParam);
        !            65:             break;
        !            66: 
        !            67: 
        !            68:         case WM_TIMER:
        !            69:             DrawObject(hWnd);
        !            70:             break;
        !            71: 
        !            72: 
        !            73:         case WM_PAINT:
        !            74:             DrawPaintProc(hWnd);
        !            75:             break;
        !            76: 
        !            77: 
        !            78:         case WM_DESTROY:
        !            79:             DrawDestroyProc(hWnd);
        !            80:             break;
        !            81: 
        !            82: 
        !            83:         default:
        !            84:             return(DefMDIChildProc(hWnd,wMsg,wParam,lParam));
        !            85:     }
        !            86:     return(0l);
        !            87: }
        !            88: 
        !            89: 
        !            90: /*---------------------------------------------------------------------------*\
        !            91: | DRAW CREATE PROCEDURE
        !            92: |
        !            93: | created: 20-May-91
        !            94: | history: 20-May-91 <chriswil> created.
        !            95: |
        !            96: \*---------------------------------------------------------------------------*/
        !            97: BOOL DrawCreateProc(HWND hWnd)
        !            98: {
        !            99:     PDRAWDATA pdd;
        !           100: 
        !           101: 
        !           102:     if(AllocWindowInfo(hWnd,sizeof(DRAWDATA)))
        !           103:     {
        !           104:         if(pdd = (PDRAWDATA)LockWindowInfo(hWnd))
        !           105:         {
        !           106:             pdd->nObject = 0;
        !           107: 
        !           108:             UnlockWindowInfo(hWnd);
        !           109: 
        !           110:             SetTimer(hWnd,1,50,NULL);
        !           111:             return(TRUE);
        !           112:         }
        !           113:         FreeWindowInfo(hWnd);
        !           114:     }
        !           115:     return(FALSE);
        !           116: }
        !           117: 
        !           118: 
        !           119: /*---------------------------------------------------------------------------*\
        !           120: | DRAW COMMAND PROCEDURE
        !           121: |
        !           122: | created: 20-May-91
        !           123: | history: 20-May-91 <chriswil> created.
        !           124: |
        !           125: \*---------------------------------------------------------------------------*/
        !           126: BOOL DrawCommandProc(HWND hWnd, WPARAM wParam, LONG lParam)
        !           127: {
        !           128:     hWnd   = hWnd;
        !           129:     wParam = wParam;
        !           130:     lParam = lParam;
        !           131: 
        !           132:     return(TRUE);
        !           133: }
        !           134: 
        !           135: 
        !           136: /*---------------------------------------------------------------------------*\
        !           137: | DRAW PAINT PROCEDURE
        !           138: |
        !           139: | created: 20-May-91
        !           140: | history: 20-May-91 <chriswil> created.
        !           141: |
        !           142: \*---------------------------------------------------------------------------*/
        !           143: VOID DrawPaintProc(HWND hWnd)
        !           144: {
        !           145:     HDC         hDC;
        !           146:     PAINTSTRUCT ps;
        !           147: 
        !           148: 
        !           149:     if(hDC = BeginPaint(hWnd,&ps))
        !           150:         EndPaint(hWnd,&ps);
        !           151: 
        !           152:     return;
        !           153: }
        !           154: 
        !           155: 
        !           156: /*---------------------------------------------------------------------------*\
        !           157: | DRAW DESTROY PROCEDURE
        !           158: |
        !           159: | created: 20-May-91
        !           160: | history: 20-May-91 <chriswil> created.
        !           161: |
        !           162: \*---------------------------------------------------------------------------*/
        !           163: VOID DrawDestroyProc(HWND hWnd)
        !           164: {
        !           165:     KillTimer(hWnd,1);
        !           166:     FreeWindowInfo(hWnd);
        !           167:     return;
        !           168: }
        !           169: 
        !           170: 
        !           171: VOID DrawObject(HWND hWnd)
        !           172: {
        !           173:     PDRAWDATA pdd;
        !           174:     RECT      rect;
        !           175:     HDC       hDC;
        !           176:     int       x1,y1,x2,y2,x3,y3,x4,y4,r,g,b,nObject;
        !           177:     HBRUSH    hBrush;
        !           178:     char      szDebug[80];
        !           179: 
        !           180: 
        !           181:     if(pdd = (PDRAWDATA)LockWindowInfo(hWnd))
        !           182:     {
        !           183:         if(hDC = GetDC(hWnd))
        !           184:         {
        !           185:             GetClientRect(hWnd,&rect);
        !           186: 
        !           187:             r = lRandom() % 255;
        !           188:             g = lRandom() % 255;
        !           189:             b = lRandom() % 255;
        !           190: 
        !           191:             if(hBrush = SelectObject(hDC,CreateSolidBrush(RGB(r,g,b))))
        !           192:             {
        !           193:                 x1 = lRandom() % rect.right;
        !           194:                 y1 = lRandom() % rect.bottom;
        !           195:                 x2 = lRandom() % rect.right;
        !           196:                 y2 = lRandom() % rect.bottom;
        !           197:                 x3 = lRandom() % rect.right;
        !           198:                 y3 = lRandom() % rect.bottom;
        !           199:                 x4 = lRandom() % rect.right;
        !           200:                 y4 = lRandom() % rect.bottom;
        !           201: 
        !           202: 
        !           203:                 nObject = lRandom() % 5;
        !           204: 
        !           205:                 switch(nObject)
        !           206:                 {
        !           207:                     default:
        !           208:                     case OBJ_RECTANGLE:
        !           209:                         wsprintf(szDebug,"Rectangle(%d,%d,%d,%d)\n",x1,y1,x2,y2);
        !           210:                         DEBUGOUT(szDebug);
        !           211:                         Rectangle(hDC,x1,y1,x2,y2);
        !           212:                         break;
        !           213: 
        !           214:                     case OBJ_ELLIPSE:
        !           215:                         wsprintf(szDebug,"Ellipse(%d,%d,%d,%d)\n",x1,y1,x2,y2);
        !           216:                         DEBUGOUT(szDebug);
        !           217:                         Ellipse(hDC,x1,y1,x2,y2);
        !           218:                         break;
        !           219: 
        !           220: 
        !           221: 
        !           222:                     case OBJ_ROUNDRECT:
        !           223:                         wsprintf(szDebug,"RoundRect(%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3);
        !           224:                         DEBUGOUT(szDebug);
        !           225:                         RoundRect(hDC,x1,y1,x2,y2,x3,y3);
        !           226:                         break;
        !           227: 
        !           228:                     case OBJ_CHORD:
        !           229:                         wsprintf(szDebug,"Chord(%d,%d,%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3,x4,y4);
        !           230:                         DEBUGOUT(szDebug);
        !           231:                         Chord(hDC,x1,y1,x2,y2,x3,y3,x4,y4);
        !           232:                         break;
        !           233: 
        !           234:                     case OBJ_PIE:
        !           235:                         wsprintf(szDebug,"Pie(%d,%d,%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3,x4,y4);
        !           236:                         DEBUGOUT(szDebug);
        !           237:                         Pie(hDC,x1,y1,x2,y2,x3,y3,x4,y4);
        !           238:                        break;
        !           239: 
        !           240:                 }
        !           241: 
        !           242:                 DeleteObject(SelectObject(hDC,hBrush));
        !           243:             }
        !           244:             ReleaseDC(hWnd,hDC);
        !           245:         }
        !           246:         UnlockWindowInfo(hWnd);
        !           247:     }
        !           248:     return;
        !           249: }

unix.superglobalmegacorp.com

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