ExportAllDlg.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. ** Command & Conquer Generals(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/ExportAllDlg.cpp $*
  25. * *
  26. * $Author:: Andre_a $*
  27. * *
  28. * $Modtime:: 10/15/99 4:25p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // ExportAllDlg.cpp : implementation file
  36. //
  37. #include "ExportAllDlg.h"
  38. #include <Max.h>
  39. #include <assert.h>
  40. #include <shlobj.h> // SHBrowseForFolder
  41. static BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  42. /////////////////////////////////////////////////////////////////////////////
  43. // ExportAllDlg dialog
  44. ExportAllDlg::ExportAllDlg (Interface *max_interface)
  45. {
  46. m_Directory[0] = '\0';
  47. m_Recursive = TRUE;
  48. m_hWnd = NULL;
  49. assert(max_interface != NULL);
  50. m_MaxInterface = max_interface;
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // ExportAllDlg Methods
  54. int ExportAllDlg::DoModal (void)
  55. {
  56. // Put up the dialog box.
  57. BOOL result = DialogBoxParam(AppInstance, MAKEINTRESOURCE(IDD_EXPORT_ALL),
  58. m_MaxInterface->GetMAXHWnd(), (DLGPROC)_thunk_dialog_proc,
  59. (LPARAM)this);
  60. // Return IDOK if the user accepted the new settings.
  61. return (result == 1) ? IDOK : IDCANCEL;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // ExportAllDlg DialogProc
  65. BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  66. {
  67. static ExportAllDlg *dialog = NULL;
  68. if (uMsg == WM_INITDIALOG)
  69. {
  70. dialog = (ExportAllDlg*)lParam;
  71. dialog->m_hWnd = hWnd;
  72. }
  73. if (dialog)
  74. return dialog->DialogProc(hWnd, uMsg, wParam, lParam);
  75. else
  76. return 0;
  77. }
  78. BOOL CALLBACK ExportAllDlg::DialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  79. {
  80. int code = HIWORD(wParam);
  81. switch (uMsg)
  82. {
  83. /*******************************************************************
  84. * WM_INITDIALOG
  85. *
  86. * Initialize all of the custom controls for the dialog box
  87. *
  88. *******************************************************************/
  89. case WM_INITDIALOG:
  90. OnInitDialog();
  91. return TRUE;
  92. /*******************************************************************
  93. * WM_COMMAND
  94. *
  95. *
  96. *******************************************************************/
  97. case WM_COMMAND:
  98. switch (LOWORD(wParam))
  99. {
  100. case IDOK:
  101. if (OnOK() == FALSE)
  102. return TRUE;
  103. SetCursor(LoadCursor(NULL, IDC_WAIT));
  104. EndDialog(m_hWnd, 1);
  105. break;
  106. case IDCANCEL:
  107. EndDialog(m_hWnd, 0);
  108. break;
  109. case IDC_BROWSE:
  110. OnBrowse();
  111. return FALSE;
  112. }
  113. return TRUE;
  114. }
  115. return FALSE;
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // ExportAllDlg message handlers
  119. void ExportAllDlg::OnInitDialog (void)
  120. {
  121. CenterWindow(m_hWnd, m_MaxInterface->GetMAXHWnd());
  122. SetCursor(LoadCursor(NULL, IDC_ARROW));
  123. // Set the check box state.
  124. CheckDlgButton(m_hWnd, IDC_RECURSIVE, m_Recursive);
  125. // Set the default directory.
  126. HWND edit = GetDlgItem(m_hWnd, IDC_DIRECTORY);
  127. assert(edit != NULL);
  128. SetWindowText(edit, m_Directory);
  129. }
  130. void ExportAllDlg::OnBrowse()
  131. {
  132. char folder_name[MAX_PATH];
  133. BROWSEINFO bi;
  134. ZeroMemory(&bi, sizeof(bi));
  135. bi.hwndOwner = m_hWnd;
  136. bi.pszDisplayName = folder_name;
  137. bi.lpszTitle = "Select a folder for export...";
  138. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  139. // Browse for a folder.
  140. LPITEMIDLIST il = SHBrowseForFolder(&bi);
  141. if (il)
  142. {
  143. // Get the path of the folder.
  144. if (SHGetPathFromIDList(il, folder_name))
  145. {
  146. HWND edit = GetDlgItem(m_hWnd, IDC_DIRECTORY);
  147. assert(edit != NULL);
  148. SetWindowText(edit, folder_name);
  149. }
  150. else
  151. MessageBox(m_hWnd, "Error getting pathname with SHGetPathFromIDList()",
  152. "Error", MB_OK | MB_ICONSTOP);
  153. }
  154. }
  155. BOOL ExportAllDlg::OnOK (void)
  156. {
  157. // Get the directory chosen by the user. If none is entered,
  158. // freak on the user.
  159. char dir[_MAX_PATH];
  160. HWND edit = GetDlgItem(m_hWnd, IDC_DIRECTORY);
  161. assert(edit != NULL);
  162. if (GetWindowText(edit, dir, sizeof(dir)) == 0)
  163. {
  164. // The edit box is empty, that's not a valid choice.
  165. MessageBox(m_hWnd, "You must choose a directory to export",
  166. "Invalid Directory", MB_OK);
  167. SetFocus(edit);
  168. return FALSE;
  169. }
  170. // TODO: Validate the directory as one that actually exists.
  171. // Store the values from the dialog in our class members.
  172. strcpy(m_Directory, dir);
  173. m_Recursive = (IsDlgButtonChecked(m_hWnd, IDC_RECURSIVE) == BST_CHECKED) ? TRUE : FALSE;
  174. return TRUE;
  175. }