home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
source
/
adg_4-6
/
cntl-de.c
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
8KB
|
217 lines
/****************************************************************************
Module name: Cntl-DE.C
Programmer : Jeffrey M. Richter.
*****************************************************************************/
#include "..\nowindws.h"
#undef NOCTLMGR
#undef NOKERNEL
#undef NOLSTRING
#undef NOMEMMGR
#undef NOUSER
#include <windows.h>
#include <custcntl.h>
#include "cntl-de.h"
// Property string used internally to store local handle of CTLSTYLEDLG
// data structure.
static char _szCtlProp[] = "CtlDlgStyleData";
// Data structure used internally to get information into the style
// dialog box function.
typedef struct {
GLOBALHANDLE hCtlStyle; // Memory handle holds CTLSTYLE for control.
LPFNSTRTOID lpfnStrToId; // DIALOG func to cnvrt string ID to number.
LPFNIDTOSTR lpfnIdToStr; // DIALOG func to cnvrt numeric ID to string.
} CTLSTYLEDLG, FAR *LPCTLSTYLEDLG, NEAR *NPCTLSTYLEDLG;
// This function should be called first in the ClassInfo function to
// initialize the new control.
GLOBALHANDLE FAR PASCAL ControlInfo (WORD wVersion, LPSTR szClass, LPSTR szTitle) {
GLOBALHANDLE hMem = NULL;
LPCTLINFO lpCtlInfo;
hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
(DWORD) sizeof(CTLINFO));
if (hMem == NULL) return(hMem);
lpCtlInfo = (LPCTLINFO) GlobalLock(hMem);
lpCtlInfo->wVersion = wVersion;
// Initialize wCtlTypes to zero, incremented by AddControlType function.
lpCtlInfo->wCtlTypes = 0;
lstrcpy(lpCtlInfo->szClass, szClass);
lstrcpy(lpCtlInfo->szTitle, szTitle);
GlobalUnlock(hMem);
return(hMem);
}
// This function should be called repeatedly to add new control types to
// the structure returned by the ControlInfo function. This function should
// be called in the ClassInfo function.
BOOL FAR PASCAL AddControlType (GLOBALHANDLE hMem, WORD wType,
WORD wWidth, WORD wHeight, DWORD dwStyle, LPSTR szDescr) {
LPCTLINFO lpCtlInfo; WORD wNumTypes;
lpCtlInfo = (LPCTLINFO) GlobalLock(hMem);
wNumTypes = lpCtlInfo->wCtlTypes;
if (wNumTypes == CTLTYPES) {
GlobalUnlock(hMem);
return(FALSE);
}
lpCtlInfo->Type[wNumTypes].wType = wType;
lpCtlInfo->Type[wNumTypes].wWidth = wWidth;
lpCtlInfo->Type[wNumTypes].wHeight = wHeight;
lpCtlInfo->Type[wNumTypes].dwStyle = dwStyle;
lstrcpy(lpCtlInfo->Type[wNumTypes].szDescr, szDescr);
lpCtlInfo->wCtlTypes++;
GlobalUnlock(hMem);
return(TRUE);
}
// This function displays the control's style dialog box and should be called
// from the ClassStyle function.
int FAR PASCAL ShowStyleDlg (HANDLE hInstance, LPSTR szTemplate,
HWND hWndParent, FARPROC fpDlgProc, LONG lParam,
GLOBALHANDLE hCtlStyle, LPFNSTRTOID lpfnStrToId,
LPFNIDTOSTR lpfnIdToStr) {
LOCALHANDLE hCtlStyleDlg;
NPCTLSTYLEDLG npCtlStyleDlg;
int x;
hCtlStyleDlg =
LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, sizeof(CTLSTYLEDLG));
if (hCtlStyleDlg == NULL) return(FALSE);
npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
npCtlStyleDlg->hCtlStyle = hCtlStyle;
npCtlStyleDlg->lpfnStrToId = lpfnStrToId;
npCtlStyleDlg->lpfnIdToStr = lpfnIdToStr;
LocalUnlock(hCtlStyleDlg);
// Associate property with Dialog Editor's window.
SetProp(hWndParent, _szCtlProp, hCtlStyleDlg);
// Display control's Styles Dialog Box.
x = DialogBoxParam(hInstance, szTemplate, hWndParent, fpDlgProc, lParam);
// Remove property associated with Dialog Editor's window.
RemoveProp(hWndParent, _szCtlProp);
LocalFree(hCtlStyleDlg);
return(x == IDOK); // Return whether CTLSTYLE structure has been changed.
}
// This function should only be called from the ClassDlgFn function. It
// locks the memory block containing the CTLSTYLE structure for the selected
// control and returns the FAR address to that structure.
LPCTLSTYLE FAR PASCAL CtlStyleLock (HWND hDlg) {
LOCALHANDLE hCtlStyleDlg;
NPCTLSTYLEDLG npCtlStyleDlg;
LPCTLSTYLE lpCtlStyle = NULL;
// Property is associated with Dialog Editor's window. Parent of
// the dialog box is the Dialog Editor.
hCtlStyleDlg = GetProp(GetParent(hDlg), _szCtlProp);
if (hCtlStyleDlg == NULL) return(lpCtlStyle);
npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
lpCtlStyle = (LPCTLSTYLE) GlobalLock(npCtlStyleDlg->hCtlStyle);
LocalUnlock(hCtlStyleDlg);
return(lpCtlStyle);
}
// This function should only be called from the ClassDlgFn function. It
// unlocks the memory block containing the CTLSTYLE structure for the
// selected control and returns whether the block was successfully unlocked.
BOOL FAR PASCAL CtlStyleUnlock (HWND hDlg) {
LOCALHANDLE hCtlStyleDlg;
NPCTLSTYLEDLG npCtlStyleDlg;
BOOL fOk = FALSE;
// Property is associated with Dialog Editor's window. Parent of
// the dialog box is the Dialog Editor.
hCtlStyleDlg = GetProp(GetParent(hDlg), _szCtlProp);
if (hCtlStyleDlg == NULL) return(fOk);
npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
fOk = GlobalUnlock(npCtlStyleDlg->hCtlStyle);
LocalUnlock(hCtlStyleDlg);
return(fOk);
}
// This function should only be called from the ClassDlgFn function. It
// converts the ID value for the control into a identifier string and stores
// the string in the address passed in. The number of characters in the
// string is returned.
WORD FAR PASCAL GetIdString (HWND hDlg, LPSTR szId, WORD wIdMaxLen) {
LOCALHANDLE hCtlStyleDlg;
NPCTLSTYLEDLG npCtlStyleDlg;
LPCTLSTYLE lpCtlStyle;
WORD wIdLen;
// Property is associated with Dialog Editor's window. Parent of
// the dialog box is the Dialog Editor.
hCtlStyleDlg = GetProp(GetParent(hDlg), _szCtlProp);
if (hCtlStyleDlg == NULL) return(0);
npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
lpCtlStyle = (LPCTLSTYLE) GlobalLock(npCtlStyleDlg->hCtlStyle);
// Call the lpfnIdToStr function to convert the numeric ID to its
// string equivalent.
wIdLen = (*npCtlStyleDlg->lpfnIdToStr)(lpCtlStyle->wId, szId, wIdMaxLen);
GlobalUnlock(npCtlStyleDlg->hCtlStyle);
LocalUnlock(hCtlStyleDlg);
return(wIdLen);
}
// This function should only be called from the ClassDlgFn function. It
// converts an ID string value into its numeric equivalent and stores the
// numeric value in the CTLSTYLE structure for the control. If the loword of
// the result is 0, the ID is invalid, otherwise, the hiword contains the
// numeric value of the ID.
DWORD FAR PASCAL SetIdValue (HWND hDlg, LPSTR szId) {
LOCALHANDLE hCtlStyleDlg;
NPCTLSTYLEDLG npCtlStyleDlg;
LPCTLSTYLE lpCtlStyle;
DWORD dwResult = 0;
hCtlStyleDlg = GetProp(GetParent(hDlg), _szCtlProp);
if (hCtlStyleDlg == NULL) return(dwResult);
npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
// Call the lpfnStrToId function to convert the string ID to its
// numeric equivalent.
dwResult = (*npCtlStyleDlg->lpfnStrToId)(szId);
LocalUnlock(hCtlStyleDlg);
// If LOWORD is zero, string NOT found.
if (LOWORD(dwResult) == 0)
return(dwResult);
// LOWORD is not zero, numeric ID is in the HIWORD.
lpCtlStyle = CtlStyleLock(hDlg);
lpCtlStyle->wId = HIWORD(dwResult);
CtlStyleUnlock(hDlg);
return(dwResult);
}