InputDlg.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : G *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/InputDlg.cpp $*
  25. * *
  26. * $Author:: Andre_a $*
  27. * *
  28. * $Modtime:: 5/08/00 1:58p $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // InputDlg.cpp : implementation file
  36. //
  37. #include "InputDlg.h"
  38. #include <assert.h>
  39. static BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  40. /////////////////////////////////////////////////////////////////////////////
  41. // InputDlg dialog
  42. InputDlg::InputDlg (HWND hWndParent)
  43. : m_hWndParent(hWndParent),
  44. m_hWnd(NULL)
  45. {
  46. // Set the strings to default values.
  47. SetCaption("Input Value...");
  48. SetLabel("Please enter a value:");
  49. SetValue(NULL);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // InputDlg Methods
  53. int InputDlg::DoModal (void)
  54. {
  55. // Put up the dialog box.
  56. BOOL result = DialogBoxParam(AppInstance, MAKEINTRESOURCE(IDD),
  57. m_hWndParent, (DLGPROC)_thunk_dialog_proc,
  58. (LPARAM)this);
  59. // Return IDOK if the user accepted the new settings.
  60. return (result == 1) ? IDOK : IDCANCEL;
  61. }
  62. void InputDlg::SetCaption (const char *caption)
  63. {
  64. if (caption)
  65. {
  66. assert(strlen(caption) < sizeof(m_Caption));
  67. strcpy(m_Caption, caption);
  68. }
  69. else
  70. m_Caption[0] = '\0';
  71. }
  72. void InputDlg::SetLabel (const char *label)
  73. {
  74. if (label)
  75. {
  76. assert(strlen(label) < sizeof(m_Label));
  77. strcpy(m_Label, label);
  78. }
  79. else
  80. m_Label[0] = '\0';
  81. }
  82. void InputDlg::SetValue (const char *value)
  83. {
  84. if (value)
  85. {
  86. assert(strlen(value) < sizeof(m_Value));
  87. strcpy(m_Value, value);
  88. }
  89. else
  90. m_Value[0] = '\0';
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // InputDlg DialogProc
  94. BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  95. {
  96. static InputDlg *dialog = NULL;
  97. if (uMsg == WM_INITDIALOG)
  98. {
  99. dialog = (InputDlg*)lParam;
  100. dialog->m_hWnd = hWnd;
  101. }
  102. if (dialog)
  103. return dialog->DialogProc(hWnd, uMsg, wParam, lParam);
  104. else
  105. return 0;
  106. }
  107. BOOL CALLBACK InputDlg::DialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  108. {
  109. int code = HIWORD(wParam);
  110. switch (uMsg)
  111. {
  112. /*******************************************************************
  113. * WM_INITDIALOG
  114. *
  115. * Initialize all of the custom controls for the dialog box
  116. *
  117. *******************************************************************/
  118. case WM_INITDIALOG:
  119. OnInitDialog(wParam, lParam);
  120. return TRUE;
  121. /*******************************************************************
  122. * WM_COMMAND
  123. *
  124. *
  125. *******************************************************************/
  126. case WM_COMMAND:
  127. switch (LOWORD(wParam))
  128. {
  129. case IDOK:
  130. if (!OnOK())
  131. return TRUE;
  132. SetCursor(LoadCursor(NULL, IDC_WAIT));
  133. EndDialog(m_hWnd, 1);
  134. break;
  135. case IDCANCEL:
  136. EndDialog(m_hWnd, 0);
  137. break;
  138. }
  139. return TRUE;
  140. }
  141. return FALSE;
  142. }
  143. /////////////////////////////////////////////////////////////////////////////
  144. // InputDlg message handlers
  145. LRESULT InputDlg::OnInitDialog (WPARAM wParam, LPARAM lParam)
  146. {
  147. // Set the cursor to the normal arrow.
  148. SetCursor(LoadCursor(NULL, IDC_ARROW));
  149. // Set the dialog box caption.
  150. SetWindowText(m_hWnd, m_Caption);
  151. // Set the label text.
  152. HWND hLabel = GetDlgItem(m_hWnd, IDC_LABEL);
  153. assert(hLabel != NULL);
  154. SetWindowText(hLabel, m_Label);
  155. // Set the default value.
  156. HWND hEdit = GetDlgItem(m_hWnd, IDC_VALUE);
  157. assert(hEdit != NULL);
  158. SetWindowText(hEdit, m_Value);
  159. // Select all of the text in the edit box.
  160. SendMessage(hEdit, EM_SETSEL, 0, -1);
  161. return 0;
  162. }
  163. BOOL InputDlg::OnOK (void)
  164. {
  165. // Update our copy of what the user typed.
  166. HWND hEdit = GetDlgItem(m_hWnd, IDC_VALUE);
  167. assert(hEdit != NULL);
  168. GetWindowText(hEdit, m_Value, sizeof(m_Value));
  169. // The dialog can be dismissed.
  170. return TRUE;
  171. }