|
|
Microsoft Windows NT Build 328 10-12-1992
/******************************************************************************\
*
* MODULE: SPINCUBE.C
*
* PURPOSE: Demonstrates how to create a custom control library which
* may be used by applications and the Dialog Editor.
*
* FUNCTIONS: DLLEntryPoint() - Registers spincube class when a
* process loads this DLL.
* CustomControlInfoA() - Called by DLGEDIT to initialize
* a CCINFO structure(s).
* SpincubeStyle() - Brings up dialog box which allows
* user to modify control style.
* SpincubeSizeToText() - Called by DLGEDIT if user requests
* that control be sized to fit text.
* SpincubeWndProc() - Window procedure for spincube
* control.
* SpincubeDlgProc() - Procedure for control style dialog.
*
* COMMMENTS: The dialog editor interface has changed since Win 3.0.
* I recommend browsing the NT CUSTCNTL.H file to get an
* idea of the new interface.
*
*
* Microsoft Developer Support
* Copyright (c) 1992 Microsoft Corporation
*
\******************************************************************************/
#include <windows.h>
#include "spincube.h"
void Paint (HWND); // function prototype for Paint() in PAINT.C
/******************************************************************************\
*
* FUNCTION: DLLEntryPoint
*
* INPUTS: hDLL - DLL module handle
* dwReason - reason being called (e.g. process attaching)
* lpReserved - reserved
*
* RETURNS: (Only used when dwReason == DLL_PROCESS_ATTACH)
* TRUE if initialization passed, or
* FALSE if initialization failed.
*
* GLOBAL VARS: ghMod - DLL module handle
*
* COMMENTS: On DLL_PROCESS_ATTACH registers the SPINCUBECLASS
*
\******************************************************************************/
BOOL WINAPI DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{
ghMod = hDLL;
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_CLASSDC |
CS_GLOBALCLASS ;
wc.lpfnWndProc = (WNDPROC) SpincubeWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = SPINCUBE_EXTRA;
wc.hInstance = hDLL;
wc.hIcon = NULL;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = (LPSTR) NULL;
wc.lpszClassName = (LPSTR) SPINCUBECLASS;
if (!RegisterClass (&wc))
{
MessageBox (NULL, (LPCTSTR) "DLLEntryPoint(): RegisterClass() failed",
(LPCTSTR) "Err! - SPINCUBE.DLL",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
break;
}
default:
break;
}
return TRUE;
}
/******************************************************************************\
*
* FUNCTION: CustomControlInfoA
*
* INPUTS: acci - pointer to an array od CCINFOA structures
*
* RETURNS: Number of controls supported by this DLL
*
* COMMENTS: See CUSTCNTL.H for more info
*
\******************************************************************************/
UINT CALLBACK CustomControlInfoA (LPCCINFOA acci)
{
//
// dlgedit is querying the number of controls this DLL supports, so return 1.
// Then we'll get called again with a valid "acci"
//
if (!acci)
return 1;
acci[0].flOptions = 0;
acci[0].cxDefault = 40; // default width (dialog units)
acci[0].cyDefault = 40; // default height (dialog units)
acci[0].flStyleDefault = WS_CHILD |
WS_VISIBLE;
acci[0].flExtStyleDefault = 0;
acci[0].flCtrlTypeMask = 0;
acci[0].cStyleFlags = 1; // entries in following style table
if (!(acci[0].aStyleFlags = (LPCCSTYLEFLAG)
LocalAlloc (LPTR, sizeof(CCSTYLEFLAG) +
sizeof(STYLEDEFSTR) + 1)))
return 0;
acci[0].aStyleFlags[0].flStyle = 0;
acci[0].aStyleFlags[0].flStyleMask = 0;
acci[0].aStyleFlags[0].pszStyle = (LPSTR) &acci[1];
acci[0].lpfnStyle = SpincubeStyle;
acci[0].lpfnSizeToText = SpincubeSizeToText;
acci[0].dwReserved1 = 0;
acci[0].dwReserved2 = 0;
lstrcpy (acci[0].szClass, SPINCUBECLASS);
lstrcpy (acci[0].szDesc, SPINCUBEDESCRIPTION);
lstrcpy (acci[0].szTextDefault, SPINCUBEDEFTEXT);
lstrcpy ((char *)&acci[1], STYLEDEFSTR);
//
// return the number of controls that the DLL supports
//
return 1;
}
/******************************************************************************\
*
* FUNCTION: SpincubeStyle
*
* INPUTS: hWndParent - handle of parent window (dialog editor)
* pccs - pointer to a CCSTYLE structure
*
* RETURNS: TRUE if success,
* FALSE if error occured
*
* GLOBAL VARS: gpccs - global pointer to a CCSTYLE structure
*
* LOCAL VARS: rc - return code from DialogBox
*
\******************************************************************************/
BOOL CALLBACK SpincubeStyle (HWND hWndParent, LPCCSTYLE pccs)
{
int rc;
gpccs = pccs;
if ((rc = DialogBox (ghMod, "SpincubeStyle", hWndParent,
(DLGPROC)SpincubeDlgProc)) == -1)
{
MessageBox (hWndParent, (LPCTSTR) "SpincubeStyle(): DialogBox failed",
(LPCTSTR) "Err!- Spincube.dll",
MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
rc = 0;
}
return (BOOL) rc;
}
/******************************************************************************\
*
* FUNCTION: SpincubeSizeToText
*
* INPUTS: flStyle - control style
* flExtStyle - control extended style
* hFont - handle of font used to draw text
* pszText - control text
*
* RETURNS: Width (in pixels) control must be to accomodate text, or
* -1 if an error occurs.
*
* COMMENTS: Just no-op here
*
\******************************************************************************/
INT CALLBACK SpincubeSizeToText (DWORD flStyle, DWORD flExtStyle,
HFONT hFont, LPSTR pszText)
{
return -1;
}
/******************************************************************************\
*
* FUNCTION: SpincubeWndProc (standard window procedure INPUTS/RETURNS)
*
* COMMENTS: This is the window procedure for our custom control. At
* creation we alloc a SPINCUBEINFO struct, initialize it,
* and associate it with this particular control. We also
* start a timer which will invalidate the window every so
* often; this causes a repaint, and the cube gets drawn in
* a new position. Left button clicks will toggle the motion
* state of the control (and turn the timer on/off).
*
\******************************************************************************/
LRESULT CALLBACK SpincubeWndProc (HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
//
// Alloc & init a SPINCUBEINFO struct for this particular control
//
HANDLE hSCI = LocalAlloc (LHND, sizeof(SPINCUBEINFO));
PSPINCUBEINFO pSCI = (PSPINCUBEINFO) LocalLock (hSCI);
pSCI->xRotAngle = (float) 0.0;
pSCI->xRotAngle = (float) 0.0;
pSCI->xRotAngle = (float) 0.0;
pSCI->inMotion = TRUE;
LocalUnlock (hSCI);
SetWindowLong (hWnd, GWL_SPINCUBEDATA, (LONG) hSCI);
SetTimer (hWnd, SPIN_EVENT, SPIN_INTERVAL, NULL);
break;
}
case WM_PAINT:
Paint (hWnd);
break;
case WM_TIMER:
switch (wParam)
{
case SPIN_EVENT:
InvalidateRect (hWnd, NULL, FALSE);
break;
}
break;
case WM_LBUTTONDOWN:
{
//
// Change the inMotion state of the control
//
HANDLE hSCI = (HANDLE) GetWindowLong (hWnd, GWL_SPINCUBEDATA);
PSPINCUBEINFO pSCI = (PSPINCUBEINFO) LocalLock (hSCI);
if (pSCI->inMotion)
{
KillTimer (hWnd, SPIN_EVENT);
pSCI->inMotion = FALSE;
}
else
{
SetTimer (hWnd, SPIN_EVENT, SPIN_INTERVAL, NULL);
pSCI->inMotion = TRUE;
}
LocalUnlock (hSCI);
break;
}
case WM_DESTROY:
{
HANDLE hSCI = (HANDLE) GetWindowLong (hWnd, GWL_SPINCUBEDATA);
LocalFree (hSCI);
break;
}
default:
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
return ((LONG) TRUE);
}
/******************************************************************************\
*
* FUNCTION: SpincubeDlgProc (standard dialog procedure INPUTS/RETURNS)
*
* GLOBAL VARS: gpccs - pointer to a CCSTYLE structure
*
* COMMENTS: The dialog comes up in response to a user requesting to
* modify the control style. This sample allows for changing
* the control's text, and this is done by modifying the
* CCSTYLE structure pointed at by "gpccs" (a pointer
* that was passed to us by dlgedit).
*
\******************************************************************************/
LRESULT CALLBACK SpincubeDlgProc (HWND hDlg, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG :
{
SetDlgItemText (hDlg, DID_EDIT, gpccs->szText);
break;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case DID_CANCEL:
EndDialog (hDlg, 0);
break;
case DID_OK:
GetDlgItemText (hDlg, DID_EDIT, gpccs->szText,
CCHCCTEXT);
EndDialog (hDlg, 1);
break;
}
break;
}
return FALSE;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.