Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
9.0 KiB

  1. //
  2. // MAIN.CPP
  3. // Whiteboard Windows App Code
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. // PRECOMP
  8. #include "precomp.h"
  9. #include <it120app.h>
  10. #include <regentry.h>
  11. #include "gccmsg.h"
  12. #include "coder.hpp"
  13. #include "NMWbObj.h"
  14. #include "wbloader.h"
  15. Coder * g_pCoder;
  16. WbMainWindow * g_pMain;
  17. HINSTANCE g_hInstance;
  18. UINT g_uConfShutdown;
  19. WbPrinter * g_pPrinter;
  20. BOOL g_bPalettesInitialized;
  21. BOOL g_bUsePalettes;
  22. HPALETTE g_hRainbowPaletteDisplay;
  23. DWORD g_dwWorkThreadID = 0;
  24. DWORD __stdcall WBWorkThreadProc(LPVOID lpv);
  25. HINSTANCE g_hImmLib;
  26. IGC_PROC g_fnImmGetContext;
  27. INI_PROC g_fnImmNotifyIME;
  28. extern HANDLE g_hWorkThread;
  29. //
  30. // Arrays
  31. //
  32. COLORREF g_ColorTable[NUM_COLOR_ENTRIES] =
  33. {
  34. RGB( 0, 255, 255), // Cyan
  35. RGB(255, 255, 0), // Yellow
  36. RGB(255, 0, 255), // Magenta
  37. RGB( 0, 0, 255), // Blue
  38. RGB(192, 192, 192), // Grey
  39. RGB(255, 0, 0), // Red
  40. RGB( 0, 0, 128), // Dark blue
  41. RGB( 0, 128, 128), // Dark cyan
  42. RGB( 0, 255, 0), // Green
  43. RGB( 0, 128, 0), // Dark green
  44. RGB(128, 0, 0), // Dark red
  45. RGB(128, 0, 128), // Purple
  46. RGB(128, 128, 0), // Olive
  47. RGB(128, 128, 128), // Grey
  48. RGB(255, 255, 255), // White
  49. RGB( 0, 0, 0), // Black
  50. RGB(255, 128, 0), // Orange
  51. RGB(128, 255, 255), // Turquoise
  52. RGB( 0, 128, 255), // Mid blue
  53. RGB( 0, 255, 128), // Pale green
  54. RGB(255, 0, 128) // Dark pink
  55. };
  56. int g_ClipboardFormats[CLIPBOARD_ACCEPTABLE_FORMATS] =
  57. {
  58. 0, // CLIPBOARD_PRIVATE - Reserved for the T126 whiteboard private format
  59. CF_DIB, // Standard formats
  60. CF_ENHMETAFILE, // move metafiles to lower pri than bitmaps (bug NM4db:411)
  61. CF_TEXT
  62. };
  63. // Default widths for all tools except for highlighters
  64. UINT g_PenWidths[NUM_OF_WIDTHS] = { 2, 4, 8, 16 };
  65. // Default widths for highlight tools
  66. UINT g_HighlightWidths[NUM_OF_WIDTHS] = { 4, 8, 16, 32 };
  67. //
  68. // Objects
  69. //
  70. WbDrawingArea * g_pDraw;
  71. DCWbColorToIconMap * g_pIcons;
  72. UINT g_localGCCHandle; // This is a fake GCC handle used when we are not in a conference
  73. #ifdef _DEBUG
  74. HDBGZONE ghZoneWb;
  75. PTCHAR g_rgZonesWb[] = // CHECK ZONE_WBxxx CONSTANTS IF THESE CHANGE
  76. {
  77. "NewWB",
  78. DEFAULT_ZONES
  79. "DEBUG",
  80. "MSG",
  81. "TIMER",
  82. "EVENT"
  83. };
  84. #endif // _DEBUG
  85. //
  86. // Mapping of internal return codes to string resources
  87. //
  88. typedef struct tagERROR_MAP
  89. {
  90. UINT uiFEReturnCode;
  91. UINT uiDCGReturnCode;
  92. UINT uiCaption;
  93. UINT uiMessage;
  94. }
  95. ERROR_MAP;
  96. ERROR_MAP g_ErrorStringID[] =
  97. {
  98. { WBFE_RC_JOIN_CALL_FAILED, // Registration failed
  99. 0,
  100. IDS_MSG_CAPTION,
  101. IDS_MSG_JOIN_CALL_FAILED
  102. },
  103. { WBFE_RC_WINDOWS, // A windows error has occurred
  104. 0,
  105. IDS_MSG_CAPTION,
  106. IDS_MSG_WINDOWS_RESOURCES
  107. },
  108. { WBFE_RC_WB, // Page limit exceeded
  109. WB_RC_TOO_MANY_PAGES,
  110. IDS_MSG_CAPTION,
  111. IDS_MSG_TOO_MANY_PAGES
  112. },
  113. { WBFE_RC_WB, // Another user has the contents lock
  114. WB_RC_LOCKED,
  115. IDS_MSG_CAPTION,
  116. IDS_MSG_LOCKED
  117. },
  118. { WBFE_RC_WB, // Another user has the graphic locked
  119. WB_RC_GRAPHIC_LOCKED,
  120. IDS_MSG_CAPTION,
  121. IDS_MSG_GRAPHIC_LOCKED,
  122. },
  123. { WBFE_RC_WB, // The local user does not have the lock
  124. WB_RC_NOT_LOCKED,
  125. IDS_MSG_CAPTION,
  126. IDS_MSG_NOT_LOCKED
  127. },
  128. { WBFE_RC_WB, // File is not in expected format
  129. WB_RC_BAD_FILE_FORMAT,
  130. IDS_MSG_CAPTION,
  131. IDS_MSG_BAD_FILE_FORMAT
  132. },
  133. { WBFE_RC_WB, // File is not in expected format
  134. WB_RC_BAD_STATE,
  135. IDS_MSG_CAPTION,
  136. IDS_MSG_BAD_STATE_TO_LOAD_FILE
  137. },
  138. { WBFE_RC_WB, // Whiteboard busy (exhausted page cache)
  139. WB_RC_BUSY,
  140. IDS_MSG_CAPTION,
  141. IDS_MSG_BUSY
  142. },
  143. { WBFE_RC_CM, // Failed to access call manager
  144. 0,
  145. IDS_MSG_CAPTION,
  146. IDS_MSG_CM_ERROR
  147. },
  148. { WBFE_RC_AL, // Failed to register with application loader
  149. 0,
  150. IDS_MSG_CAPTION,
  151. IDS_MSG_AL_ERROR
  152. },
  153. { WBFE_RC_PRINTER, // Failed to register with application loader
  154. 0,
  155. IDS_MSG_CAPTION,
  156. IDS_MSG_PRINTER_ERROR
  157. },
  158. { 0, // Catch-all default
  159. 0,
  160. IDS_MSG_CAPTION,
  161. IDS_MSG_DEFAULT
  162. }
  163. };
  164. //
  165. //
  166. // Function: Message
  167. //
  168. // Purpose: Display an error message box with string resources specified
  169. // as parameters, with the WB main window as the modal window.
  170. //
  171. //
  172. int Message
  173. (
  174. HWND hwnd,
  175. UINT uiCaption,
  176. UINT uiMessage,
  177. UINT uiStyle
  178. )
  179. {
  180. TCHAR message[256];
  181. TCHAR caption[256];
  182. //make sure we're on top
  183. ASSERT(g_pMain);
  184. if (!hwnd)
  185. hwnd = g_pMain->m_hwnd;
  186. if (hwnd != NULL)
  187. {
  188. ::SetForegroundWindow(hwnd);
  189. }
  190. LoadString(g_hInstance, uiMessage, message, 256);
  191. LoadString(g_hInstance, uiCaption, caption, 256);
  192. //
  193. // BOGUS LAURABU:
  194. // Make use of MessageBoxEx() and just pass the string IDs along,
  195. // rather than doing the LoadString() ourself.
  196. //
  197. // Display a message box with the relevant text
  198. return(::MessageBox(hwnd, message, caption, uiStyle));
  199. }
  200. //
  201. //
  202. // Function: ErrorMessage
  203. //
  204. // Purpose: Display an error based on return codes from Whiteboard
  205. // processing.
  206. //
  207. //
  208. void ErrorMessage(UINT uiFEReturnCode, UINT uiDCGReturnCode)
  209. {
  210. MLZ_EntryOut(ZONE_FUNCTION, "::ErrorMessage (codes)");
  211. TRACE_MSG(("FE return code = %hd", uiFEReturnCode));
  212. TRACE_MSG(("DCG return code = %hd", uiDCGReturnCode));
  213. // Find the associated string resource IDS
  214. int iIndex;
  215. for (iIndex = 0; ; iIndex++)
  216. {
  217. // If we have come to the end of the list, stop
  218. if (g_ErrorStringID[iIndex].uiFEReturnCode == 0)
  219. {
  220. break;
  221. }
  222. // Check for a match
  223. if (g_ErrorStringID[iIndex].uiFEReturnCode == uiFEReturnCode)
  224. {
  225. if ( (g_ErrorStringID[iIndex].uiDCGReturnCode == uiDCGReturnCode)
  226. || (g_ErrorStringID[iIndex].uiDCGReturnCode == 0))
  227. {
  228. break;
  229. }
  230. }
  231. }
  232. // Display the message
  233. Message(NULL, g_ErrorStringID[iIndex].uiCaption, g_ErrorStringID[iIndex].uiMessage);
  234. }
  235. //
  236. //
  237. // Function: DefaultExceptionHandler
  238. //
  239. // Purpose: Default exception processing. This can be called in an
  240. // exception handler to get a message relevant to the
  241. // exception. The message is generated by posting a message to
  242. // the applications main window.
  243. //
  244. //
  245. void DefaultExceptionHandler(UINT uiFEReturnCode, UINT uiDCGReturnCode)
  246. {
  247. MLZ_EntryOut(ZONE_FUNCTION, "DefaultExceptionHandler");
  248. // Post a message to the main window to get the error displayed
  249. if (g_pMain != NULL)
  250. {
  251. if (g_pMain->m_hwnd)
  252. ::PostMessage(g_pMain->m_hwnd, WM_USER_DISPLAY_ERROR, uiFEReturnCode, uiDCGReturnCode);
  253. }
  254. }
  255. BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD fdwReason, LPVOID lpv)
  256. {
  257. switch (fdwReason)
  258. {
  259. case DLL_PROCESS_ATTACH:
  260. g_hInstance = hDllInst;
  261. DisableThreadLibraryCalls(hDllInst);
  262. g_dwWorkThreadID = 0;
  263. #ifdef _DEBUG
  264. MLZ_DbgInit((PSTR *) &g_rgZonesWb[0],
  265. (sizeof(g_rgZonesWb) / sizeof(g_rgZonesWb[0])) - 1);
  266. #endif
  267. DBG_INIT_MEMORY_TRACKING(hDllInst);
  268. g_pCoder = new Coder;
  269. ::T120_AppletStatus(APPLET_ID_WB, APPLET_LIBRARY_LOADED);
  270. break;
  271. case DLL_PROCESS_DETACH:
  272. if (NULL != g_hWorkThread)
  273. {
  274. ::CloseHandle(g_hWorkThread);
  275. }
  276. ::T120_AppletStatus(APPLET_ID_WB, APPLET_LIBRARY_FREED);
  277. g_hInstance = NULL;
  278. g_dwWorkThreadID = 0;
  279. if(g_pCoder)
  280. {
  281. delete g_pCoder;
  282. g_pCoder = NULL;
  283. }
  284. DBG_CHECK_MEMORY_TRACKING(hDllInst);
  285. #ifdef _DEBUG
  286. MLZ_DbgDeInit();
  287. #endif
  288. break;
  289. default:
  290. break;
  291. }
  292. return TRUE;
  293. }