|
|
1.1 ! root 1: /**************************************************************************** ! 2: * ! 3: * ! 4: * PROGRAM: Stereo.c ! 5: * ! 6: * PURPOSE: Example of a Control Panel Application ! 7: * ! 8: * FUNCTIONS: ! 9: * ! 10: * DllMain() ! 11: * InitStereoApplet() ! 12: * TermStereoApplet() ! 13: * CPIApplet() ! 14: * AmpDlgProc() ! 15: * TermDlgProc() ! 16: * TunerDlgProc() ! 17: * ! 18: * COMMENTS: ! 19: * ! 20: * The following code sample shows the CPlApplet function for a DLL containing ! 21: * three Control Panel applications that set preferences for a component stereo ! 22: * system attached to the computer. The sample uses an application-defined ! 23: * StereoApplets array that contains three structures, each corresponding to ! 24: * one of the Control Panel applications. Each structure contains all the ! 25: * information required by the CPL_NEWINQUIRE message, as well as the dialog ! 26: * box template and dialog box procedure required by the CPL_DBLCLK message. ! 27: * The code demonstrates how to fill the structures in the StereoApplets array. ! 28: * ! 29: ****************************************************************************/ ! 30: ! 31: #include <windows.h> ! 32: #include <cpl.h> ! 33: #include "stereo.h" ! 34: ! 35: typedef struct tagApplets ! 36: { ! 37: int icon; // icon resource identifier ! 38: int namestring; // name-string resource identifier ! 39: int descstring; // description-string resource identifier ! 40: int dlgtemplate; // dialog box template resource identifier ! 41: DLGPROC dlgfn; // dialog box procedure ! 42: } APPLETS; ! 43: ! 44: APPLETS StereoApplets[] = ! 45: { ! 46: AMP_ICON, AMP_NAME, AMP_DESC, AMP_DLG, AmpDlgProc, ! 47: TUNER_ICON, TUNER_NAME, TUNER_DESC, TUNER_DLG, TunerDlgProc, ! 48: TAPE_ICON, TAPE_NAME, TAPE_DESC, TAPE_DLG, TapeDlgProc, ! 49: ! 50: }; ! 51: ! 52: #define NUM_APPLETS (sizeof(StereoApplets)/sizeof(StereoApplets[0])) ! 53: ! 54: ! 55: HANDLE hModule = NULL; ! 56: ! 57: char szCtlPanel[30]; ! 58: ! 59: /**************************************************************************** ! 60: * ! 61: * FUNCTION: DllMain(PVOID, ULONG, PCONTEXT) ! 62: * ! 63: * PURPOSE: Win 32 Initialization DLL ! 64: * ! 65: * COMMENTS: ! 66: * ! 67: * ! 68: ****************************************************************************/ ! 69: ! 70: BOOL WINAPI DllMain( ! 71: IN PVOID hmod, ! 72: IN ULONG ulReason, ! 73: IN PCONTEXT pctx OPTIONAL) ! 74: { ! 75: if (ulReason != DLL_PROCESS_ATTACH) ! 76: { ! 77: return TRUE; ! 78: } ! 79: else ! 80: { ! 81: hModule = hmod; ! 82: } ! 83: ! 84: return TRUE; ! 85: ! 86: UNREFERENCED_PARAMETER(pctx); ! 87: } ! 88: ! 89: ! 90: /**************************************************************************** ! 91: * ! 92: * FUNCTION: InitStereoApplet(HWND) ! 93: * ! 94: * PURPOSE: loads the caption string for the Control Panel ! 95: * ! 96: * COMMENTS: ! 97: * ! 98: * ! 99: ****************************************************************************/ ! 100: ! 101: BOOL InitStereoApplet (HWND hwndParent) ! 102: { ! 103: LoadString (hModule, CPCAPTION, szCtlPanel, sizeof(szCtlPanel)); ! 104: ! 105: return TRUE; ! 106: ! 107: UNREFERENCED_PARAMETER(hwndParent); ! 108: } ! 109: ! 110: ! 111: /**************************************************************************** ! 112: * ! 113: * FUNCTION: TermStereoApplet() ! 114: * ! 115: * PURPOSE: termination procedure for the stereo applets ! 116: * ! 117: * COMMENTS: ! 118: * ! 119: * ! 120: ****************************************************************************/ ! 121: ! 122: void TermStereoApplet() ! 123: { ! 124: return; ! 125: } ! 126: ! 127: ! 128: ! 129: /**************************************************************************** ! 130: * ! 131: * FUNCTION: CPIApplet(HWND, UINT, LONG, LONG) ! 132: * ! 133: * PURPOSE: Processes messages for control panel applets ! 134: * ! 135: * COMMENTS: ! 136: * ! 137: * ! 138: ****************************************************************************/ ! 139: LONG CALLBACK CPlApplet (hwndCPL, uMsg, lParam1, lParam2) ! 140: HWND hwndCPL; // handle of Control Panel window ! 141: UINT uMsg; // message ! 142: LONG lParam1; // first message parameter ! 143: LONG lParam2; // second message parameter ! 144: { ! 145: int iApplet; ! 146: LPNEWCPLINFO lpNewCPlInfo; ! 147: static iInitCount = 0; ! 148: ! 149: switch (uMsg) { ! 150: case CPL_INIT: // first message, sent once ! 151: if (!iInitCount) ! 152: { ! 153: if (!InitStereoApplet(hwndCPL)) ! 154: return FALSE; ! 155: } ! 156: iInitCount++; ! 157: return TRUE; ! 158: ! 159: case CPL_GETCOUNT: // second message, sent once ! 160: return (LONG)NUM_APPLETS; ! 161: break; ! 162: ! 163: case CPL_NEWINQUIRE: // third message, sent once per app ! 164: lpNewCPlInfo = (LPNEWCPLINFO) lParam2; ! 165: ! 166: iApplet = (int)(LONG)lParam1; ! 167: lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO); ! 168: lpNewCPlInfo->dwFlags = 0; ! 169: lpNewCPlInfo->dwHelpContext = 0; ! 170: lpNewCPlInfo->lData = 0; ! 171: lpNewCPlInfo->hIcon = LoadIcon (hModule, ! 172: (LPCTSTR) MAKEINTRESOURCE(StereoApplets[iApplet].icon)); ! 173: lpNewCPlInfo->szHelpFile[0] = '\0'; ! 174: ! 175: LoadString (hModule, StereoApplets[iApplet].namestring, ! 176: lpNewCPlInfo->szName, 32); ! 177: ! 178: LoadString (hModule, StereoApplets[iApplet].descstring, ! 179: lpNewCPlInfo->szInfo, 64); ! 180: break; ! 181: ! 182: case CPL_SELECT: // application icon selected ! 183: break; ! 184: ! 185: ! 186: case CPL_DBLCLK: // application icon double-clicked ! 187: iApplet = (int)(LONG)lParam1; ! 188: MessageBeep (MB_ICONEXCLAMATION); ! 189: ! 190: DialogBox (hModule, ! 191: MAKEINTRESOURCE(StereoApplets[iApplet].dlgtemplate), ! 192: hwndCPL, ! 193: StereoApplets[iApplet].dlgfn); ! 194: break; ! 195: ! 196: case CPL_STOP: // sent once per app. before CPL_EXIT ! 197: break; ! 198: ! 199: case CPL_EXIT: // sent once before FreeLibrary called ! 200: iInitCount--; ! 201: if (!iInitCount) ! 202: TermStereoApplet(); ! 203: break; ! 204: ! 205: default: ! 206: break; ! 207: } ! 208: return 0; ! 209: } ! 210: ! 211: /**************************************************************************** ! 212: * ! 213: * FUNCTION: AmpDlgProc ! 214: * ! 215: * PURPOSE: Processes messages sent to the Amp applet. ! 216: * ! 217: * COMMENTS: ! 218: * ! 219: * This dialog simply puts up a box and has an OK key. It doesn't ! 220: * do anything except display. ! 221: * ! 222: ****************************************************************************/ ! 223: BOOL APIENTRY AmpDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam) ! 224: { ! 225: switch (message) ! 226: { ! 227: case WM_INITDIALOG: ! 228: return (TRUE); ! 229: ! 230: case WM_COMMAND: ! 231: if (LOWORD(wParam)) ! 232: { ! 233: EndDialog(hDlg, TRUE); ! 234: return (TRUE); ! 235: } ! 236: break; ! 237: } ! 238: return (FALSE); ! 239: } ! 240: ! 241: /**************************************************************************** ! 242: * ! 243: * FUNCTION: TunerDlgProc ! 244: * ! 245: * PURPOSE: Processes messages sent to the Tuner applet. ! 246: * ! 247: * COMMENTS: ! 248: * ! 249: * This dialog simply puts up a box and has an OK key. It doesn't ! 250: * do anything except display. ! 251: * ! 252: ****************************************************************************/ ! 253: BOOL APIENTRY TunerDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam) ! 254: { ! 255: switch (message) ! 256: { ! 257: case WM_INITDIALOG: ! 258: return (TRUE); ! 259: ! 260: case WM_COMMAND: ! 261: if (LOWORD(wParam)) ! 262: { ! 263: EndDialog(hDlg, TRUE); ! 264: return (TRUE); ! 265: } ! 266: break; ! 267: } ! 268: return (FALSE); ! 269: } ! 270: ! 271: /**************************************************************************** ! 272: * ! 273: * FUNCTION: TapeDlgProc ! 274: * ! 275: * PURPOSE: Processes messages sent to the Tape applet. ! 276: * ! 277: * COMMENTS: ! 278: * ! 279: * This dialog simply puts up a box and has an OK key. It doesn't ! 280: * do anything except display. ! 281: * ! 282: ****************************************************************************/ ! 283: BOOL APIENTRY TapeDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam) ! 284: { ! 285: switch (message) ! 286: { ! 287: case WM_INITDIALOG: ! 288: return (TRUE); ! 289: ! 290: case WM_COMMAND: ! 291: if (LOWORD(wParam)) ! 292: { ! 293: EndDialog(hDlg, TRUE); ! 294: return (TRUE); ! 295: } ! 296: break; ! 297: } ! 298: return (FALSE); ! 299: } ! 300:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.