logdlg.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. /* $Header: /Commando/Code/Tools/max2w3d/logdlg.cpp 5 11/07/00 5:40p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando Tools - W3D export *
  24. * *
  25. * $Archive:: /Commando/Code/Tools/max2w3d/logdlg.cpp $*
  26. * *
  27. * $Author:: Greg_h $*
  28. * *
  29. * $Modtime:: 11/07/00 4:24p $*
  30. * *
  31. * $Revision:: 5 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "logdlg.h"
  37. #include "resource.h"
  38. #include "dllmain.h"
  39. #include "w3dexp.h"
  40. #include "util.h"
  41. #include "rawfile.h"
  42. #include "units.h"
  43. /*
  44. ** Static functions
  45. */
  46. static BOOL CALLBACK _logdata_dialog_proc(HWND Hwnd,UINT message,WPARAM wParam,LPARAM lParam);
  47. static DWORD WINAPI _logdata_thread_function(LPVOID log_obj_ptr);
  48. /***********************************************************************************************
  49. * LogDataDialogClass::LogDataDialogClass -- constructor for the options dialog object *
  50. * *
  51. * INPUT: *
  52. * *
  53. * OUTPUT: *
  54. * *
  55. * WARNINGS: *
  56. * *
  57. * HISTORY: *
  58. * 02/09/2000 JGA : Created. *
  59. *=============================================================================================*/
  60. LogDataDialogClass::LogDataDialogClass(HWND parent):
  61. Hwnd(NULL),
  62. ParentHwnd(parent),
  63. buffer_index(0),
  64. last_buffer_index(0),
  65. status(0)
  66. {
  67. ThreadHandle = CreateThread(NULL, 0, _logdata_thread_function, (LPVOID)this, 0, &ThreadID);
  68. if (ThreadHandle) {
  69. while (status == 0) {
  70. // sync, wait for init
  71. }
  72. }
  73. }
  74. LogDataDialogClass::~LogDataDialogClass(void)
  75. {
  76. status = 3;
  77. if (::IsWindow(Hwnd)) {
  78. SendMessage( Hwnd, WM_CLOSE, 0, 0 );
  79. }
  80. }
  81. /***********************************************************************************************
  82. * LogDataDialogClass::printf -- handles doing printfs into the current log window *
  83. * *
  84. * INPUT: *
  85. * *
  86. * OUTPUT: *
  87. * *
  88. * WARNINGS: *
  89. * *
  90. * HISTORY: *
  91. * 02/11/2000 JGA : Created. *
  92. *=============================================================================================*/
  93. void LogDataDialogClass::printf(char *text, ...)
  94. {
  95. va_list arguments;
  96. va_start(arguments, text);
  97. } // printf
  98. void LogDataDialogClass::printf(char * text, const va_list & args)
  99. {
  100. static char string_buffer[256];
  101. vsprintf(string_buffer, text, args);
  102. HWND ctrlHwnd = GetDlgItem(Hwnd, IDC_ANIM_LOG_RICHEDIT);
  103. SendMessage(ctrlHwnd, EM_SETSEL, -1, -1 );
  104. SendMessage(ctrlHwnd, EM_REPLACESEL, FALSE, (long)string_buffer);
  105. last_buffer_index = buffer_index;
  106. buffer_index+=strlen(string_buffer);
  107. //int min,max,pos;
  108. //GetScrollRange(ctrlHwnd, SB_VERT, &min, &max);
  109. //pos = GetScrollPos(ctrlHwnd, SB_VERT);
  110. //if (pos == max) {
  111. SendMessage(GetDlgItem(Hwnd,IDC_ANIM_LOG_RICHEDIT), EM_SCROLLCARET, 0, 0);
  112. //}
  113. }
  114. /***********************************************************************************************
  115. * LogDataDialogClass::rprintf -- replace last printf, with this new printf *
  116. * *
  117. * INPUT: *
  118. * *
  119. * OUTPUT: *
  120. * *
  121. * WARNINGS: *
  122. * *
  123. * HISTORY: *
  124. * 02/14/2000 JGA : Created. *
  125. *=============================================================================================*/
  126. void LogDataDialogClass::rprintf(char *text, ...)
  127. {
  128. va_list arguments;
  129. va_start(arguments, text);
  130. rprintf(text,arguments);
  131. }
  132. void LogDataDialogClass::rprintf(char *text, const va_list & args)
  133. {
  134. static char string_buffer[256];
  135. vsprintf(string_buffer, text, args);
  136. HWND ctrlHwnd = GetDlgItem(Hwnd, IDC_ANIM_LOG_RICHEDIT);
  137. SendMessage(ctrlHwnd, EM_SETSEL, last_buffer_index, buffer_index );
  138. SendMessage(ctrlHwnd, EM_REPLACESEL, FALSE, (long)string_buffer);
  139. buffer_index = strlen(string_buffer) + last_buffer_index;
  140. //int min,max,pos;
  141. //GetScrollRange(ctrlHwnd, SB_VERT, &min, &max);
  142. //pos = GetScrollPos(ctrlHwnd, SB_VERT);
  143. //SendMessage(GetDlgItem(Hwnd,IDC_ANIM_LOG_RICHEDIT), EM_SCROLLCARET, 0, 0);
  144. } // rprintf
  145. /***********************************************************************************************
  146. * LogDataDialogClass::updatebar - send message to progress meter *
  147. * *
  148. * INPUT: *
  149. * *
  150. * OUTPUT: *
  151. * *
  152. * WARNINGS: *
  153. * *
  154. * HISTORY: *
  155. * 02/14/2000 JGA : Created. *
  156. *=============================================================================================*/
  157. void LogDataDialogClass::updatebar(float position, float total)
  158. {
  159. int pos;
  160. pos = ((position / total) * 100.0f);
  161. HWND ctrlHwnd = GetDlgItem(Hwnd, IDC_ANIM_COMPRESS_PROGRESS);
  162. SendMessage(ctrlHwnd, PBM_SETPOS, pos, 0 );
  163. } // updatebar
  164. /***********************************************************************************************
  165. * LogDataDialogClass::Wait_OK - Give user a chance to review log, then hit ok *
  166. * *
  167. * INPUT: *
  168. * *
  169. * OUTPUT: *
  170. * *
  171. * WARNINGS: *
  172. * *
  173. * HISTORY: *
  174. * 02/14/2000 JGA : Created. *
  175. *=============================================================================================*/
  176. void LogDataDialogClass::Wait_OK()
  177. {
  178. ::EnableWindow(GetDlgItem(Hwnd,IDOK),TRUE);
  179. ::SetForegroundWindow(Hwnd);
  180. while (status < 2) {
  181. // wait for the OK
  182. }
  183. } // Wait_OK
  184. /***********************************************************************************************
  185. * LogDataDialogClass::Dialog_Proc -- Handles the windows message for the options dialog *
  186. * *
  187. * INPUT: *
  188. * *
  189. * OUTPUT: *
  190. * *
  191. * WARNINGS: *
  192. * *
  193. * HISTORY: *
  194. * 07/24/1997 GH : Created. *
  195. *=============================================================================================*/
  196. bool LogDataDialogClass::Dialog_Proc
  197. (
  198. HWND hwnd,
  199. UINT message,
  200. WPARAM wParam,
  201. LPARAM
  202. )
  203. {
  204. int code = HIWORD(wParam);
  205. switch (message ) {
  206. /*******************************************************************
  207. * WM_INITDIALOG
  208. *
  209. * Initialize all of the custom controls for the dialog box
  210. *
  211. *******************************************************************/
  212. case WM_INITDIALOG:
  213. Dialog_Init();
  214. return TRUE;
  215. /*******************************************************************
  216. * WM_COMMAND
  217. *
  218. *
  219. *******************************************************************/
  220. case WM_COMMAND:
  221. switch (LOWORD(wParam))
  222. {
  223. case IDOK:
  224. status = 2;
  225. EndDialog(Hwnd, 1);
  226. Hwnd = NULL;
  227. return TRUE;
  228. break;
  229. }
  230. break;
  231. //case WM_VSCROLL:
  232. // return TRUE;
  233. // break;
  234. case WM_CLOSE:
  235. if (status >= 2) {
  236. EndDialog(Hwnd, 1);
  237. Hwnd = NULL;
  238. }
  239. return TRUE;
  240. break;
  241. }
  242. return FALSE;
  243. } // Dialog_Proc
  244. void LogDataDialogClass::Dialog_Init()
  245. {
  246. SetCursor(LoadCursor (NULL, IDC_ARROW));
  247. RECT desktop;
  248. RECT ourwin;
  249. GetWindowRect(GetDesktopWindow(), &desktop);
  250. GetWindowRect(Hwnd, &ourwin);
  251. int sx,sy,cx,cy;
  252. sx = ourwin.right - ourwin.left;
  253. sy = ourwin.bottom - ourwin.top;
  254. cx = (((desktop.right - desktop.left) - sx)/2) + desktop.left;
  255. cy = (((desktop.bottom - desktop.top) - sy)/2) + desktop.top;
  256. //SetWindowPos(Hwnd, HWND_TOPMOST, cx, cy, 0, 0, SWP_NOSIZE);
  257. SetWindowPos(Hwnd, HWND_TOP, cx, cy, 0, 0, SWP_NOSIZE);
  258. EnableWindow(GetDlgItem(Hwnd,IDOK),FALSE);
  259. status = 1; // signal init
  260. } // Dialog_Init
  261. /***********************************************************************************************
  262. * _logdata_dialog_proc -- thunks into the logdata dialog class's windows message handler *
  263. * *
  264. * INPUT: *
  265. * *
  266. * OUTPUT: *
  267. * *
  268. * WARNINGS: *
  269. * *
  270. * HISTORY: *
  271. * 02/09/2000 JGA : Created. *
  272. *=============================================================================================*/
  273. BOOL CALLBACK _logdata_dialog_proc
  274. (
  275. HWND hwnd,
  276. UINT message,
  277. WPARAM wParam,
  278. LPARAM lParam
  279. )
  280. {
  281. if (message == WM_INITDIALOG) {
  282. LogDataDialogClass * log = (LogDataDialogClass *)lParam;
  283. log->Hwnd = hwnd;
  284. ::SetProp(hwnd,"LogDataDialogClass",(HANDLE)log);
  285. }
  286. LogDataDialogClass * log = (LogDataDialogClass *)::GetProp(hwnd,"LogDataDialogClass");
  287. if (message == WM_DESTROY) {
  288. ::RemoveProp(hwnd,"LogDataDialogClass");
  289. }
  290. if (log) {
  291. return log->Dialog_Proc(hwnd,message,wParam,lParam);
  292. } else {
  293. return FALSE;
  294. }
  295. } // _logdata_dialog_proc
  296. DWORD WINAPI _logdata_thread_function(LPVOID log_obj_ptr)
  297. {
  298. // put logdata dialog box (lpParameter is the "this" pointer of the object)
  299. DialogBoxParam( AppInstance,
  300. MAKEINTRESOURCE(IDD_W3D_LOG),
  301. ((LogDataDialogClass*)log_obj_ptr)->ParentHwnd,
  302. (DLGPROC) _logdata_dialog_proc,
  303. (LPARAM) log_obj_ptr);
  304. // When this exits it should terminate the thread
  305. return(0);
  306. }
  307. // EOF - logdlg.cpp