|
|
1.1.1.2 ! root 1: /******************************************************************************\ 1.1 root 2: * 3: * MODULE: SPINCUBE.C 4: * 5: * PURPOSE: Demonstrates how to create a custom control library which 6: * may be used by applications and the Dialog Editor. 7: * 8: * FUNCTIONS: DLLEntryPoint() - Registers spincube class when a 9: * process loads this DLL. 10: * CustomControlInfoA() - Called by DLGEDIT to initialize 11: * a CCINFO structure(s). 12: * SpincubeStyle() - Brings up dialog box which allows 13: * user to modify control style. 14: * SpincubeSizeToText() - Called by DLGEDIT if user requests 15: * that control be sized to fit text. 16: * SpincubeWndProc() - Window procedure for spincube 17: * control. 18: * SpincubeDlgProc() - Procedure for control style dialog. 19: * 20: * COMMMENTS: The dialog editor interface has changed since Win 3.0. 21: * I recommend browsing the NT CUSTCNTL.H file to get an 22: * idea of the new interface. 23: * 1.1.1.2 ! root 24: * ! 25: * Microsoft Developer Support ! 26: * Copyright (c) 1992 Microsoft Corporation ! 27: * ! 28: \******************************************************************************/ 1.1 root 29: 30: #include <windows.h> 31: #include "spincube.h" 32: 1.1.1.2 ! root 33: void Paint (HWND); // function prototype for Paint() in PAINT.C 1.1 root 34: 35: 36: 1.1.1.2 ! root 37: /******************************************************************************\ 1.1 root 38: * 39: * FUNCTION: DLLEntryPoint 40: * 41: * INPUTS: hDLL - DLL module handle 42: * dwReason - reason being called (e.g. process attaching) 43: * lpReserved - reserved 44: * 45: * RETURNS: (Only used when dwReason == DLL_PROCESS_ATTACH) 46: * TRUE if initialization passed, or 47: * FALSE if initialization failed. 48: * 1.1.1.2 ! root 49: * GLOBAL VARS: ghMod - DLL module handle 1.1 root 50: * 51: * COMMENTS: On DLL_PROCESS_ATTACH registers the SPINCUBECLASS 52: * 1.1.1.2 ! root 53: \******************************************************************************/ 1.1 root 54: 1.1.1.2 ! root 55: BOOL WINAPI DLLEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) 1.1 root 56: { 1.1.1.2 ! root 57: ghMod = hDLL; 1.1 root 58: switch (dwReason) 59: { 60: case DLL_PROCESS_ATTACH: 61: { 62: WNDCLASS wc; 63: 64: wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_CLASSDC | 65: CS_GLOBALCLASS ; 66: wc.lpfnWndProc = (WNDPROC) SpincubeWndProc; 67: wc.cbClsExtra = 0; 68: wc.cbWndExtra = SPINCUBE_EXTRA; 69: wc.hInstance = hDLL; 70: wc.hIcon = NULL; 71: wc.hCursor = LoadCursor (NULL, IDC_ARROW); 72: wc.hbrBackground = NULL; 73: wc.lpszMenuName = (LPSTR) NULL; 74: wc.lpszClassName = (LPSTR) SPINCUBECLASS; 75: 76: if (!RegisterClass (&wc)) 77: { 1.1.1.2 ! root 78: MessageBox (NULL, (LPCTSTR) "DLLEntryPoint(): RegisterClass() failed", ! 79: (LPCTSTR) "Err! - SPINCUBE.DLL", ! 80: MB_OK | MB_ICONEXCLAMATION); 1.1 root 81: return FALSE; 82: } 83: break; 84: } 85: default: 86: break; 87: } 88: return TRUE; 89: } 90: 91: 92: 1.1.1.2 ! root 93: /******************************************************************************\ 1.1 root 94: * 95: * FUNCTION: CustomControlInfoA 96: * 97: * INPUTS: acci - pointer to an array od CCINFOA structures 98: * 99: * RETURNS: Number of controls supported by this DLL 100: * 101: * COMMENTS: See CUSTCNTL.H for more info 102: * 1.1.1.2 ! root 103: \******************************************************************************/ 1.1 root 104: 105: UINT CALLBACK CustomControlInfoA (LPCCINFOA acci) 106: { 1.1.1.2 ! root 107: // ! 108: // dlgedit is querying the number of controls this DLL supports, so return 1. ! 109: // Then we'll get called again with a valid "acci" ! 110: // ! 111: ! 112: if (!acci) ! 113: ! 114: return 1; 1.1 root 115: 116: acci[0].flOptions = 0; 1.1.1.2 ! root 117: acci[0].cxDefault = 40; // default width (dialog units) ! 118: acci[0].cyDefault = 40; // default height (dialog units) 1.1 root 119: acci[0].flStyleDefault = WS_CHILD | 120: WS_VISIBLE; 121: acci[0].flExtStyleDefault = 0; 122: acci[0].flCtrlTypeMask = 0; 1.1.1.2 ! root 123: acci[0].cStyleFlags = 1; // entries in following style table 1.1 root 124: 125: if (!(acci[0].aStyleFlags = (LPCCSTYLEFLAG) 126: LocalAlloc (LPTR, sizeof(CCSTYLEFLAG) + 127: sizeof(STYLEDEFSTR) + 1))) 128: return 0; 129: 130: acci[0].aStyleFlags[0].flStyle = 0; 131: acci[0].aStyleFlags[0].flStyleMask = 0; 132: acci[0].aStyleFlags[0].pszStyle = (LPSTR) &acci[1]; 133: acci[0].lpfnStyle = SpincubeStyle; 134: acci[0].lpfnSizeToText = SpincubeSizeToText; 135: acci[0].dwReserved1 = 0; 136: acci[0].dwReserved2 = 0; 137: 138: lstrcpy (acci[0].szClass, SPINCUBECLASS); 139: lstrcpy (acci[0].szDesc, SPINCUBEDESCRIPTION); 140: lstrcpy (acci[0].szTextDefault, SPINCUBEDEFTEXT); 141: lstrcpy ((char *)&acci[1], STYLEDEFSTR); 142: 1.1.1.2 ! root 143: // ! 144: // return the number of controls that the DLL supports ! 145: // ! 146: ! 147: return 1; 1.1 root 148: } 149: 150: 151: 1.1.1.2 ! root 152: /******************************************************************************\ 1.1 root 153: * 154: * FUNCTION: SpincubeStyle 155: * 156: * INPUTS: hWndParent - handle of parent window (dialog editor) 157: * pccs - pointer to a CCSTYLE structure 158: * 159: * RETURNS: TRUE if success, 160: * FALSE if error occured 161: * 162: * GLOBAL VARS: gpccs - global pointer to a CCSTYLE structure 163: * 164: * LOCAL VARS: rc - return code from DialogBox 165: * 1.1.1.2 ! root 166: \******************************************************************************/ 1.1 root 167: 168: BOOL CALLBACK SpincubeStyle (HWND hWndParent, LPCCSTYLE pccs) 169: { 170: int rc; 171: 172: gpccs = pccs; 173: 1.1.1.2 ! root 174: if ((rc = DialogBox (ghMod, "SpincubeStyle", hWndParent, 1.1 root 175: (DLGPROC)SpincubeDlgProc)) == -1) 176: { 1.1.1.2 ! root 177: MessageBox (hWndParent, (LPCTSTR) "SpincubeStyle(): DialogBox failed", ! 178: (LPCTSTR) "Err!- Spincube.dll", 1.1 root 179: MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); 180: rc = 0; 181: } 182: return (BOOL) rc; 183: } 184: 185: 186: 1.1.1.2 ! root 187: /******************************************************************************\ 1.1 root 188: * 189: * FUNCTION: SpincubeSizeToText 190: * 191: * INPUTS: flStyle - control style 192: * flExtStyle - control extended style 193: * hFont - handle of font used to draw text 194: * pszText - control text 195: * 196: * RETURNS: Width (in pixels) control must be to accomodate text, or 197: * -1 if an error occurs. 198: * 199: * COMMENTS: Just no-op here 200: * 1.1.1.2 ! root 201: \******************************************************************************/ 1.1 root 202: 203: INT CALLBACK SpincubeSizeToText (DWORD flStyle, DWORD flExtStyle, 204: HFONT hFont, LPSTR pszText) 205: { 206: return -1; 207: } 208: 209: 210: 211: 1.1.1.2 ! root 212: /******************************************************************************\ 1.1 root 213: * 214: * FUNCTION: SpincubeWndProc (standard window procedure INPUTS/RETURNS) 215: * 216: * COMMENTS: This is the window procedure for our custom control. At 217: * creation we alloc a SPINCUBEINFO struct, initialize it, 218: * and associate it with this particular control. We also 219: * start a timer which will invalidate the window every so 220: * often; this causes a repaint, and the cube gets drawn in 221: * a new position. Left button clicks will toggle the motion 222: * state of the control (and turn the timer on/off). 223: * 1.1.1.2 ! root 224: \******************************************************************************/ 1.1 root 225: 1.1.1.2 ! root 226: LRESULT CALLBACK SpincubeWndProc (HWND hWnd, UINT msg, WPARAM wParam, ! 227: LPARAM lParam) 1.1 root 228: { 229: switch (msg) 230: { 231: case WM_CREATE: 232: { 1.1.1.2 ! root 233: // ! 234: // Alloc & init a SPINCUBEINFO struct for this particular control ! 235: // 1.1 root 236: 237: HANDLE hSCI = LocalAlloc (LHND, sizeof(SPINCUBEINFO)); 238: PSPINCUBEINFO pSCI = (PSPINCUBEINFO) LocalLock (hSCI); 239: pSCI->xRotAngle = (float) 0.0; 240: pSCI->xRotAngle = (float) 0.0; 241: pSCI->xRotAngle = (float) 0.0; 242: pSCI->inMotion = TRUE; 243: LocalUnlock (hSCI); 244: SetWindowLong (hWnd, GWL_SPINCUBEDATA, (LONG) hSCI); 245: 246: SetTimer (hWnd, SPIN_EVENT, SPIN_INTERVAL, NULL); 247: break; 248: } 249: 250: case WM_PAINT: 251: 252: Paint (hWnd); 253: break; 254: 255: case WM_TIMER: 256: 257: switch (wParam) 258: { 259: case SPIN_EVENT: 260: InvalidateRect (hWnd, NULL, FALSE); 261: break; 262: } 263: break; 264: 265: case WM_LBUTTONDOWN: 266: { 1.1.1.2 ! root 267: // ! 268: // Change the inMotion state of the control ! 269: // 1.1 root 270: 271: HANDLE hSCI = (HANDLE) GetWindowLong (hWnd, GWL_SPINCUBEDATA); 272: PSPINCUBEINFO pSCI = (PSPINCUBEINFO) LocalLock (hSCI); 273: if (pSCI->inMotion) 274: { 275: KillTimer (hWnd, SPIN_EVENT); 276: pSCI->inMotion = FALSE; 277: } 278: else 279: { 280: SetTimer (hWnd, SPIN_EVENT, SPIN_INTERVAL, NULL); 281: pSCI->inMotion = TRUE; 282: } 283: LocalUnlock (hSCI); 284: 285: break; 286: } 1.1.1.2 ! root 287: 1.1 root 288: case WM_DESTROY: 289: { 290: HANDLE hSCI = (HANDLE) GetWindowLong (hWnd, GWL_SPINCUBEDATA); 291: LocalFree (hSCI); 292: break; 293: } 1.1.1.2 ! root 294: 1.1 root 295: default: 296: 297: return (DefWindowProc(hWnd, msg, wParam, lParam)); 298: } 299: return ((LONG) TRUE); 300: } 301: 302: 303: 1.1.1.2 ! root 304: /******************************************************************************\ 1.1 root 305: * 306: * FUNCTION: SpincubeDlgProc (standard dialog procedure INPUTS/RETURNS) 307: * 308: * GLOBAL VARS: gpccs - pointer to a CCSTYLE structure 309: * 310: * COMMENTS: The dialog comes up in response to a user requesting to 311: * modify the control style. This sample allows for changing 312: * the control's text, and this is done by modifying the 313: * CCSTYLE structure pointed at by "gpccs" (a pointer 314: * that was passed to us by dlgedit). 315: * 1.1.1.2 ! root 316: \******************************************************************************/ 1.1 root 317: 1.1.1.2 ! root 318: LRESULT CALLBACK SpincubeDlgProc (HWND hDlg, UINT msg, WPARAM wParam, ! 319: LPARAM lParam) 1.1 root 320: { 321: switch (msg) 322: { 323: case WM_INITDIALOG : 324: { 325: SetDlgItemText (hDlg, DID_EDIT, gpccs->szText); 326: break; 327: } 328: 329: case WM_COMMAND: 330: 331: switch (LOWORD(wParam)) 332: { 333: case DID_CANCEL: 334: 335: EndDialog (hDlg, 0); 336: break; 337: 338: case DID_OK: 339: 340: GetDlgItemText (hDlg, DID_EDIT, gpccs->szText, 341: CCHCCTEXT); 342: EndDialog (hDlg, 1); 343: break; 344: } 345: break; 346: } 347: return FALSE; 348: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.