cmssetup.c
/*--------------------------------------------------------------------
CMS setup window
L. R. Erickson, Apr. 1994
-------------------------------------------------------------------*/
#include <windows.h>
#include "cms.h"
static int fStartUp = TRUE ;
static int cxMinCnts, cyMinCnts ;
static int cxDispCharSpace, cyDispCharSpace, cyLineSpace ;
struct
{
HWND hwnd ;
int CntrlClassIndex ;
long CntrlStyle ;
char *SetupText ;
int xpos ;
int ypos ;
int width ;
}
static SetupCntrl[] =
{
NULL, CC_BUTTONINDEX, BS_GROUPBOX, "488 BUS", 0, 0, 59,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "RESET INTERFACE", 1, 1, 18,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ 330", 1, 2, 11,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ DVM", 1, 3, 11,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ VAC", 1, 4, 11,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ LAKESHORE", 1, 5, 18,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "USE POSITIONER", 20, 1, 17,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "MIRROR", 22, 2, 10,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "FILTER", 22, 3, 10,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "APERTURE", 22, 4, 12,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "HOME POSITIONER", 40, 1, 19,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "MIRROR", 42, 2, 10,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "FILTER", 42, 3, 10,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "APERTURE", 42, 4, 12,
NULL, CC_BUTTONINDEX, BS_GROUPBOX, "DATA LOGGING", 0, 6, 20,
NULL, CC_STATICINDEX, SS_LEFT, "INTERVAL (MIN)", 1, 7, 15,
NULL, CC_EDITINDEX, WS_BORDER | ES_LEFT, "10", 16, 7, 3,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "TO PRINTER", 1, 8, 12,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "TO DISK", 1, 9, 9,
NULL, CC_STATICINDEX, SS_LEFT, "FILE", 1, 11, 5,
NULL, CC_EDITINDEX, ES_AUTOHSCROLL | WS_BORDER | ES_LEFT,
"", 5, 11, 14,
NULL, CC_BUTTONINDEX, BS_GROUPBOX, "gdc-r", 21, 6, 19,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "LOGIN", 22, 7, 9,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "MOUNT HDR", 22, 8, 14,
NULL, CC_BUTTONINDEX, BS_GROUPBOX, "OTHER", 40, 6, 19,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ 208", 41, 7, 13,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "READ SWITCHES", 41, 8, 17,
NULL, CC_BUTTONINDEX, BS_PUSHBUTTON, "CANCEL", 0, 13, 16,
NULL, CC_BUTTONINDEX, BS_DEFPUSHBUTTON, "OK", 0, 13, 16,
NULL, CC_BUTTONINDEX, BS_PUSHBUTTON, "CONFIGURE CMS", 0, 13, 16,
NULL, CC_BUTTONINDEX, BS_CHECKBOX, "DEFAULT FILE", 1, 10, 15,
} ;
//************* Control ID's -- Want these up front and visible
// and in this file. ID must equal index into SetupCntrl[]
// for the control.
//****************************************************************
#define ID_488BUS 0
#define ID_RESETINTF 1
#define ID_330 2
#define ID_DVM 3
#define ID_VAC 4
#define ID_LAKESHORE 5
#define ID_USEPOS 6
#define ID_MIRROR 7
#define ID_FILTER 8
#define ID_APERTURE 9
#define ID_HOME 10
#define ID_HMIRROR 11
#define ID_HFILTER 12
#define ID_HAPERTURE 13
#define ID_LOG 14
#define ID_INTERVAL 15
#define ID_LOGTIME 16
#define ID_PRINTER 17
#define ID_DISK 18
#define ID_FILE 19
#define ID_FILENAME 20
#define ID_GDCR 21
#define ID_LOGIN 22
#define ID_MTHDR 23
#define ID_OTHER 24
#define ID_208 25
#define ID_SWITCHES 26
#define ID_CANCEL 27
#define ID_SUOK 28
#define ID_CONFIG 29
#define ID_DEFFILE 30
#define NUM_SETUP_CNTRLS (sizeof SetupCntrl / sizeof SetupCntrl[0])
//******************* Start ofCMSSetupProc ******************************
long FAR PASCAL _export CMSSetupWndProc (HWND hwnd, UINT message, UINT wParam,
LONG lParam)
{
static HWND hwndClient, hwndFrame ;
static HWND hwndOKButton ;
static RECT rect ;
static HMENU hMenuSetup, hMenuSetupWindow ;
int index = 0 ;
int i ;
WORD fUsePos ;
CNTLPOS CntlPos ;
switch (message)
{
case WM_CREATE:
// Save window handles
hwndClient = GetParent (hwnd) ;
hwndFrame = GetParent (hwndClient) ;
// Setup menu
hMenuSetup = LoadMenu (globhCMSInst, "CMSSetupMenu") ;
hMenuSetupWindow = GetSubMenu (hMenuSetup, SETUP_MENU_POS) ;
// Set control minimum positions.
SetSetupCntrlMins () ;
// Start up controls
for (i = 0 ; i < NUM_SETUP_CNTRLS ; i++)
{
SetCntlPos (i, &CntlPos) ;
SetupCntrl[i].hwnd = CreateWindow (
globCntrlClass[SetupCntrl[i].CntrlClassIndex],
SetupCntrl[i].SetupText,
WS_CHILD | WS_VISIBLE |
SetupCntrl[i].CntrlStyle,
CntlPos.cxPos, CntlPos.cyPos,
CntlPos.cWidth, CntlPos.cHeight,
hwnd, i, globhCMSInst, NULL) ;
}
return 0 ;
case WM_MDIACTIVATE:
// Set the Setup menu if gaining focus
if (wParam == TRUE)
SendMessage (hwndClient, WM_MDISETMENU, 0,
MAKELONG (hMenuSetup, hMenuSetupWindow)) ;
DrawMenuBar (hwndFrame) ;
return 0 ;
case WM_DESTROY :
DestroyMenu (hMenuSetup) ;
return 0 ;
case WM_COMMAND :
switch (wParam)
{
case ID_SUOK :
if (fStartUp)
{ // Start data acquisition window
fStartUp = FALSE ;
SetWindowText (hwnd, "CMS Setup") ;
PostMessage (hwndFrame, WM_COMMAND, ID_MAKEOPSWIN, 0L) ;
}
return 0 ;
case ID_CANCEL :
// Return to last active window.
if (!fStartUp)
SendMessage (hwndClient, WM_MDINEXT,
(WPARAM) hwnd, 0L) ;
return 0 ;
case ID_USEPOS :
fUsePos = (WORD) SendMessage (SetupCntrl[ID_USEPOS].hwnd,
BM_GETCHECK, 0, 0L) ;
fUsePos = !fUsePos ;
SendMessage (SetupCntrl[ID_USEPOS].hwnd,
BM_SETCHECK, fUsePos, 0L) ;
return 0 ;
}
return 0 ;
case WM_SIZE :
// Reset control windows.
SetDispCharSpace (lParam) ;
for (i = 0 ; i < NUM_SETUP_CNTRLS ; i++)
{
SetCntlPos (i, &CntlPos) ;
MoveWindow (SetupCntrl[i].hwnd,
CntlPos.cxPos, CntlPos.cyPos,
CntlPos.cWidth, CntlPos.cHeight,
TRUE ) ;
}
break ;
}
return DefMDIChildProc (hwnd, message, wParam, lParam) ;
}
//******************* End of CMSSetupProc ******************************
//******************* Start of SetSetupCntrlMins ***********************
// Set control minimum positions.
void SetSetupCntrlMins (void)
{
cxMinCnts = 60 * globcxCharSpace ;
cyMinCnts = 15 * ((11 * globcyCharSpace) / 8) ;
}
//******************* End of SetSetupCntrlMins ***********************
//******************* Start of SetCntlPos **********************
void SetCntlPos (int i, CNTLPOS *CntlPos)
{
CntlPos->cxPos = SetxCnts (i) ;
CntlPos->cyPos = SetyCnts (i) ;
CntlPos->cWidth = SetWidth (i) ;
CntlPos->cHeight = SetHeight (i) ;
}
//******************* End of SetCntlPos **********************
//****************** Start of SetDispCharSpace ************************
void SetDispCharSpace (LONG lParam)
{
if ((int) LOWORD (lParam) <= cxMinCnts)
cxDispCharSpace = globcxCharSpace ;
else
cxDispCharSpace = (int) (((LONG) globcxCharSpace
* (LONG) LOWORD (lParam)) / (LONG) cxMinCnts) ;
if ((int) HIWORD (lParam) <= cyMinCnts)
{
cyDispCharSpace = globcyCharSpace ;
cyLineSpace = (11 * globcyCharSpace) / 8 ;
}
else
{
cyDispCharSpace = (int) (((LONG) globcyCharSpace
* (LONG) HIWORD (lParam)) / (LONG) cyMinCnts) ;
cyLineSpace = (int) (((LONG) ((11 * globcyCharSpace) / 8)
* (LONG) HIWORD (lParam)) / (LONG) cyMinCnts) ;
}
}
//****************** End of SetDispCharSpace ************************
//******************* Start of SetxCnts **********************
int SetxCnts (int i)
{
int cxcnts ;
switch (i)
{
case ID_CANCEL :
cxcnts = (SetupCntrl[ID_LOG].xpos + (SetupCntrl[ID_LOG].width / 2)
- (SetupCntrl[ID_CANCEL].width / 2)) * cxDispCharSpace ;
return cxcnts ;
case ID_SUOK :
cxcnts = (SetupCntrl[ID_GDCR].xpos + (SetupCntrl[ID_GDCR].width / 2)
- (SetupCntrl[ID_SUOK].width / 2)) * cxDispCharSpace ;
return cxcnts ;
case ID_CONFIG :
cxcnts = (SetupCntrl[ID_OTHER].xpos
+ (SetupCntrl[ID_OTHER].width / 2)
- (SetupCntrl[ID_CONFIG].width / 2)) * cxDispCharSpace ;
return cxcnts ;
default :
cxcnts = SetupCntrl[i].xpos * cxDispCharSpace ;
switch (i)
{
case ID_488BUS :
case ID_LOG :
case ID_DEFFILE :
case ID_FILE :
case ID_FILENAME :
case ID_OTHER :
case ID_208 :
case ID_SWITCHES :
cxcnts = cxcnts + (cxDispCharSpace / 2) ;
return cxcnts ;
}
return cxcnts ;
}
}
//******************* End of SetxCnts **********************
//******************* Start of SetWidth **********************
int SetWidth (int i)
{
int width ;
width = SetupCntrl[i].width * cxDispCharSpace ;
return width ;
}
//******************* End of SetWidth **********************
//******************* Start of SetHeight **********************
int SetHeight (int i)
{
int height ;
switch (i)
{
case ID_LOGTIME :
case ID_FILENAME :
height = (3 * globcyCharSpace) / 2 ;
return height ;
case ID_CANCEL :
case ID_SUOK :
case ID_CONFIG :
height = (7 * cyDispCharSpace) / 4 ;
return height ;
case ID_LOG :
case ID_GDCR :
case ID_OTHER :
height = 9 * cyDispCharSpace ;
return height ;
case ID_488BUS :
height = 8 * cyDispCharSpace ;
return height ;
default :
height = (5 * cyDispCharSpace) / 4 ;
return height ;
}
}
//******************* End of SetHeight **********************
//******************* Start of SetyCnts **********************
int SetyCnts (int i)
{
int cycnts ;
cycnts = SetupCntrl[i].ypos * cyLineSpace ;
return cycnts ;
}
//******************* End of SetyCnts **********************