xref: /reactos/dll/cpl/usrmgr/usrmgr.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS User Manager Control Panel
4  * FILE:            dll/cpl/usrmgr/usrmgr.c
5  * PURPOSE:         Main functions
6  *
7  * PROGRAMMERS:     Eric Kohl
8  */
9 
10 #include "usrmgr.h"
11 
12 #define NUM_APPLETS 1
13 
14 static LONG APIENTRY UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
15 
16 HINSTANCE hApplet = 0;
17 
18 /* Applets */
19 APPLET Applets[NUM_APPLETS] =
20 {
21     {
22         IDI_USRMGR_ICON,
23         IDS_CPLNAME,
24         IDS_CPLDESCRIPTION,
25         UsrmgrApplet
26     }
27 };
28 
29 
30 static VOID
31 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
32 {
33     ZeroMemory(psp, sizeof(PROPSHEETPAGE));
34     psp->dwSize = sizeof(PROPSHEETPAGE);
35     psp->dwFlags = PSP_DEFAULT;
36     psp->hInstance = hApplet;
37     psp->pszTemplate = MAKEINTRESOURCE(idDlg);
38     psp->pfnDlgProc = DlgProc;
39 }
40 
41 
42 /* Display Applet */
43 static LONG APIENTRY
44 UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
45 {
46     PROPSHEETPAGE psp[3];
47     PROPSHEETHEADER psh;
48     TCHAR Caption[1024];
49 
50     UNREFERENCED_PARAMETER(lParam);
51     UNREFERENCED_PARAMETER(wParam);
52     UNREFERENCED_PARAMETER(uMsg);
53 
54     LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
55 
56     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
57     psh.dwSize = sizeof(PROPSHEETHEADER);
58     psh.dwFlags =  PSH_PROPSHEETPAGE;
59     psh.hwndParent = hwnd;
60     psh.hInstance = hApplet;
61     psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_USRMGR_ICON));
62     psh.pszCaption = Caption;
63     psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
64     psh.nStartPage = 0;
65     psh.ppsp = psp;
66 
67     InitPropSheetPage(&psp[0], IDD_USERS, (DLGPROC)UsersPageProc);
68     InitPropSheetPage(&psp[1], IDD_GROUPS, (DLGPROC)GroupsPageProc);
69     InitPropSheetPage(&psp[2], IDD_EXTRA, (DLGPROC)ExtraPageProc);
70 
71     return (LONG)(PropertySheet(&psh) != -1);
72 }
73 
74 
75 /* Control Panel Callback */
76 LONG CALLBACK
77 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
78 {
79     int i = (int)lParam1;
80 
81     switch (uMsg)
82     {
83         case CPL_INIT:
84             return TRUE;
85 
86         case CPL_GETCOUNT:
87             return NUM_APPLETS;
88 
89         case CPL_INQUIRE:
90             {
91                 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
92                 CPlInfo->lData = 0;
93                 CPlInfo->idIcon = Applets[i].idIcon;
94                 CPlInfo->idName = Applets[i].idName;
95                 CPlInfo->idInfo = Applets[i].idDescription;
96             }
97             break;
98 
99         case CPL_DBLCLK:
100             Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
101             break;
102     }
103 
104     return FALSE;
105 }
106 
107 
108 BOOL WINAPI
109 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
110 {
111     UNREFERENCED_PARAMETER(lpvReserved);
112 
113     switch (dwReason)
114     {
115         case DLL_PROCESS_ATTACH:
116             hApplet = hinstDLL;
117             break;
118     }
119 
120     return TRUE;
121 }
122