home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
WNDSETUP.PRG
< prev
next >
Wrap
Text File
|
1993-10-29
|
5KB
|
156 lines
////////////////////////////
//
// WndSetup.prg
//
// Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// Set up for Windows, using a window proc.
//
////////////////////////////
#include "windows.ch"
//////////////////////////
//
// WndSetup(cAppNAme, cTitle, bAction, aWM, ...) --> hWnd
//
// Registers the window class and creates a window.
// Returns the handle to the window.
//
//////////////////////////
/*
WndSetup(<cAppName>, <cTitle>, <bAction>, <aWM> ;
[ <nX> ], [ <nY> ], [ <nWidth> ], [ <nHeight> ], ;
[ <cnIcon> ], [ <cnCursor> ], ;
[ <nBrush> ], [ <nStyle> ] ) --> hWnd
Registers the window class and creates a window of that class.
<bAction> is the code block to handle the messages listed in aWM
(it is also sent any >= WM_USER).
Optional parameters <nX>, <nY>, <nWidth>, and <nHeight> allow you to
override the defaults and thus place the main window wherever you
desire. <nX> and <nY> are the starting X and Y coordinates. For
example, to have the startup window occupy the full screen, you
could use: WndSetup(appname, app_description, bAction, aWM, 0, 0, 640, 480)
Optional parameter <cnIcon> is the name or id of an icon made available to
the .EXE via a resource compiler. This icon will be used when the
application is minimized.
Optional parameter <cnCursor> is either a pre-defined or user-defined
cursor to be used as the default mouse cursor for this window class.
If you pass the name or id of a user-defined cursor, it must have been
made available to the .EXE via a resource compiler.
Optional parameter <nBrush> is one of the stock brushes found in
WINDOWS.CH (e.g., WHITE_BRUSH, etcetera). This will be used as the
background drawing brush for this window class.
<nStyle> is an optional numeric parameter specifying the window style
to use. This should be a combination of the WS_* values defined
in WINDOWS.CH (such as WS_OVERLAPPEDWINDOW + WS_CLIPCHILDREN).
The default is WS_OVERLAPPEDWINDOW.
Returns: A handle to the newly created window
*/
function WndSetup(cAppName, cTitle, bAction, aWM, nX, nY, nWidth, nHeight, ;
cIcon, cCursor, nBrush, nStyle, cParam)
local hWnd
local hInst := _GetInstance()
local hPrevInst := _GetPrevInstance()
local nCmdShow := _GetnCmdShow()
local hCursor // NOTE: 0 would mean no cursor,
// nil means default: LoadCursor( , IDC_ARROW)
local hBrush // nil means default: GetStockObject(WHITE_BRUSH)
local hIcon // nil means default: LoadIcon( , IDI_APPLICATION)
if hPrevInst == 0
//───── set up icon if one was specified
if cIcon <> NIL
hIcon := LoadIcon(hInst,cIcon)
endif
//───── set up cursor if one was specified
if cCursor <> NIL
hCursor := LoadCursor(hInst, cCursor)
endif
//───── set up background brush if one was specified
if nBrush <> NIL
hBrush := GetStockObject(nBrush)
endif
if ! RegisterClass(CS_HREDRAW + CS_VREDRAW + CS_SAVEBITS ;
; // remove next line to suppress mouse doubleclicks
+ CS_DBLCLKS, ;
hInst, ; // application instance
hIcon, ; // default icon
hCursor, ; // default cursor
hBrush, ; // default background brush
cAppName, ; // class name
bAction, ; // window proc
aWM, ; // msgs wanted
) // defaults for the rest
// (an important default is RCF_WINDOW,
// so unwanted msgs go to the default handler)
// probably out of resources
quit
endif
endif
//───── assign default values for X, Y coordinates, and height/width
if nX == NIL
nX := CW_USEDEFAULT
endif
if nY == NIL
nY := CW_USEDEFAULT
endif
if nWidth == NIL
nWidth := CW_USEDEFAULT
endif
if nHeight == NIL
nHeight := CW_USEDEFAULT
endif
if nStyle == nil
nStyle = WS_OVERLAPPEDWINDOW
endif
hWnd = CreateWindow(cAppName, ; // window class
cTitle, ; // caption for title bar
nStyle, ; // window style
nX, ; // x co-ordinate
nY, ; // y co-ordinate
nWidth, ; // width
nHeight, ; // height
0, ; // hWnd of parent (none)
0, ; // hMenu of menu (none yet)
hInst, ; // our own app instance
cParam) // optional params
if hWnd == 0
MessageBox(, "Window Creation Failed!", "Error", MB_ICONEXCLAMATION + MB_OK)
hWnd := NIL
endif
// make sure it's displayed ...
ShowWindow(hWnd, nCmdShow)
// ... and up to date
UpdateWindow(hWnd) // bAction can get invoked from here
return hWnd
//───── end of file WNDSETUP.PRG