- Update to r53061
[reactos.git] / dll / cpl / main / main.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS Sample Control Panel
22 * FILE: lib/cpl/main/main.c
23 * PURPOSE: ReactOS Main Control Panel
24 * PROGRAMMER: Eric Kohl
25 * UPDATE HISTORY:
26 * 05-01-2004 Created
27 */
28
29 #include "main.h"
30
31 #define NUM_APPLETS (2)
32
33
34 HINSTANCE hApplet = 0;
35
36
37 /* Applets */
38 APPLET Applets[NUM_APPLETS] =
39 {
40 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, MouseApplet},
41 {IDC_CPLICON_2, IDS_CPLNAME_2, IDS_CPLDESCRIPTION_2, KeyboardApplet}
42 };
43
44
45 BOOL
46 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
47 {
48 HPROPSHEETPAGE hPage;
49 PROPSHEETPAGE psp;
50
51 if (ppsh->nPages < MAX_CPL_PAGES)
52 {
53 ZeroMemory(&psp, sizeof(psp));
54 psp.dwSize = sizeof(psp);
55 psp.dwFlags = PSP_DEFAULT;
56 psp.hInstance = hApplet;
57 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
58 psp.pfnDlgProc = DlgProc;
59
60 hPage = CreatePropertySheetPage(&psp);
61 if (hPage != NULL)
62 {
63 return PropSheetAddPage(hPage, (LPARAM)ppsh);
64 }
65 }
66
67 return FALSE;
68 }
69
70 BOOL CALLBACK
71 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
72 {
73 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
74 if (ppsh != NULL && ppsh->nPages < MAX_CPL_PAGES)
75 {
76 ppsh->phpage[ppsh->nPages++] = hpage;
77 return TRUE;
78 }
79
80 return FALSE;
81 }
82
83
84 /* Control Panel Callback */
85 LONG CALLBACK
86 CPlApplet(HWND hwndCpl,
87 UINT uMsg,
88 LPARAM lParam1,
89 LPARAM lParam2)
90 {
91 switch(uMsg)
92 {
93 case CPL_INIT:
94 return TRUE;
95
96 case CPL_GETCOUNT:
97 return NUM_APPLETS;
98
99 case CPL_INQUIRE:
100 {
101 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
102 UINT uAppIndex = (UINT)lParam1;
103
104 CPlInfo->lData = lParam1;
105 CPlInfo->idIcon = Applets[uAppIndex].idIcon;
106 CPlInfo->idName = Applets[uAppIndex].idName;
107 CPlInfo->idInfo = Applets[uAppIndex].idDescription;
108 break;
109 }
110
111 case CPL_DBLCLK:
112 {
113 UINT uAppIndex = (UINT)lParam1;
114 Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
115 break;
116 }
117 }
118
119 return FALSE;
120 }
121
122
123 BOOL WINAPI
124 DllMain(HINSTANCE hinstDLL,
125 DWORD dwReason,
126 LPVOID lpReserved)
127 {
128 INITCOMMONCONTROLSEX InitControls;
129 UNREFERENCED_PARAMETER(lpReserved);
130
131 switch(dwReason)
132 {
133 case DLL_PROCESS_ATTACH:
134 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
135 InitControls.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_BAR_CLASSES;
136 InitCommonControlsEx(&InitControls);
137
138 hApplet = hinstDLL;
139 break;
140 }
141
142 return TRUE;
143 }
144