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.

112 lines
3.6 KiB

  1. #include <windows.h>
  2. #include "instring.h"
  3. typedef struct _STRING_BUFFER {
  4. ULONG cbBuffer;
  5. LPTSTR lpBuffer;
  6. LPTSTR lpPrompt;
  7. LPTSTR lpTitle;
  8. } STRING_BUFFER, *LPSTRING_BUFFER;
  9. INT_PTR CALLBACK InputStringDlgProc(HWND hDlg, WORD message, WORD wParam, LONG lParam) {
  10. static LPSTRING_BUFFER lpBuffer = NULL;
  11. USHORT cchString;
  12. switch (message) {
  13. case WM_INITDIALOG:
  14. // DialogBoxParam passes in pointer to buffer description.
  15. lpBuffer = (LPSTRING_BUFFER)lParam;
  16. if (lpBuffer->lpPrompt) {
  17. SetDlgItemText(hDlg, IDD_INPUT_STRING_PROMPT, lpBuffer->lpPrompt);
  18. }
  19. if (lpBuffer->lpTitle) {
  20. SetWindowText(hDlg, lpBuffer->lpTitle);
  21. }
  22. SendDlgItemMessage(hDlg,
  23. IDD_INPUT_STRING,
  24. EM_LIMITTEXT,
  25. (WPARAM)(lpBuffer->cbBuffer - 1), // text length, in characters (leave room for null)
  26. 0); // not used; must be zero
  27. return(TRUE);
  28. case WM_COMMAND:
  29. switch (wParam) {
  30. case IDOK:
  31. // Get number of characters.
  32. cchString = (WORD)SendDlgItemMessage(hDlg,
  33. IDD_INPUT_STRING,
  34. EM_LINELENGTH,
  35. (WPARAM) 0,
  36. (LPARAM) 0);
  37. if (cchString == 0) {
  38. *(lpBuffer->lpBuffer) = '\0';
  39. EndDialog(hDlg, TRUE);
  40. lpBuffer->cbBuffer = 0;
  41. return FALSE;
  42. }
  43. // Put the number of characters into first word
  44. // of buffer.
  45. *((USHORT*)lpBuffer->lpBuffer) = cchString;
  46. lpBuffer->cbBuffer = cchString;
  47. // Get the characters.
  48. SendDlgItemMessage(hDlg,
  49. IDD_INPUT_STRING,
  50. EM_GETLINE,
  51. (WPARAM)0, // line 0
  52. (LPARAM)lpBuffer->lpBuffer);
  53. // Null-terminate the string.
  54. lpBuffer->lpBuffer[cchString] = 0;
  55. lpBuffer = NULL; // prevent reuse of buffer
  56. EndDialog(hDlg, 0);
  57. return(TRUE);
  58. }
  59. break;
  60. default:
  61. return(FALSE);
  62. }
  63. return(TRUE);
  64. }
  65. /***************************************************************************
  66. Name : InputString
  67. Purpose : Brings up a dialog requesting string input
  68. Parameters: hInstance = hInstance of app
  69. hwnd = hwnd of parent window
  70. lpszTitle = Dialog box title
  71. lpszPrompt = Text in dialog box
  72. lpBuffer = buffer to fill
  73. cchBuffer = size of buffer
  74. Returns : return ULONG number of characters entered (not including terminating
  75. NULL)
  76. Comment :
  77. ***************************************************************************/
  78. ULONG InputString(HINSTANCE hInstance, HWND hwnd, const LPTSTR lpszTitle,
  79. const LPTSTR lpszPrompt, LPTSTR lpBuffer, ULONG cchBuffer) {
  80. STRING_BUFFER StringBuffer;
  81. StringBuffer.lpPrompt = lpszPrompt;
  82. StringBuffer.lpTitle = lpszTitle;
  83. StringBuffer.cbBuffer = cchBuffer;
  84. StringBuffer.lpBuffer = lpBuffer;
  85. DialogBoxParam(hInstance, (LPCTSTR)"InputString", hwnd, InputStringDlgProc,
  86. (LPARAM)&StringBuffer);
  87. return(StringBuffer.cbBuffer);
  88. }