InputBox.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // InputBox.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "FinalSun.h"
  20. #include "InputBox.h"
  21. #include "functions.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /*
  28. InputBox();
  29. Shows a inputbox with specified caption and text.
  30. Returns the user input. If the user cancels, the user input is "".
  31. */
  32. CString InputBox(const char* Sentence, const char* Caption)
  33. {
  34. CInputBox inp;
  35. inp.SetCaption(Caption);
  36. inp.SetSentence(Sentence);
  37. char* res=(char*) inp.DoModal();
  38. CString cstr=res;
  39. return cstr;
  40. }
  41. CInputBox::CInputBox(CWnd* pParent /*=NULL*/)
  42. : CDialog(CInputBox::IDD, pParent)
  43. {
  44. //{{AFX_DATA_INIT(CInputBox)
  45. //}}AFX_DATA_INIT
  46. }
  47. void CInputBox::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CInputBox)
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CInputBox, CDialog)
  54. //{{AFX_MSG_MAP(CInputBox)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. void CInputBox::OnOK()
  58. {
  59. CString text;
  60. GetDlgItem(IDC_VAL)->GetWindowText(text);
  61. if(text.GetLength()==0){EndDialog(NULL);};
  62. char* str;
  63. str=new(char[text.GetLength()]);
  64. strcpy(str, (LPCTSTR)text);
  65. EndDialog((int)str);
  66. }
  67. void CInputBox::OnCancel()
  68. {
  69. EndDialog(NULL);
  70. }
  71. void CInputBox::SetCaption(CString Caption)
  72. {
  73. m_Caption=Caption;
  74. }
  75. void CInputBox::SetSentence(CString Sentence)
  76. {
  77. m_Text=Sentence;
  78. }
  79. BOOL CInputBox::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. SetWindowText(m_Caption);
  83. SetDlgItemText(IDC_SENTENCE, m_Text);
  84. SetDlgItemText(IDOK, GetLanguageStringACP("OK"));
  85. SetDlgItemText(IDCANCEL, GetLanguageStringACP("Cancel"));
  86. GetDlgItem(IDC_VAL)->SetFocus();
  87. return FALSE;
  88. }