f70ff242d29996a61fedcbf0e62b8808818c2cd4
[reactos.git] / reactos / lib / cpl / cplsample / cplsample.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: cplsample.c,v 1.4 2004/10/11 21:08:04 weiden Exp $
20 *
21 * PROJECT: ReactOS Sample Control Panel
22 * FILE: lib/cpl/cplsample/cplsample.c
23 * PURPOSE: ReactOS Sample Control Panel
24 * PROGRAMMER: Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 05-01-2004 Created
27 */
28 #include <windows.h>
29 #include <stdlib.h>
30 #include "resource.h"
31 #include "cplsample.h"
32
33 #define NUM_APPLETS (1)
34
35 LONG CALLBACK Applet1(VOID);
36 HINSTANCE hApplet = 0;
37
38 /* Applets */
39 APPLET Applets[NUM_APPLETS] =
40 {
41 {IDC_CPLICON_1, IDS_CPLNAME_1, IDS_CPLDESCRIPTION_1, Applet1}
42 };
43
44 static void
45 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
46 {
47 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
48 psp->dwSize = sizeof(PROPSHEETPAGE);
49 psp->dwFlags = PSP_DEFAULT;
50 psp->hInstance = hApplet;
51 psp->u1.pszTemplate = MAKEINTRESOURCE(idDlg);
52 psp->pfnDlgProc = DlgProc;
53 }
54
55 /* Property page dialog callback */
56 INT_PTR CALLBACK
57 Page1Proc(
58 HWND hwndDlg,
59 UINT uMsg,
60 WPARAM wParam,
61 LPARAM lParam
62 )
63 {
64 switch(uMsg)
65 {
66 case WM_INITDIALOG:
67 break;
68 }
69 return FALSE;
70 }
71
72 /* Property page dialog callback */
73 INT_PTR CALLBACK
74 Page2Proc(
75 HWND hwndDlg,
76 UINT uMsg,
77 WPARAM wParam,
78 LPARAM lParam
79 )
80 {
81 switch(uMsg)
82 {
83 case WM_INITDIALOG:
84 break;
85 }
86 return FALSE;
87 }
88
89 /* Property page dialog callback */
90 INT_PTR CALLBACK
91 Page3Proc(
92 HWND hwndDlg,
93 UINT uMsg,
94 WPARAM wParam,
95 LPARAM lParam
96 )
97 {
98 switch(uMsg)
99 {
100 case WM_INITDIALOG:
101 break;
102 }
103 return FALSE;
104 }
105
106 /* Property Sheet Callback */
107 int CALLBACK
108 PropSheetProc(
109 HWND hwndDlg,
110 UINT uMsg,
111 LPARAM lParam
112 )
113 {
114 switch(uMsg)
115 {
116 case PSCB_BUTTONPRESSED:
117 switch(lParam)
118 {
119 case PSBTN_OK: /* OK */
120 break;
121 case PSBTN_CANCEL: /* Cancel */
122 break;
123 case PSBTN_APPLYNOW: /* Apply now */
124 break;
125 case PSBTN_FINISH: /* Close */
126 break;
127 default:
128 return FALSE;
129 }
130 break;
131
132 case PSCB_INITIALIZED:
133 break;
134 }
135 return TRUE;
136 }
137
138 /* First Applet */
139
140 LONG CALLBACK
141 Applet1(VOID)
142 {
143 PROPSHEETPAGE psp[3];
144 PROPSHEETHEADER psh;
145 TCHAR Caption[1024];
146
147 LoadString(hApplet, IDS_CPLNAME_1, Caption, sizeof(Caption) / sizeof(TCHAR));
148
149 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
150 psh.dwSize = sizeof(PROPSHEETHEADER);
151 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_PROPTITLE;
152 psh.hwndParent = NULL;
153 psh.hInstance = hApplet;
154 psh.u1.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON_1));
155 psh.pszCaption = Caption;
156 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
157 psh.u2.nStartPage = 0;
158 psh.u3.ppsp = psp;
159 psh.pfnCallback = PropSheetProc;
160
161 InitPropSheetPage(&psp[0], IDD_PROPPAGE1, Page1Proc);
162 InitPropSheetPage(&psp[1], IDD_PROPPAGE2, Page2Proc);
163 InitPropSheetPage(&psp[2], IDD_PROPPAGE3, Page3Proc);
164
165 return (LONG)(PropertySheet(&psh) != -1);
166 }
167
168 /* Control Panel Callback */
169 LONG CALLBACK
170 CPlApplet(
171 HWND hwndCPl,
172 UINT uMsg,
173 LPARAM lParam1,
174 LPARAM lParam2)
175 {
176 int i = (int)lParam1;
177
178 switch(uMsg)
179 {
180 case CPL_INIT:
181 {
182 return TRUE;
183 }
184 case CPL_GETCOUNT:
185 {
186 return NUM_APPLETS;
187 }
188 case CPL_INQUIRE:
189 {
190 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
191 CPlInfo->lData = 0;
192 CPlInfo->idIcon = Applets[i].idIcon;
193 CPlInfo->idName = Applets[i].idName;
194 CPlInfo->idInfo = Applets[i].idDescription;
195 break;
196 }
197 case CPL_DBLCLK:
198 {
199 Applets[i].AppletProc();
200 break;
201 }
202 }
203 return FALSE;
204 }
205
206
207 BOOL STDCALL
208 DllMain(
209 HINSTANCE hinstDLL,
210 DWORD dwReason,
211 LPVOID lpvReserved)
212 {
213 switch(dwReason)
214 {
215 case DLL_PROCESS_ATTACH:
216 case DLL_THREAD_ATTACH:
217 hApplet = hinstDLL;
218 break;
219 }
220 return TRUE;
221 }
222