home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / WINSETUP.PRG < prev    next >
Text File  |  1993-10-29  |  5KB  |  147 lines

  1. ////////////////////////////
  2. //
  3. //    WinSetup.prg
  4. //
  5. //    Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
  6. //    All Rights Reserved.
  7. //
  8. //    Set up for Windows.
  9. //
  10. ////////////////////////////
  11.  
  12.  
  13. #include "windows.ch"
  14.  
  15.  
  16. //////////////////////////
  17. //
  18. //    WinSetup(cAppNAme, cTitle) --> hWnd
  19. //
  20. //    Registers the window class and creates a window.
  21. //    Returns the handle to the window.
  22. //
  23. //////////////////////////
  24.  
  25. /*
  26.  
  27.     WinSetup(<cAppName>, <cTitle>, [ <nX> ], [ <nY> ],                 ;
  28.              [ <nWidth> ], [ <nHeight> ], [ <cIcon> ], [ <cCursor> ],  ;
  29.              [ <nBrush> ], [ <nStyle> ] )  --> hWnd
  30.  
  31.     Registers the window class and creates a window of that class.
  32.  
  33.     Optional parameters <nX>, <nY>, <nWidth>, and <nHeight> allow you to
  34.     override the defaults and thus place the main window wherever you
  35.     desire.  <nX> and <nY> are the starting X and Y coordinates.  For
  36.     example, to have the startup window occupy the full screen, you
  37.     could use: WinSetup(appname, app_description, 0, 0, 640, 480)
  38.  
  39.     Optional parameter <cIcon> is the name of an icon made available to
  40.     the .EXE via a resource compiler.  This icon will be used when the
  41.     application is minimized (i.e., when using Alt-Tab to switch between
  42.     Windows applications).
  43.  
  44.     Optional parameter <cCursor> is either a pre-defined or user-defined
  45.     cursor to be used as the default mouse cursor for this window class.
  46.     If you pass the name of a user-defined cursor, that must have been
  47.     made available to the .EXE via a resource compiler.
  48.  
  49.     Optional parameter <nBrush> is one of the stock brushes found in
  50.     WINDOWS.CH (e.g., WHITE_BRUSH, etcetera).  This will be used as the
  51.     background drawing brush for this window class.
  52.  
  53.     <nStyle> is an optional numeric parameter specifying the window style
  54.     to use.  This should be a combination of the WS_* values defined
  55.     in WINDOWS.CH (such as WS_OVERLAPPEDWINDOW + WS_CLIPCHILDREN).
  56.     The default is WS_OVERLAPPEDWINDOW.
  57.  
  58.     Returns:  A handle to the newly created window
  59.  
  60. */
  61.  
  62.  
  63. function WinSetup(cAppName, cTitle, nX, nY, nWidth, nHeight, ;
  64.                   cIcon, cCursor, nBrush, nStyle)
  65. local hWnd
  66. local hInst     := _GetInstance()
  67. local hPrevInst := _GetPrevInstance()
  68. local nCmdShow  := _GetnCmdShow()
  69. local hCursor    // NOTE: 0 would mean no cursor,
  70.         //     nil means default: LoadCursor( , IDC_ARROW)
  71. local hBrush    // nil means default: GetStockObject(WHITE_BRUSH)
  72. local hIcon    // nil means default: LoadIcon( , IDI_APPLICATION)
  73.  
  74. if hPrevInst == 0
  75.    //───── set up icon if one was specified
  76.    if cIcon <> NIL
  77.       hIcon := LoadIcon(hInst,cIcon)
  78.    endif
  79.  
  80.    //───── set up cursor if one was specified
  81.    if cCursor <> NIL
  82.       hCursor := LoadCursor(hInst, cCursor)
  83.    endif
  84.  
  85.    //───── set up background brush if one was specified
  86.    if nBrush <> NIL
  87.       hBrush := GetStockObject(nBrush)
  88.    endif
  89.  
  90.    if ! RegisterClass(CS_HREDRAW + CS_VREDRAW + CS_SAVEBITS         ;
  91.                       ;  // remove next line to suppress mouse doubleclicks
  92.                       + CS_DBLCLKS, ;
  93.                       hInst,        ;    // application instance
  94.                       hIcon,        ;    // default icon
  95.                       hCursor,      ;    // default cursor
  96.                       hBrush,       ;    // default background brush
  97.                       cAppName)          // app name
  98.  
  99.       // probably out of resources
  100.       quit
  101.    endif
  102. endif
  103.  
  104. //───── assign default values for X, Y coordinates, and height/width
  105. if nX == NIL
  106.    nX := CW_USEDEFAULT
  107. endif
  108. if nY == NIL
  109.    nY := CW_USEDEFAULT
  110. endif
  111. if nWidth == NIL
  112.    nWidth := CW_USEDEFAULT
  113. endif
  114. if nHeight == NIL
  115.    nHeight := CW_USEDEFAULT
  116. endif
  117.  
  118. if nStyle == nil
  119.    nStyle = WS_OVERLAPPEDWINDOW
  120. endif
  121.  
  122. hWnd := CreateWindow(cAppName,          ;       // window class
  123.             cTitle,         ;    // caption for title bar
  124.             nStyle,        ;    // window style
  125.                     nX,                 ;       // x co-ordinate
  126.                     nY,                 ;       // y co-ordinate
  127.                     nWidth,             ;       // width
  128.                     nHeight,            ;       // height
  129.             0,            ;    // hWnd of parent (none)
  130.             0,            ;    // hMenu of menu (none yet)
  131.             hInst)            // our own app instance
  132.  
  133. if hWnd == 0
  134.    MessageBox(, "Window Creation Failed!", "Error", MB_ICONEXCLAMATION + MB_OK)
  135.    hWnd := NIL
  136. endif
  137.  
  138. // make sure it's displayed ...
  139. ShowWindow(hWnd, nCmdShow)
  140.  
  141. // ... and up to date
  142. UpdateWindow(hWnd)
  143.  
  144. return hWnd
  145.  
  146. //───── end of file WINSETUP.PRG
  147.