Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
10 KiB

  1. /****************************************************************************
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name: cplsimpledialogs.cpp
  4. Author: toddb - 10/06/98
  5. ****************************************************************************/
  6. #include "cplPreComp.h"
  7. #include "cplSimpleDialogs.h"
  8. // ****************************************************
  9. //
  10. // CEditDialog
  11. //
  12. // ****************************************************
  13. CEditDialog::CEditDialog()
  14. {
  15. m_psz = NULL;
  16. }
  17. CEditDialog::~CEditDialog()
  18. {
  19. if ( m_psz )
  20. {
  21. delete m_psz;
  22. }
  23. }
  24. INT_PTR CEditDialog::DoModal(HWND hwndParent, int iTitle, int iText, int iDesc, DWORD dwFlags)
  25. {
  26. m_iTitle = iTitle;
  27. m_iText = iText;
  28. m_iDesc = iDesc;
  29. m_dwFlags = dwFlags;
  30. return DialogBoxParam(GetUIInstance(),
  31. MAKEINTRESOURCE(IDD_EDITDIALOG),
  32. hwndParent,
  33. CEditDialog::DialogProc,
  34. (LPARAM)this);
  35. }
  36. LPTSTR CEditDialog::GetString()
  37. {
  38. return m_psz;
  39. }
  40. INT_PTR CALLBACK CEditDialog::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  41. {
  42. CEditDialog * ped = (CEditDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  43. switch (uMsg)
  44. {
  45. case WM_INITDIALOG:
  46. ped = (CEditDialog *)lParam;
  47. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  48. return ped->OnInitDialog(hwnd);
  49. case WM_COMMAND:
  50. switch ( LOWORD(wParam) )
  51. {
  52. case IDOK:
  53. ped->OnOK(hwnd);
  54. // fall through
  55. case IDCANCEL:
  56. HideToolTip();
  57. EndDialog(hwnd, LOWORD(wParam));
  58. break;
  59. }
  60. break;
  61. #define aIDs ((ped->m_iTitle == IDS_SPECIFYDIGITS)?a117HelpIDs:a116HelpIDs)
  62. case WM_HELP:
  63. // Process clicks on controls after Context Help mode selected
  64. TapiCplWinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (DWORD_PTR)(LPTSTR) aIDs);
  65. break;
  66. case WM_CONTEXTMENU:
  67. // Process right-clicks on controls
  68. TapiCplWinHelp ((HWND) wParam, gszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID) aIDs);
  69. break;
  70. #undef aIDs
  71. }
  72. return 0;
  73. }
  74. BOOL CEditDialog::OnInitDialog(HWND hwnd)
  75. {
  76. TCHAR szText[512];
  77. LoadString(GetUIInstance(), m_iTitle, szText, ARRAYSIZE(szText));
  78. SetWindowText(hwnd, szText);
  79. LoadString(GetUIInstance(), m_iText, szText, ARRAYSIZE(szText));
  80. SetWindowText(GetDlgItem(hwnd,IDC_TEXT), szText);
  81. LoadString(GetUIInstance(), m_iDesc, szText, ARRAYSIZE(szText));
  82. SetWindowText(GetDlgItem(hwnd,IDC_DESCRIPTIONTEXT), szText);
  83. HWND hwndEdit = GetDlgItem(hwnd,IDC_EDIT);
  84. SendMessage(hwndEdit, EM_SETLIMITTEXT, CPL_SETTEXTLIMIT, 0);
  85. SetFocus(hwndEdit);
  86. LimitInput(hwndEdit,m_dwFlags);
  87. return 0;
  88. }
  89. void CEditDialog::OnOK(HWND hwnd)
  90. {
  91. DWORD dwStart;
  92. DWORD dwEnd;
  93. HWND hwndEdit = GetDlgItem(hwnd,IDC_EDIT);
  94. SendMessage(hwndEdit,EM_SETSEL,0,-1);
  95. SendMessage(hwndEdit,EM_GETSEL,(WPARAM)&dwStart,(LPARAM)&dwEnd);
  96. dwEnd++; // add room for a NULL terminator
  97. m_psz = new TCHAR[dwEnd]; // allocate the buffer
  98. if (NULL != m_psz)
  99. {
  100. GetWindowText(hwndEdit,m_psz,dwEnd); // and read in the string
  101. }
  102. }
  103. // ****************************************************
  104. //
  105. // CWaitForDialog
  106. //
  107. // ****************************************************
  108. CWaitForDialog::CWaitForDialog()
  109. {
  110. m_iRes = -1;
  111. }
  112. CWaitForDialog::~CWaitForDialog()
  113. {
  114. }
  115. INT_PTR CWaitForDialog::DoModal(HWND hwndParent)
  116. {
  117. return DialogBoxParam(GetUIInstance(),
  118. MAKEINTRESOURCE(IDD_WAITFORDIALOG),
  119. hwndParent,
  120. CWaitForDialog::DialogProc,
  121. (LPARAM)this);
  122. }
  123. int CWaitForDialog::GetWaitType()
  124. {
  125. return m_iRes;
  126. }
  127. INT_PTR CALLBACK CWaitForDialog::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  128. {
  129. CWaitForDialog * pwd = (CWaitForDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  130. switch (uMsg)
  131. {
  132. case WM_INITDIALOG:
  133. pwd = (CWaitForDialog *)lParam;
  134. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  135. return pwd->OnInitDialog(hwnd);
  136. case WM_COMMAND:
  137. switch ( LOWORD(wParam) )
  138. {
  139. case IDC_WAITFORDIALTONE:
  140. case IDC_WAITFORVOICE:
  141. EnableWindow(GetDlgItem(hwnd, IDC_TIME), FALSE);
  142. break;
  143. case IDC_WAITFORTIME:
  144. EnableWindow(GetDlgItem(hwnd, IDC_TIME), TRUE);
  145. break;
  146. case IDOK:
  147. pwd->OnOK(hwnd);
  148. // fall through
  149. case IDCANCEL:
  150. EndDialog(hwnd, LOWORD(wParam));
  151. break;
  152. }
  153. break;
  154. case WM_HELP:
  155. // Process clicks on controls after Context Help mode selected
  156. TapiCplWinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (DWORD_PTR)(LPTSTR) a111HelpIDs);
  157. break;
  158. case WM_CONTEXTMENU:
  159. // Process right-clicks on controls
  160. TapiCplWinHelp ((HWND) wParam, gszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID) a111HelpIDs);
  161. break;
  162. }
  163. return 0;
  164. }
  165. BOOL CWaitForDialog::OnInitDialog(HWND hwndDlg)
  166. {
  167. HWND hwnd;
  168. SendMessage(GetDlgItem(hwndDlg,IDC_WAITFORDIALTONE),BM_SETCHECK,BST_CHECKED,0);
  169. hwnd = GetDlgItem(hwndDlg, IDC_TIME);
  170. SetDlgItemInt(hwndDlg, IDC_TIME, 2, FALSE);
  171. SendMessage(hwnd, EM_SETLIMITTEXT, 2, 0);
  172. EnableWindow(hwnd, FALSE);
  173. LimitInput(hwnd, LIF_ALLOWNUMBER);
  174. hwnd = GetDlgItem(hwndDlg, IDC_TIMESPIN);
  175. SendMessage(hwnd, UDM_SETRANGE32, 2, 98);
  176. SendMessage(hwnd, UDM_SETPOS, 0, MAKELONG(2, 0) );
  177. UDACCEL accel;
  178. accel.nSec = 0;
  179. accel.nInc = 2;
  180. SendMessage(hwnd, UDM_SETACCEL, 1, (LPARAM)&accel );
  181. return 0;
  182. }
  183. void CWaitForDialog::OnOK(HWND hwnd)
  184. {
  185. if ( BST_CHECKED == SendMessage(GetDlgItem(hwnd,IDC_WAITFORDIALTONE),BM_GETCHECK,0,0) )
  186. {
  187. m_iRes = 0;
  188. }
  189. else if ( BST_CHECKED == SendMessage(GetDlgItem(hwnd,IDC_WAITFORVOICE),BM_GETCHECK,0,0) )
  190. {
  191. m_iRes = 1;
  192. }
  193. else
  194. {
  195. m_iRes = GetDlgItemInt(hwnd, IDC_TIME, NULL, FALSE);
  196. if ( m_iRes < 2 )
  197. {
  198. m_iRes = 2;
  199. }
  200. }
  201. }
  202. // ****************************************************
  203. //
  204. // CDestNumDialog
  205. //
  206. // ****************************************************
  207. CDestNumDialog::CDestNumDialog(BOOL bDialCountryCode, BOOL bDialAreaCode)
  208. {
  209. m_wsz[0] = NULL;
  210. m_bDialCountryCode = bDialCountryCode;
  211. m_bDialAreaCode = bDialAreaCode;
  212. }
  213. CDestNumDialog::~CDestNumDialog()
  214. {
  215. }
  216. INT_PTR CDestNumDialog::DoModal(HWND hwndParent)
  217. {
  218. return DialogBoxParam(GetUIInstance(),
  219. MAKEINTRESOURCE(IDD_DESTNUMDIALOG),
  220. hwndParent,
  221. CDestNumDialog::DialogProc,
  222. (LPARAM)this);
  223. }
  224. PWSTR CDestNumDialog::GetResult()
  225. {
  226. return m_wsz;
  227. }
  228. INT_PTR CALLBACK CDestNumDialog::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  229. {
  230. CDestNumDialog * pwd = (CDestNumDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  231. switch (uMsg)
  232. {
  233. case WM_INITDIALOG:
  234. pwd = (CDestNumDialog *)lParam;
  235. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  236. return pwd->OnInitDialog(hwnd);
  237. case WM_COMMAND:
  238. switch ( LOWORD(wParam) )
  239. {
  240. case IDOK:
  241. pwd->OnOK(hwnd);
  242. // fall through
  243. case IDCANCEL:
  244. EndDialog(hwnd, LOWORD(wParam));
  245. break;
  246. }
  247. break;
  248. case WM_HELP:
  249. // Process clicks on controls after Context Help mode selected
  250. TapiCplWinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (DWORD_PTR)(LPTSTR) a112HelpIDs);
  251. break;
  252. case WM_CONTEXTMENU:
  253. // Process right-clicks on controls
  254. TapiCplWinHelp ((HWND) wParam, gszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID) a112HelpIDs);
  255. break;
  256. }
  257. return 0;
  258. }
  259. BOOL CDestNumDialog::OnInitDialog(HWND hwnd)
  260. {
  261. SendMessage(GetDlgItem(hwnd,IDC_AREACODE),BM_SETCHECK,m_bDialAreaCode ? BST_CHECKED : BST_UNCHECKED,0);
  262. SendMessage(GetDlgItem(hwnd,IDC_COUNTRYCODE),BM_SETCHECK,m_bDialCountryCode ? BST_CHECKED : BST_UNCHECKED,0);
  263. SendMessage(GetDlgItem(hwnd,IDC_LOCALNUMBER),BM_SETCHECK,BST_CHECKED,0);
  264. return 0;
  265. }
  266. void CDestNumDialog::OnOK(HWND hwnd)
  267. {
  268. int i = 0;
  269. if ( BST_CHECKED == SendMessage(GetDlgItem(hwnd,IDC_COUNTRYCODE),BM_GETCHECK,0,0) )
  270. {
  271. m_wsz[i++] = L'E';
  272. }
  273. if ( BST_CHECKED == SendMessage(GetDlgItem(hwnd,IDC_AREACODE),BM_GETCHECK,0,0) )
  274. {
  275. m_wsz[i++] = L'F';
  276. }
  277. if ( BST_CHECKED == SendMessage(GetDlgItem(hwnd,IDC_LOCALNUMBER),BM_GETCHECK,0,0) )
  278. {
  279. m_wsz[i++] = L'G';
  280. }
  281. m_wsz[i] = NULL;
  282. }
  283. void ShowErrorMessage(HWND hwnd, int iErr)
  284. {
  285. TCHAR szCaption[128];
  286. TCHAR szText[1024];
  287. LoadString(GetUIInstance(), IDS_ERRORCAPTION, szCaption, ARRAYSIZE(szCaption));
  288. LoadString(GetUIInstance(), iErr, szText, ARRAYSIZE(szText));
  289. MessageBeep(MB_ICONEXCLAMATION);
  290. MessageBox(hwnd, szText, szCaption, MB_OK | MB_ICONEXCLAMATION);
  291. SetFocus(hwnd);
  292. }
  293. BOOL WinHelpEnabled()
  294. {
  295. DWORD cb;
  296. TCHAR szName[MAX_PATH];
  297. BOOL fWinHelpEnabled = FALSE;
  298. HDESK hDesk;
  299. //
  300. // Get the name of the desktop. Normally returns default or Winlogon or system or WinNT
  301. // The context sensitive help needs to be disabled in winlogon
  302. //
  303. szName[0] = 0;
  304. hDesk = GetThreadDesktop(GetCurrentThreadId());
  305. if (hDesk)
  306. {
  307. if (GetUserObjectInformation(hDesk, UOI_NAME, szName, sizeof(szName), &cb))
  308. {
  309. if (_tcscmp(TEXT("Winlogon"), szName) != 0)
  310. {
  311. // This is not winlogon; we can enable context sensitive help
  312. fWinHelpEnabled = TRUE;
  313. }
  314. }
  315. }
  316. return (fWinHelpEnabled);
  317. }
  318. BOOL TapiCplWinHelp(HWND hWndMain, LPCTSTR lpszHelp, UINT uCommand, DWORD_PTR dwData)
  319. {
  320. if (WinHelpEnabled())
  321. {
  322. return WinHelp(hWndMain, lpszHelp, uCommand, dwData);
  323. }
  324. return TRUE;
  325. }