1c2c66affSColin Finck /*
2c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory
3c2c66affSColin Finck * PROJECT: ReactOS User Manager Control Panel
4c2c66affSColin Finck * FILE: dll/cpl/usrmgr/usrmgr.c
5c2c66affSColin Finck * PURPOSE: Main functions
6c2c66affSColin Finck *
7c2c66affSColin Finck * PROGRAMMERS: Eric Kohl
8*8532f187SKatayama Hirofumi MZ * Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
9c2c66affSColin Finck */
10c2c66affSColin Finck
11c2c66affSColin Finck #include "usrmgr.h"
12c2c66affSColin Finck
13c2c66affSColin Finck #define NUM_APPLETS 1
14c2c66affSColin Finck
15c2c66affSColin Finck static LONG APIENTRY UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
16c2c66affSColin Finck
17c2c66affSColin Finck HINSTANCE hApplet = 0;
18c2c66affSColin Finck
GetDlgItemTextAlloc(HWND hwndDlg,INT nDlgItem)19*8532f187SKatayama Hirofumi MZ LPTSTR GetDlgItemTextAlloc(HWND hwndDlg, INT nDlgItem)
20*8532f187SKatayama Hirofumi MZ {
21*8532f187SKatayama Hirofumi MZ INT nLength = GetWindowTextLength(GetDlgItem(hwndDlg, nDlgItem));
22*8532f187SKatayama Hirofumi MZ LPTSTR psz = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
23*8532f187SKatayama Hirofumi MZ if (psz)
24*8532f187SKatayama Hirofumi MZ GetDlgItemText(hwndDlg, nDlgItem, psz, nLength + 1);
25*8532f187SKatayama Hirofumi MZ return psz;
26*8532f187SKatayama Hirofumi MZ }
27*8532f187SKatayama Hirofumi MZ
GetComboBoxLBTextAlloc(HWND hwndDlg,INT nDlgItem,INT nIndex)28*8532f187SKatayama Hirofumi MZ LPTSTR GetComboBoxLBTextAlloc(HWND hwndDlg, INT nDlgItem, INT nIndex)
29*8532f187SKatayama Hirofumi MZ {
30*8532f187SKatayama Hirofumi MZ INT nLength = (INT)SendDlgItemMessage(hwndDlg, nDlgItem, CB_GETLBTEXTLEN, nIndex, 0);
31*8532f187SKatayama Hirofumi MZ LPTSTR psz = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
32*8532f187SKatayama Hirofumi MZ if (psz)
33*8532f187SKatayama Hirofumi MZ SendDlgItemMessage(hwndDlg, nDlgItem, CB_GETLBTEXT, nIndex, (LPARAM)psz);
34*8532f187SKatayama Hirofumi MZ return psz;
35*8532f187SKatayama Hirofumi MZ }
36*8532f187SKatayama Hirofumi MZ
37c2c66affSColin Finck /* Applets */
38c2c66affSColin Finck APPLET Applets[NUM_APPLETS] =
39c2c66affSColin Finck {
40c2c66affSColin Finck {
41c2c66affSColin Finck IDI_USRMGR_ICON,
42c2c66affSColin Finck IDS_CPLNAME,
43c2c66affSColin Finck IDS_CPLDESCRIPTION,
44c2c66affSColin Finck UsrmgrApplet
45c2c66affSColin Finck }
46c2c66affSColin Finck };
47c2c66affSColin Finck
48c2c66affSColin Finck static VOID
InitPropSheetPage(PROPSHEETPAGE * psp,WORD idDlg,DLGPROC DlgProc)49c2c66affSColin Finck InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
50c2c66affSColin Finck {
51c2c66affSColin Finck ZeroMemory(psp, sizeof(PROPSHEETPAGE));
52c2c66affSColin Finck psp->dwSize = sizeof(PROPSHEETPAGE);
53c2c66affSColin Finck psp->dwFlags = PSP_DEFAULT;
54c2c66affSColin Finck psp->hInstance = hApplet;
55c2c66affSColin Finck psp->pszTemplate = MAKEINTRESOURCE(idDlg);
56c2c66affSColin Finck psp->pfnDlgProc = DlgProc;
57c2c66affSColin Finck }
58c2c66affSColin Finck
59bd55105cSKatayama Hirofumi MZ static int CALLBACK
PropSheetProc(HWND hwndDlg,UINT uMsg,LPARAM lParam)60bd55105cSKatayama Hirofumi MZ PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
61bd55105cSKatayama Hirofumi MZ {
62bd55105cSKatayama Hirofumi MZ // NOTE: This callback is needed to set large icon correctly.
63bd55105cSKatayama Hirofumi MZ HICON hIcon;
64bd55105cSKatayama Hirofumi MZ switch (uMsg)
65bd55105cSKatayama Hirofumi MZ {
66bd55105cSKatayama Hirofumi MZ case PSCB_INITIALIZED:
67bd55105cSKatayama Hirofumi MZ {
68bd55105cSKatayama Hirofumi MZ hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_USRMGR_ICON));
69bd55105cSKatayama Hirofumi MZ SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
70bd55105cSKatayama Hirofumi MZ break;
71bd55105cSKatayama Hirofumi MZ }
72bd55105cSKatayama Hirofumi MZ }
73bd55105cSKatayama Hirofumi MZ return 0;
74bd55105cSKatayama Hirofumi MZ }
75c2c66affSColin Finck
76c2c66affSColin Finck /* Display Applet */
77c2c66affSColin Finck static LONG APIENTRY
UsrmgrApplet(HWND hwnd,UINT uMsg,LPARAM wParam,LPARAM lParam)78c2c66affSColin Finck UsrmgrApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
79c2c66affSColin Finck {
804ceea749SJared Smudde PROPSHEETPAGE psp[2];
81c2c66affSColin Finck PROPSHEETHEADER psh;
82c2c66affSColin Finck
83c2c66affSColin Finck UNREFERENCED_PARAMETER(lParam);
84c2c66affSColin Finck UNREFERENCED_PARAMETER(wParam);
85c2c66affSColin Finck UNREFERENCED_PARAMETER(uMsg);
86c2c66affSColin Finck
87c2c66affSColin Finck ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
88c2c66affSColin Finck psh.dwSize = sizeof(PROPSHEETHEADER);
89bd55105cSKatayama Hirofumi MZ psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
90c2c66affSColin Finck psh.hwndParent = hwnd;
91c2c66affSColin Finck psh.hInstance = hApplet;
92bd55105cSKatayama Hirofumi MZ psh.pszIcon = MAKEINTRESOURCEW(IDI_USRMGR_ICON);
930c324e35SThamatip Chitpong psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME);
94c2c66affSColin Finck psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
95c2c66affSColin Finck psh.nStartPage = 0;
96c2c66affSColin Finck psh.ppsp = psp;
97bd55105cSKatayama Hirofumi MZ psh.pfnCallback = PropSheetProc;
98c2c66affSColin Finck
99bcbe0dd8SThomas Faber InitPropSheetPage(&psp[0], IDD_USERS, UsersPageProc);
100bcbe0dd8SThomas Faber InitPropSheetPage(&psp[1], IDD_GROUPS, GroupsPageProc);
1014ceea749SJared Smudde /* InitPropSheetPage(&psp[2], IDD_EXTRA, ExtraPageProc); */
102c2c66affSColin Finck
103c2c66affSColin Finck return (LONG)(PropertySheet(&psh) != -1);
104c2c66affSColin Finck }
105c2c66affSColin Finck
106c2c66affSColin Finck
107c2c66affSColin Finck /* Control Panel Callback */
108c2c66affSColin Finck LONG CALLBACK
CPlApplet(HWND hwndCPl,UINT uMsg,LPARAM lParam1,LPARAM lParam2)109c2c66affSColin Finck CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
110c2c66affSColin Finck {
111e5ebbc8aSKatayama Hirofumi MZ UINT i = (UINT)lParam1;
112c2c66affSColin Finck
113c2c66affSColin Finck switch (uMsg)
114c2c66affSColin Finck {
115c2c66affSColin Finck case CPL_INIT:
116c2c66affSColin Finck return TRUE;
117c2c66affSColin Finck
118c2c66affSColin Finck case CPL_GETCOUNT:
119c2c66affSColin Finck return NUM_APPLETS;
120c2c66affSColin Finck
121c2c66affSColin Finck case CPL_INQUIRE:
122e5ebbc8aSKatayama Hirofumi MZ if (i < NUM_APPLETS)
123c2c66affSColin Finck {
124c2c66affSColin Finck CPLINFO *CPlInfo = (CPLINFO*)lParam2;
125c2c66affSColin Finck CPlInfo->lData = 0;
126c2c66affSColin Finck CPlInfo->idIcon = Applets[i].idIcon;
127c2c66affSColin Finck CPlInfo->idName = Applets[i].idName;
128c2c66affSColin Finck CPlInfo->idInfo = Applets[i].idDescription;
129c2c66affSColin Finck }
130e5ebbc8aSKatayama Hirofumi MZ else
131e5ebbc8aSKatayama Hirofumi MZ {
132e5ebbc8aSKatayama Hirofumi MZ return TRUE;
133e5ebbc8aSKatayama Hirofumi MZ }
134c2c66affSColin Finck break;
135c2c66affSColin Finck
136c2c66affSColin Finck case CPL_DBLCLK:
137e5ebbc8aSKatayama Hirofumi MZ if (i < NUM_APPLETS)
138c2c66affSColin Finck Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
139e5ebbc8aSKatayama Hirofumi MZ else
140e5ebbc8aSKatayama Hirofumi MZ return TRUE;
141c2c66affSColin Finck break;
142c2c66affSColin Finck }
143c2c66affSColin Finck
144c2c66affSColin Finck return FALSE;
145c2c66affSColin Finck }
146c2c66affSColin Finck
147c2c66affSColin Finck
148c2c66affSColin Finck BOOL WINAPI
DllMain(HINSTANCE hinstDLL,DWORD dwReason,LPVOID lpvReserved)149c2c66affSColin Finck DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
150c2c66affSColin Finck {
151c2c66affSColin Finck UNREFERENCED_PARAMETER(lpvReserved);
152c2c66affSColin Finck
153c2c66affSColin Finck switch (dwReason)
154c2c66affSColin Finck {
155c2c66affSColin Finck case DLL_PROCESS_ATTACH:
156c2c66affSColin Finck hApplet = hinstDLL;
157c2c66affSColin Finck break;
158c2c66affSColin Finck }
159c2c66affSColin Finck
160c2c66affSColin Finck return TRUE;
161c2c66affSColin Finck }
162