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

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