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