floaterdialog.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 : Max2W3d *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/floaterdialog.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 10/30/00 2:58p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * FloaterDialogClass::FloaterDialogClass -- Constructor *
  37. * FloaterDialogClass::~FloaterDialogClass -- Destructor *
  38. * FloaterDialogClass::Is_Created -- test whether the floater has already been created *
  39. * FloaterDialogClass::Create -- create the window *
  40. * FloaterDialogClass::Dialog_Proc -- Dialog Proc for the floater *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "floaterdialog.h"
  43. #include "dllmain.h"
  44. #include "resource.h"
  45. #include <Max.h>
  46. /**********************************************************************************************
  47. **
  48. ** FloaterDialogClass Implementation
  49. **
  50. **********************************************************************************************/
  51. BOOL CALLBACK _floater_dialog_proc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  52. {
  53. if (message == WM_INITDIALOG) {
  54. FloaterDialogClass * floater = (FloaterDialogClass *)lParam;
  55. ::SetProp(hwnd,"FloaterDialogClass",(HANDLE)floater);
  56. }
  57. FloaterDialogClass * floater = (FloaterDialogClass *)::GetProp(hwnd,"FloaterDialogClass");
  58. if (message == WM_DESTROY) {
  59. ::RemoveProp(hwnd,"FloaterDialogClass");
  60. }
  61. if (floater) {
  62. return floater->Dialog_Proc(hwnd,message,wParam,lParam);
  63. } else {
  64. return FALSE;
  65. }
  66. }
  67. /***********************************************************************************************
  68. * FloaterDialogClass::FloaterDialogClass -- Constructor *
  69. * *
  70. * INPUT: *
  71. * *
  72. * OUTPUT: *
  73. * *
  74. * WARNINGS: *
  75. * *
  76. * HISTORY: *
  77. *=============================================================================================*/
  78. FloaterDialogClass::FloaterDialogClass(void) :
  79. Hwnd(NULL),
  80. ChildDialogTemplateID(-1),
  81. ChildDialogProc(NULL)
  82. {
  83. }
  84. /***********************************************************************************************
  85. * FloaterDialogClass::~FloaterDialogClass -- Destructor *
  86. * *
  87. * INPUT: *
  88. * *
  89. * OUTPUT: *
  90. * *
  91. * WARNINGS: *
  92. * *
  93. * HISTORY: *
  94. *=============================================================================================*/
  95. FloaterDialogClass::~FloaterDialogClass(void)
  96. {
  97. if (Hwnd != NULL) {
  98. ::DestroyWindow(Hwnd);
  99. }
  100. }
  101. /***********************************************************************************************
  102. * FloaterDialogClass::Is_Created -- test whether the floater has already been created *
  103. * *
  104. * INPUT: *
  105. * *
  106. * OUTPUT: *
  107. * *
  108. * WARNINGS: *
  109. * *
  110. * HISTORY: *
  111. * 10/11/2000 gth : Created. *
  112. *=============================================================================================*/
  113. bool FloaterDialogClass::Is_Created(void)
  114. {
  115. return (Hwnd != NULL);
  116. }
  117. /***********************************************************************************************
  118. * FloaterDialogClass::Create -- create the window *
  119. * *
  120. * This function will return automatically if the floater has been created already. *
  121. * *
  122. * INPUT: *
  123. * *
  124. * OUTPUT: *
  125. * *
  126. * WARNINGS: *
  127. * *
  128. * HISTORY: *
  129. * 10/11/2000 gth : Created. *
  130. *=============================================================================================*/
  131. void FloaterDialogClass::Create(Interface * ip, int child_dlg_id, DLGPROC child_dlg_proc)
  132. {
  133. /*
  134. ** Don't create multiple ones
  135. */
  136. if (Is_Created()) {
  137. return;
  138. }
  139. /*
  140. ** Copy down the data needed to create the child window later
  141. */
  142. ChildDialogTemplateID = child_dlg_id;
  143. ChildDialogProc = child_dlg_proc;
  144. /*
  145. ** Create the dialog box
  146. */
  147. Hwnd = CreateDialogParam(
  148. AppInstance,
  149. MAKEINTRESOURCE(IDD_W3DUTILITY_FLOATER_DIALOG),
  150. ::GetCOREInterface()->GetMAXHWnd(),
  151. (DLGPROC) _floater_dialog_proc,
  152. (LPARAM) this
  153. );
  154. ::GetCOREInterface()->RegisterDlgWnd(Hwnd);
  155. }
  156. /***********************************************************************************************
  157. * FloaterDialogClass::Dialog_Proc -- Dialog Proc for the floater *
  158. * *
  159. * The only thing we need to do here is to create the child dialog and resize ourselves to *
  160. * contain it. *
  161. * *
  162. * INPUT: *
  163. * *
  164. * OUTPUT: *
  165. * *
  166. * WARNINGS: *
  167. * *
  168. * HISTORY: *
  169. * 10/11/2000 gth : Created. *
  170. *=============================================================================================*/
  171. bool FloaterDialogClass::Dialog_Proc(HWND hWnd,UINT message,WPARAM wParam,LPARAM)
  172. {
  173. switch (message ) {
  174. case WM_INITDIALOG:
  175. {
  176. HWND childhwnd = CreateDialogParam(
  177. AppInstance,
  178. MAKEINTRESOURCE(ChildDialogTemplateID),
  179. hWnd,
  180. ChildDialogProc,
  181. 0
  182. );
  183. if (childhwnd!= NULL) {
  184. RECT rect;
  185. LONG style = ::GetWindowLong(hWnd,GWL_STYLE);
  186. ::GetWindowRect(childhwnd,&rect);
  187. ::AdjustWindowRect(&rect,style,FALSE);
  188. ::SetWindowPos(hWnd,NULL,0,0,rect.right - rect.left,rect.bottom - rect.top,SWP_NOZORDER|SWP_NOMOVE);
  189. ::SetWindowPos(childhwnd,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW);
  190. }
  191. }
  192. return 1;
  193. case WM_COMMAND:
  194. switch (LOWORD(wParam))
  195. {
  196. case IDCANCEL:
  197. DestroyWindow(Hwnd);
  198. break;
  199. }
  200. return 1;
  201. case WM_DESTROY:
  202. ::GetCOREInterface()->UnRegisterDlgWnd(Hwnd);
  203. Hwnd = NULL;
  204. break;
  205. }
  206. return 0;
  207. }