FormClass.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. ** Command & Conquer Renegade(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 : FormClass *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/FormClass.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 11/09/98 3:02a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * FormClass::Create_Form -- Loads the dialog template and initializes *
  35. * FormClass::fnFormProc -- windows proc which thunks into the virtual Dialog_Proc *
  36. * FormClass::ExecuteDlgInit -- Initializes controls in the dialog template *
  37. * FormClass::ExecuteDlgInit -- Initializes the controls in the dialog template *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #include "FormClass.H"
  40. #include "Dllmain.H"
  41. // hard-coded resource id which VC special cases for MFC... >:-)
  42. #define RT_DLGINIT MAKEINTRESOURCE(240)
  43. /***********************************************************************************************
  44. * FormClass::Create_Form -- Loads the dialog template and initializes *
  45. * *
  46. * INPUT: *
  47. * *
  48. * OUTPUT: *
  49. * *
  50. * WARNINGS: *
  51. * *
  52. * HISTORY: *
  53. * 11/6/98 GTH : Created. *
  54. *=============================================================================================*/
  55. HWND
  56. FormClass::Create_Form
  57. (
  58. HWND parent_wnd,
  59. UINT template_id
  60. )
  61. {
  62. // call PreCreateWindow to get prefered extended style
  63. CREATESTRUCT cs = { 0 };
  64. cs.style = WS_CHILD;
  65. m_hWnd = ::CreateDialogParam( AppInstance,
  66. MAKEINTRESOURCE (template_id),
  67. parent_wnd,
  68. fnFormProc,
  69. (LPARAM)this);
  70. assert(m_hWnd);
  71. // Remove the caption from the dialog (if there was any)
  72. ::SetWindowLong (m_hWnd,
  73. GWL_STYLE,
  74. ::GetWindowLong (m_hWnd, GWL_STYLE) & (~WS_CAPTION));
  75. ::GetWindowRect (m_hWnd, &m_FormRect);
  76. ExecuteDlgInit(MAKEINTRESOURCE(template_id));
  77. return m_hWnd;
  78. }
  79. /***********************************************************************************************
  80. * FormClass::fnFormProc -- windows proc which thunks into the virtual Dialog_Proc *
  81. * *
  82. * INPUT: *
  83. * *
  84. * OUTPUT: *
  85. * *
  86. * WARNINGS: *
  87. * *
  88. * HISTORY: *
  89. * 11/6/98 GTH : Created. *
  90. *=============================================================================================*/
  91. BOOL WINAPI
  92. FormClass::fnFormProc
  93. (
  94. HWND dlg_wnd,
  95. UINT message,
  96. WPARAM wparam,
  97. LPARAM lparam
  98. )
  99. {
  100. FormClass *pform = (FormClass *)::GetProp (dlg_wnd, "FORMCLASS");
  101. if (message == WM_INITDIALOG) {
  102. pform = (FormClass *)lparam;
  103. ::SetProp (dlg_wnd, "FORMCLASS", (HANDLE)pform);
  104. } else if (message == WM_DESTROY) {
  105. ::RemoveProp (dlg_wnd, "FORMCLASS");
  106. }
  107. BOOL retval = FALSE;
  108. if (pform) {
  109. retval = pform->Dialog_Proc (dlg_wnd, message, wparam, lparam);
  110. }
  111. return retval;
  112. }
  113. /***********************************************************************************************
  114. * FormClass::ExecuteDlgInit -- Initializes controls in the dialog template *
  115. * *
  116. * This code was lifted straight out of MFC. It does some "interesting" things like putting *
  117. * strings into combo boxes which are typed in the resource editor. *
  118. * *
  119. * INPUT: *
  120. * *
  121. * OUTPUT: *
  122. * *
  123. * WARNINGS: *
  124. * *
  125. * HISTORY: *
  126. * 11/6/98 GTH : Created. *
  127. *=============================================================================================*/
  128. BOOL FormClass::ExecuteDlgInit(LPCTSTR lpszResourceName)
  129. {
  130. // find resource handle
  131. LPVOID lpResource = NULL;
  132. HGLOBAL hResource = NULL;
  133. if (lpszResourceName != NULL)
  134. {
  135. HINSTANCE hInst = AppInstance;
  136. HRSRC hDlgInit = ::FindResource(hInst, lpszResourceName, RT_DLGINIT);
  137. if (hDlgInit != NULL)
  138. {
  139. // load it
  140. hResource = LoadResource(hInst, hDlgInit);
  141. if (hResource == NULL)
  142. return FALSE;
  143. // lock it
  144. lpResource = LockResource(hResource);
  145. assert(lpResource != NULL);
  146. }
  147. }
  148. // execute it
  149. BOOL bResult = ExecuteDlgInit(lpResource);
  150. // cleanup
  151. if (lpResource != NULL && hResource != NULL)
  152. {
  153. UnlockResource(hResource);
  154. FreeResource(hResource);
  155. }
  156. return bResult;
  157. }
  158. /***********************************************************************************************
  159. * FormClass::ExecuteDlgInit -- Initializes the controls in the dialog template *
  160. * *
  161. * As the above ExecuteDlgInit function, this was lifted from MFC... *
  162. * *
  163. * INPUT: *
  164. * *
  165. * OUTPUT: *
  166. * *
  167. * WARNINGS: *
  168. * *
  169. * HISTORY: *
  170. * 11/6/98 GTH : Created. *
  171. *=============================================================================================*/
  172. BOOL FormClass::ExecuteDlgInit(LPVOID lpResource)
  173. {
  174. BOOL bSuccess = TRUE;
  175. if (lpResource != NULL)
  176. {
  177. UNALIGNED WORD* lpnRes = (WORD*)lpResource;
  178. while (bSuccess && *lpnRes != 0)
  179. {
  180. WORD nIDC = *lpnRes++;
  181. WORD nMsg = *lpnRes++;
  182. DWORD dwLen = *((UNALIGNED DWORD*&)lpnRes)++;
  183. // In Win32 the WM_ messages have changed. They have
  184. // to be translated from the 32-bit values to 16-bit
  185. // values here.
  186. #define WIN16_LB_ADDSTRING 0x0401
  187. #define WIN16_CB_ADDSTRING 0x0403
  188. if (nMsg == WIN16_LB_ADDSTRING)
  189. nMsg = LB_ADDSTRING;
  190. else if (nMsg == WIN16_CB_ADDSTRING)
  191. nMsg = CB_ADDSTRING;
  192. // check for invalid/unknown message types
  193. assert(nMsg == LB_ADDSTRING || nMsg == CB_ADDSTRING);
  194. if (nMsg == LB_ADDSTRING || nMsg == CB_ADDSTRING)
  195. {
  196. // List/Combobox returns -1 for error
  197. if (::SendDlgItemMessageA(m_hWnd, nIDC, nMsg, 0, (LONG)lpnRes) == -1)
  198. bSuccess = FALSE;
  199. }
  200. // skip past data
  201. lpnRes = (WORD*)((LPBYTE)lpnRes + (UINT)dwLen);
  202. }
  203. }
  204. return bSuccess;
  205. }