[CPL] Properly set display icons of control panel applets (#1129)
[reactos.git] / dll / cpl / usrmgr / usrmgr.c
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 static int CALLBACK
42 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
43 {
44 // NOTE: This callback is needed to set large icon correctly.
45 HICON hIcon;
46 switch (uMsg)
47 {
48 case PSCB_INITIALIZED:
49 {
50 hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_USRMGR_ICON));
51 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
52 break;
53 }
54 }
55 return 0;
56 }
57
58 /* Display Applet */
59 static LONG APIENTRY
60 UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
61 {
62 PROPSHEETPAGE psp[2];
63 PROPSHEETHEADER psh;
64 TCHAR Caption[1024];
65
66 UNREFERENCED_PARAMETER(lParam);
67 UNREFERENCED_PARAMETER(wParam);
68 UNREFERENCED_PARAMETER(uMsg);
69
70 LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
71
72 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
73 psh.dwSize = sizeof(PROPSHEETHEADER);
74 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
75 psh.hwndParent = hwnd;
76 psh.hInstance = hApplet;
77 psh.pszIcon = MAKEINTRESOURCEW(IDI_USRMGR_ICON);
78 psh.pszCaption = Caption;
79 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
80 psh.nStartPage = 0;
81 psh.ppsp = psp;
82 psh.pfnCallback = PropSheetProc;
83
84 InitPropSheetPage(&psp[0], IDD_USERS, UsersPageProc);
85 InitPropSheetPage(&psp[1], IDD_GROUPS, GroupsPageProc);
86 /* InitPropSheetPage(&psp[2], IDD_EXTRA, ExtraPageProc); */
87
88 return (LONG)(PropertySheet(&psh) != -1);
89 }
90
91
92 /* Control Panel Callback */
93 LONG CALLBACK
94 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
95 {
96 int i = (int)lParam1;
97
98 switch (uMsg)
99 {
100 case CPL_INIT:
101 return TRUE;
102
103 case CPL_GETCOUNT:
104 return NUM_APPLETS;
105
106 case CPL_INQUIRE:
107 {
108 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
109 CPlInfo->lData = 0;
110 CPlInfo->idIcon = Applets[i].idIcon;
111 CPlInfo->idName = Applets[i].idName;
112 CPlInfo->idInfo = Applets[i].idDescription;
113 }
114 break;
115
116 case CPL_DBLCLK:
117 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
118 break;
119 }
120
121 return FALSE;
122 }
123
124
125 BOOL WINAPI
126 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
127 {
128 UNREFERENCED_PARAMETER(lpvReserved);
129
130 switch (dwReason)
131 {
132 case DLL_PROCESS_ATTACH:
133 hApplet = hinstDLL;
134 break;
135 }
136
137 return TRUE;
138 }