home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol04 / 01b / macsl / mpmfig3.txt < prev    next >
Text File  |  1988-10-27  |  7KB  |  220 lines

  1. HWND APIENTRY
  2. WinCreateWindow( hwndParent, pszClass,  pszName, flStyle,
  3.                  x, y, cx, cy, hwndOwner, hwndPrevSibling, id,
  4.                  pCtlData, pPresParams )
  5.     HWND        hwndParent, hwndOwner, hwndPrevSibling;
  6.     PSZ         pszClass, pszName;
  7.     ULONG       flStyle;
  8.     SHORT       x, y, cx, cy;
  9.     USHORT      id;
  10.     PVOID       pCtlData, pPresParams;
  11. {
  12.     HWND        hwnd, hwndNextSibling, hwndMac;
  13.     PMYWND      pwnd;
  14.     HMYCLASS    hClass;
  15.     PMYCLASS    pClass;
  16.     USHORT      usLen;
  17.     SHORT       sProcID;
  18.     Rect        rect, rectAdj;
  19.     WindowPeek  pwin, pwinBehind;
  20.     CHAR        szTitle[256];
  21.     BOOL        fGoAway, fFrameWindow;
  22.     UCHAR       ucKind;
  23.     USHORT      usHash;
  24.     CHAR        szClassBuf[10];
  25.     ULONG       flFrameFlags;
  26.  
  27.     /* Figure out which WK_ code to use */
  28.  
  29.     if( pszClass == WC_DESKTOP )
  30.       ucKind = WK_DESKTOP;
  31.     else
  32.     {
  33.       if( ! hwndParent  ||  hwndParent == HWND_DESKTOP )
  34.         hwndParent = _hwndDesktop;
  35.       if( hwndParent == _hwndDesktop )
  36.         ucKind = WK_MAIN;
  37.       else
  38.         ucKind = WK_CHILD;
  39.     }
  40.  
  41.     /* Fix up WC_ names, calculate hash, and find window class */
  42.  
  43.     MpmFixName( &pszClass, szClassBuf, &usHash );
  44.  
  45.     hClass = MpmFindClass( pszClass, usHash );
  46.     if( ! hClass )
  47.       return NULL;
  48.  
  49.     /* Grab frame flags if it's the window frame class */
  50.  
  51.     fFrameWindow = MpmIsFrameClass( pszClass );
  52.     flFrameFlags =
  53.       ( fFrameWindow && pCtlData ? *(PULONG)pCtlData : 0 );
  54.  
  55.     /* Allocate window structure */
  56.  
  57.     usLen = sizeof(MYWND) + (**hClass).class.cbWindowData;
  58.     hwnd = (HWND)MpmNewHandleZ( usLen );
  59.     if( ! hwnd )
  60.       return NULL;
  61.  
  62.     /* Handle WK_ specific stuff */
  63.  
  64.     switch( ucKind )
  65.     {
  66.       /* Desktop window: just set window position */
  67.  
  68.       case WK_DESKTOP:
  69.         SetRect( &rect, 0, 0, cx, cy );
  70.         SetRect( &rectAdj, 0, 0, 0, 0 );
  71.         break;
  72.  
  73.       /* Main Mac window: figure out which style of Mac window
  74.          to use and create it */
  75.  
  76.       case WK_MAIN:
  77.         fGoAway = FALSE;
  78.         if( ! ( flStyle & FS_BORDER )  &&
  79.             ! ( flFrameFlags & FCF_DOCBITS ) )
  80.         {
  81.           sProcID = plainDBox;  /* shouldn't have border! */
  82.           rectAdj = _rectAdjPlainDBox;
  83.         }
  84.         else if( flFrameFlags & FCF_DOCBITS )
  85.         {
  86.           sProcID = documentProc;
  87.           rectAdj = _rectAdjDocumentProc;
  88.           if( flFrameFlags & FCF_MAXBUTTON )
  89.             sProcID += 8;
  90.           if( flFrameFlags & FCF_SYSMENU )
  91.             fGoAway = TRUE;
  92.         }
  93.         else if( flStyle & FS_DLGBORDER )
  94.         {
  95.           sProcID = dBoxProc;
  96.           rectAdj = _rectAdjDBoxProc;
  97.         }
  98.         else
  99.         {
  100.           sProcID = altDBoxProc;
  101.           rectAdj = _rectAdjAltDBoxProc;
  102.         }
  103.  
  104.         rect.left   = rectAdj.left   + x;
  105.         rect.right  = rectAdj.right  + x + cx;
  106.         rect.top    = rectAdj.top    + rect.bottom - cy;
  107.         rect.bottom = rectAdj.bottom + screenBits.bounds.bottom - y;
  108.     
  109.         /* Should check rect for out of screen boundaries! */
  110.     
  111.         strncpy( szTitle, pszName, 255 );
  112.         szTitle[255] = '\0';
  113.     
  114.         if( hwndPrevSibling == HWND_TOP )
  115.           pwinBehind = (WindowPeek)(-1);
  116.         else if( hwndPrevSibling == HWND_BOTTOM )
  117.           pwinBehind = (WindowPeek)NULL;
  118.         else if( ISMAINWINDOW(hwndPrevSibling) )
  119.           pwinBehind = PWINOFHWND(hwndPrevSibling);
  120.         else
  121.           ERROR( "WinCreateWindow: Invalid hwndPrevSibling" );
  122.     
  123.         pwin = 
  124.           (WindowPeek)NewWindow( NULL, &rect, CtoPstr(szTitle),
  125.                                  FALSE, sProcID, pwinBehind,
  126.                                  fGoAway, (LONG)hwnd );
  127.         if( ! pwin )
  128.         {
  129.           DisposHandle( (Handle)hwnd );
  130.           return NULL;
  131.         }
  132.         PWINOFHWND(hwnd) = pwin;
  133.  
  134.         break;
  135.  
  136.       /* Child window: set up all the "kin" windows */
  137.  
  138.       case WK_CHILD:
  139.         if( hwndPrevSibling == HWND_TOP )
  140.         {
  141.           MYWNDOF(hwnd).hwndNextSibling = hwndNextSibling =
  142.             MYWNDOF(hwndParent).hwndTopChild;
  143.           MYWNDOF(hwndNextSibling).hwndPrevSibling = hwnd;
  144.           MYWNDOF(hwndParent).hwndTopChild = hwnd;
  145.         }
  146.         else if( hwndPrevSibling == HWND_BOTTOM )
  147.         {
  148.           MYWNDOF(hwnd).hwndPrevSibling = hwndPrevSibling =
  149.             MYWNDOF(hwndParent).hwndBottomChild;
  150.           MYWNDOF(hwndPrevSibling).hwndNextSibling = hwnd;
  151.           MYWNDOF(hwndParent).hwndBottomChild = hwnd;
  152.         }
  153.         else
  154.         {
  155.           if( ! MpmValidateWindow(hwndPrevSibling) )
  156.             return NULL;
  157.           if( MYWNDOF(hwndPrevSibling).hwndParent != hwndParent )
  158.             return NULL;
  159.           MYWNDOF(hwnd).hwndNextSibling = hwndNextSibling =
  160.             MYWNDOF(hwndPrevSibling).hwndNextSibling;
  161.           MYWNDOF(hwnd).hwndPrevSibling = hwndPrevSibling;
  162.           MYWNDOF(hwndPrevSibling).hwndNextSibling = hwnd;
  163.           if( hwndNextSibling )
  164.             MYWNDOF(hwndNextSibling).hwndPrevSibling = hwnd;
  165.           else
  166.             MYWNDOF(hwndParent).hwndBottomChild = hwnd;
  167.         }
  168.         if( ! MYWNDOF(hwndParent).hwndTopChild )
  169.           MYWNDOF(hwndParent).hwndTopChild = hwnd;
  170.         if( ! MYWNDOF(hwndParent).hwndBottomChild )
  171.           MYWNDOF(hwndParent).hwndBottomChild = hwnd;
  172.         for( hwndMac = hwndParent;
  173.              ISCHILDWINDOW(hwndMac);
  174.              hwndMac = MYWNDOF(hwndMac).hwndParent );
  175.         PWINOFHWND(hwnd) = PWINOFHWND(hwndMac);
  176.         rectAdj = MYWNDOF(hwndMac).rectAdj;
  177.         break;
  178.     }
  179.  
  180.     /* Fill in the window structure fields */
  181.  
  182.     pClass = *hClass;
  183.     pwnd = PMYWNDOF(hwnd);
  184.  
  185.     pwnd->signature = WND_SIGNATURE;
  186.     pwnd->ucKind = ucKind;
  187.     pwnd->pfnwp = pClass->class.pfnWindowProc;
  188.     pwnd->hclass = hClass;
  189.     pwnd->flStyle =
  190.       ( flStyle & ~WS_VISIBLE ) |
  191.       ( pClass->class.flClassStyle & CLASSWINDOWBITS );
  192.     pwnd->hwndOwner = hwndOwner;
  193.     pwnd->hwndParent = hwndParent;
  194.     pwnd->id = id;
  195.     pwnd->rectAdj = rectAdj;
  196.     pwnd->flFrameFlags = flFrameFlags;
  197.  
  198.     /* Now the window is here for real, so send the WM_CREATE */
  199.  
  200.     if( WinSendMsg( hwnd, WM_CREATE,
  201.                     MPFROMP(pCtlData), MPFROMP(&hwndParent) ) )
  202.     {
  203.       WinDestroyWindow( hwnd );
  204.       return NULL;
  205.     }
  206.  
  207.     /* Send the WM_ADJUSTWINDOWPOS if it's not the desktop window
  208.        and it has a nonzero size */
  209.  
  210.     if( cx  &&  cy  &&  ucKind != WK_DESKTOP )
  211.       WinSetWindowPos( hwnd, NULL, x, y, cx, cy, SWP_MOVE | SWP_SIZE );
  212.  
  213.     /* Make the window visible if it's supposed to be visible */
  214.  
  215.     if( flStyle & WS_VISIBLE )
  216.       WinShowWindow( hwnd, TRUE );
  217.  
  218.     return hwnd;
  219. }
  220.