beautypg.com

Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual

Page 238

background image

II. SOFTWARE GUIDES - 10. Driver488/W31

10E. C Languages

Personal488 User’s Manual, Rev. 3.0

II-223

/*******************************************************************/
/*

*/

/* nCwRegisterClasses Function

*/

/*

*/

/* The following function registers all the classes of all the

*/

/* windows associated with this application. The function returns */
/* an error code if unsuccessful, otherwise it returns 0.

*/

/*

*/

/*******************************************************************/
int nCwRegisterClasses(void)
{
WNDCLASS wndclass; /* struct to define a window class

*/

memset(&wndclass, 0x00, sizeof(WNDCLASS));

/* load WNDCLASS with window’s characteristics

*/

wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = WndProc;
/* Extra storage for Class and Window objects

*/

wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(hInst, “EXAMPLE2");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
/* Create brush for erasing background

*/

wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = szAppName;

/* Menu Name is App Name

*/

wndclass.lpszClassName = szAppName;

/* Class Name is App Name*/

if (!RegisterClass(&wndclass))
return -1;
return(0);
} /* End of nCwRegisterClasses

*/

/*******************************************************************/
/* cwCenter Function

*/

/*

*/

/* centers a window based on the client area of its parent

*/

/*

*/

/*******************************************************************/
void cwCenter(hWnd, top)
HWND hWnd;
int top;
{
POINT pt;
RECT swp;
RECT rParent;
int iwidth;
int iheight;

/* get the rectangles for the parent and the child

*/

GetWindowRect(hWnd, &swp);
GetClientRect(hWndMain, &rParent);

/* calculate the height and width for MoveWindow

*/

iwidth = swp.right - swp.left;
iheight = swp.bottom - swp.top;

/* find the center point and convert to screen coordinates

*/

pt.x = (rParent.right - rParent.left) / 2;
pt.y = (rParent.bottom - rParent.top) / 2;
ClientToScreen(hWndMain, &pt);

/* calculate the new x, y starting point

*/

pt.x = pt.x - (iwidth / 2);
pt.y = pt.y - (iheight / 2);
/* top will adjust the window position, up or down

*/

if (top)