xref: /reactos/dll/cpl/main/main.c (revision 53221834)
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 /*
20  * PROJECT:         ReactOS Sample Control Panel
21  * FILE:            dll/cpl/main/main.c
22  * PURPOSE:         ReactOS Main Control Panel
23  * PROGRAMMER:      Eric Kohl
24  * UPDATE HISTORY:
25  *      05-01-2004  Created
26  */
27 
28 #include "main.h"
29 
30 #define NUM_APPLETS	(2)
31 
32 
33 HINSTANCE hApplet = 0;
34 
35 
36 /* Applets */
37 APPLET Applets[NUM_APPLETS] =
38 {
39   {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, MouseApplet},
40   {IDC_CPLICON_2, IDS_CPLNAME_2, IDS_CPLDESCRIPTION_2, KeyboardApplet}
41 };
42 
43 
44 BOOL
45 InitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc)
46 {
47     HPROPSHEETPAGE hPage;
48     PROPSHEETPAGE psp;
49 
50     if (ppsh->nPages < MAX_CPL_PAGES)
51     {
52         ZeroMemory(&psp, sizeof(psp));
53         psp.dwSize = sizeof(psp);
54         psp.dwFlags = PSP_DEFAULT;
55         psp.hInstance = hApplet;
56         psp.pszTemplate = MAKEINTRESOURCE(idDlg);
57         psp.pfnDlgProc = DlgProc;
58 
59         hPage = CreatePropertySheetPage(&psp);
60         if (hPage != NULL)
61         {
62             return PropSheetAddPage(hPage, (LPARAM)ppsh);
63         }
64     }
65 
66     return FALSE;
67 }
68 
69 BOOL CALLBACK
70 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
71 {
72     PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
73     if (ppsh != NULL && ppsh->nPages < MAX_CPL_PAGES)
74     {
75         ppsh->phpage[ppsh->nPages++] = hpage;
76         return TRUE;
77     }
78 
79     return FALSE;
80 }
81 
82 
83 /* Control Panel Callback */
84 LONG CALLBACK
85 CPlApplet(HWND hwndCpl,
86           UINT uMsg,
87           LPARAM lParam1,
88           LPARAM lParam2)
89 {
90     switch(uMsg)
91     {
92         case CPL_INIT:
93             return TRUE;
94 
95         case CPL_GETCOUNT:
96             return NUM_APPLETS;
97 
98         case CPL_INQUIRE:
99         {
100             CPLINFO *CPlInfo = (CPLINFO*)lParam2;
101             UINT uAppIndex = (UINT)lParam1;
102 
103             CPlInfo->lData = lParam1;
104             CPlInfo->idIcon = Applets[uAppIndex].idIcon;
105             CPlInfo->idName = Applets[uAppIndex].idName;
106             CPlInfo->idInfo = Applets[uAppIndex].idDescription;
107             break;
108         }
109 
110         case CPL_DBLCLK:
111         {
112             UINT uAppIndex = (UINT)lParam1;
113             Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
114             break;
115         }
116 
117         case CPL_STARTWPARMSW:
118             return Applets[(UINT)lParam1].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
119     }
120 
121     return FALSE;
122 }
123 
124 
125 BOOL WINAPI
126 DllMain(HINSTANCE hinstDLL,
127         DWORD dwReason,
128         LPVOID lpReserved)
129 {
130     INITCOMMONCONTROLSEX InitControls;
131     UNREFERENCED_PARAMETER(lpReserved);
132 
133     switch(dwReason)
134     {
135         case DLL_PROCESS_ATTACH:
136             InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
137             InitControls.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_BAR_CLASSES;
138             InitCommonControlsEx(&InitControls);
139 
140             hApplet = hinstDLL;
141             break;
142     }
143 
144     return TRUE;
145 }
146