Merge from amd64-branch:
[reactos.git] / reactos / 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 #include <windows.h>
29 #include <initguid.h>
30 #include <devguid.h>
31 #include <commctrl.h>
32 #include <cpl.h>
33 #include <cplext.h>
34
35 #include "main.h"
36 #include "resource.h"
37
38
39 #define NUM_APPLETS (2)
40
41
42 HINSTANCE hApplet = 0;
43
44
45 /* Applets */
46 APPLET Applets[NUM_APPLETS] =
47 {
48 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, MouseApplet},
49 {IDC_CPLICON_2, IDS_CPLNAME_2, IDS_CPLDESCRIPTION_2, KeyboardApplet}
50 };
51
52
53 BOOL
54 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
55 {
56 HPROPSHEETPAGE hPage;
57 PROPSHEETPAGE psp;
58
59 if (ppsh->nPages < MAX_CPL_PAGES)
60 {
61 ZeroMemory(&psp, sizeof(psp));
62 psp.dwSize = sizeof(psp);
63 psp.dwFlags = PSP_DEFAULT;
64 psp.hInstance = hApplet;
65 psp.pszTemplate = MAKEINTRESOURCE(idDlg);
66 psp.pfnDlgProc = DlgProc;
67
68 hPage = CreatePropertySheetPage(&psp);
69 if (hPage != NULL)
70 {
71 return PropSheetAddPage(hPage, (LPARAM)ppsh);
72 }
73 }
74
75 return FALSE;
76 }
77
78 BOOL CALLBACK
79 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
80 {
81 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
82 if (ppsh != NULL && ppsh->nPages < MAX_CPL_PAGES)
83 {
84 ppsh->phpage[ppsh->nPages++] = hpage;
85 return TRUE;
86 }
87
88 return FALSE;
89 }
90
91
92 /* Control Panel Callback */
93 LONG CALLBACK
94 CPlApplet(HWND hwndCpl,
95 UINT uMsg,
96 LPARAM lParam1,
97 LPARAM lParam2)
98 {
99 switch(uMsg)
100 {
101 case CPL_INIT:
102 return TRUE;
103
104 case CPL_GETCOUNT:
105 return NUM_APPLETS;
106
107 case CPL_INQUIRE:
108 {
109 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
110 UINT uAppIndex = (UINT)lParam1;
111
112 CPlInfo->lData = lParam1;
113 CPlInfo->idIcon = Applets[uAppIndex].idIcon;
114 CPlInfo->idName = Applets[uAppIndex].idName;
115 CPlInfo->idInfo = Applets[uAppIndex].idDescription;
116 break;
117 }
118
119 case CPL_DBLCLK:
120 {
121 UINT uAppIndex = (UINT)lParam1;
122 Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
123 break;
124 }
125 }
126
127 return FALSE;
128 }
129
130
131 BOOL WINAPI
132 DllMain(HINSTANCE hinstDLL,
133 DWORD dwReason,
134 LPVOID lpReserved)
135 {
136 INITCOMMONCONTROLSEX InitControls;
137 UNREFERENCED_PARAMETER(lpReserved);
138
139 switch(dwReason)
140 {
141 case DLL_PROCESS_ATTACH:
142 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
143 InitControls.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_BAR_CLASSES;
144 InitCommonControlsEx(&InitControls);
145
146 hApplet = hinstDLL;
147 break;
148 }
149
150 return TRUE;
151 }
152