2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/netid/netid.c
5 * PURPOSE: Network ID Page
6 * COPYRIGHT: Thomas Weidenmueller <w3seek@reactos.org>
7 * Dmitry Chapyshev <dmitry@reactos.org>
11 #define WIN32_NO_STATUS
22 static INT_PTR CALLBACK
23 NetIDPageProc(IN HWND hwndDlg
,
28 static HINSTANCE hDllInstance
;
33 DNSSuffixPropDlgProc(HWND hDlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
39 switch (LOWORD(wParam
))
43 EndDialog(hDlg
, LOWORD(wParam
));
54 SetRadioBtnState(HWND hDlg
, BOOL IsDomain
)
56 SendDlgItemMessage(hDlg
, 1008, BM_SETCHECK
, (WPARAM
)IsDomain
, 0);
57 SendDlgItemMessage(hDlg
, 1004, BM_SETCHECK
, (WPARAM
)!IsDomain
, 0);
58 EnableWindow(GetDlgItem(hDlg
, 116), IsDomain
);
59 EnableWindow(GetDlgItem(hDlg
, 1007), !IsDomain
);
63 DisableControls(HWND hDlg
)
65 EnableWindow(GetDlgItem(hDlg
, 1008), FALSE
);
66 EnableWindow(GetDlgItem(hDlg
, 1004), FALSE
);
67 EnableWindow(GetDlgItem(hDlg
, 116), FALSE
);
68 EnableWindow(GetDlgItem(hDlg
, 1007), FALSE
);
73 IsValidComputerName(LPCWSTR s
)
77 for (i
= 0; i
<= wcslen(s
); i
++)
79 if (s
[i
] == L
'!' || s
[i
] == L
'@' || s
[i
] == L
'#' || s
[i
] == L
'$'
80 || s
[i
] == L
'^' || s
[i
] == L
'&' || s
[i
] == L
'\\' || s
[i
] == L
'|'
81 || s
[i
] == L
')' || s
[i
] == L
'(' || s
[i
] == L
'{' || s
[i
] == L
'"'
82 || s
[i
] == L
'}' || s
[i
] == L
'~' || s
[i
] == L
'/' || s
[i
] == L
'\''
83 || s
[i
] == L
'=' || s
[i
] == L
':' || s
[i
] == L
';' || s
[i
] == L
'+'
84 || s
[i
] == L
'<' || s
[i
] == L
'>' || s
[i
] == L
'?' || s
[i
] == L
'['
85 || s
[i
] == L
']' || s
[i
] == L
'`' || s
[i
] == L
'%' || s
[i
] == L
'_'
95 NetworkPropDlgProc(HWND hDlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
101 LPWKSTA_INFO_101 wki
= NULL
;
102 DWORD Size
= MAX_COMPUTERNAME_LENGTH
+ 1;
103 TCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
104 TCHAR MsgText
[MAX_PATH
* 2];
106 NETSETUP_JOIN_STATUS JoinStatus
;
108 if (LoadString(hDllInstance
, 25, MsgText
, sizeof(MsgText
) / sizeof(TCHAR
)))
109 SetDlgItemText(hDlg
, 1017, MsgText
);
111 SendMessage(GetDlgItem(hDlg
, 1002), EM_SETLIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
113 if (GetComputerName(ComputerName
, &Size
))
115 SetDlgItemText(hDlg
, 1002, ComputerName
);
116 SetDlgItemText(hDlg
, 1001, ComputerName
);
119 if (NetGetJoinInformation(NULL
, &JoinName
, &JoinStatus
) != NERR_Success
)
121 SetRadioBtnState(hDlg
, FALSE
);
123 if (NetWkstaGetInfo(NULL
,
125 (LPBYTE
*)&wki
) == NERR_Success
)
129 wki
->wki101_langroup
);
131 else DisableControls(hDlg
);
133 if (wki
) NetApiBufferFree(wki
);
139 case NetSetupDomainName
:
140 SetDlgItemText(hDlg
, 116, JoinName
);
141 SetRadioBtnState(hDlg
, TRUE
);
144 case NetSetupWorkgroupName
:
145 SetDlgItemText(hDlg
, 1007, JoinName
);
146 SetRadioBtnState(hDlg
, FALSE
);
149 case NetSetupUnjoined
:
152 case NetSetupUnknownStatus
:
155 SetRadioBtnState(hDlg
, FALSE
);
157 if (NetWkstaGetInfo(NULL
,
159 (LPBYTE
*)&wki
) == NERR_Success
)
163 wki
->wki101_langroup
);
165 else DisableControls(hDlg
);
167 if (wki
) NetApiBufferFree(wki
);
172 if (JoinName
) NetApiBufferFree(JoinName
);
179 switch (LOWORD(wParam
))
182 if (HIWORD(wParam
) == EN_CHANGE
)
184 TCHAR szText
[MAX_COMPUTERNAME_LENGTH
+ 1];
186 GetWindowText(GetDlgItem(hDlg
, 1002), szText
, MAX_COMPUTERNAME_LENGTH
+ 1);
187 SetDlgItemText(hDlg
, 1001, szText
);
191 case 1008: /* Domain radio button */
192 case 1004: /* Workgroup radio button */
193 if (SendDlgItemMessage(hDlg
, 1008, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
194 SetRadioBtnState(hDlg
, TRUE
);
196 SetRadioBtnState(hDlg
, FALSE
);
200 DialogBox(hDllInstance
,
201 MAKEINTRESOURCE(IDD_PROPPAGEDNSANDNETBIOS
),
203 DNSSuffixPropDlgProc
);
208 DWORD Size
= MAX_COMPUTERNAME_LENGTH
+ 1;
209 TCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
210 TCHAR NewComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
212 if (GetComputerName(ComputerName
, &Size
))
214 if (GetWindowText(GetDlgItem(hDlg
, 1002),
216 (MAX_COMPUTERNAME_LENGTH
+ 1)))
218 if (_tcscmp(ComputerName
, NewComputerName
) != 0)
220 if (!IsValidComputerName(NewComputerName
))
222 TCHAR szText
[MAX_PATH
], szMsgText
[MAX_PATH
];
224 LoadString(hDllInstance
, 1030, szText
, sizeof(szText
) / sizeof(TCHAR
));
226 swprintf(szMsgText
, szText
, NewComputerName
);
227 MessageBox(hDlg
, szMsgText
, NULL
, MB_OK
| MB_ICONERROR
);
228 SetFocus(GetDlgItem(hDlg
, 1002));
231 else if (!SetComputerName(NewComputerName
))
233 TCHAR szMsgText
[MAX_PATH
];
235 LoadString(hDllInstance
, 4001, szMsgText
, sizeof(szMsgText
) / sizeof(TCHAR
));
237 MessageBox(hDlg
, szMsgText
, NULL
, MB_OK
| MB_ICONERROR
);
241 TCHAR szMsgTitle
[MAX_PATH
], szMsgText
[MAX_PATH
];
243 LoadString(hDllInstance
, 4000, szMsgTitle
, sizeof(szMsgTitle
) / sizeof(TCHAR
));
244 LoadString(hDllInstance
, 24, szMsgText
, sizeof(szMsgText
) / sizeof(TCHAR
));
246 MessageBox(hDlg
, szMsgText
, szMsgTitle
, MB_OK
| MB_ICONINFORMATION
);
248 NetIDPageProc(GetParent(hDlg
), WM_INITDIALOG
, 0, 0);
254 EndDialog(hDlg
, LOWORD(wParam
));
259 EndDialog(hDlg
, LOWORD(wParam
));
269 static INT_PTR CALLBACK
270 NetIDPageProc(IN HWND hwndDlg
,
277 UNREFERENCED_PARAMETER(lParam
);
283 /* Display computer name */
284 LPWKSTA_INFO_101 wki
= NULL
;
285 DWORD Size
= MAX_COMPUTERNAME_LENGTH
+ 1;
286 TCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
287 if (GetComputerName(ComputerName
,&Size
))
289 SetDlgItemText(hwndDlg
,
293 if (NetWkstaGetInfo(NULL
,
295 (LPBYTE
*)&wki
) == NERR_Success
)
297 SetDlgItemText(hwndDlg
,
298 IDC_WORKGROUPDOMAIN_NAME
,
299 wki
->wki101_langroup
);
302 if (wki
) NetApiBufferFree(wki
);
309 switch (LOWORD(wParam
))
311 case IDC_NETWORK_PROPERTY
:
312 DialogBox(hDllInstance
,
313 MAKEINTRESOURCE(IDD_PROPPAGECOMPNAMECHENGE
),
324 HPROPSHEETPAGE WINAPI
325 CreateNetIDPropertyPage(VOID
)
327 PROPSHEETPAGE psp
= {0};
329 psp
.dwSize
= sizeof(psp
);
330 psp
.dwFlags
= PSP_DEFAULT
;
331 psp
.hInstance
= hDllInstance
;
332 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROPPAGECOMPUTER
);
333 psp
.pfnDlgProc
= NetIDPageProc
;
335 return CreatePropertySheetPage(&psp
);
339 DllMain(IN HINSTANCE hinstDLL
,
341 IN LPVOID lpvReserved
)
345 case DLL_PROCESS_ATTACH
:
346 hDllInstance
= hinstDLL
;
347 DisableThreadLibraryCalls(hinstDLL
);