Leaked source code of windows server 2003
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.

347 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1990-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. init.c
  5. Abstract:
  6. This module contains the init routines for the Win32 common dialogs.
  7. Revision History:
  8. --*/
  9. // precompiled headers
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. //
  13. // External Declarations.
  14. //
  15. extern HDC hdcMemory;
  16. extern HBITMAP hbmpOrigMemBmp;
  17. extern CRITICAL_SECTION g_csLocal;
  18. extern CRITICAL_SECTION g_csNetThread;
  19. // TLS index to get current dlg info for the current thread
  20. extern DWORD g_tlsiCurDlg;
  21. // TLS index to get most recent ExtError for the current thread
  22. extern DWORD g_tlsiExtError;
  23. // TLS index to get LangID used for the current thread
  24. extern DWORD g_tlsLangID;
  25. extern HANDLE hMPR;
  26. extern HANDLE hMPRUI;
  27. extern HANDLE hLNDEvent;
  28. extern DWORD dwNumDisks;
  29. extern OFN_DISKINFO gaDiskInfo[MAX_DISKS];
  30. extern DWORD cbNetEnumBuf;
  31. extern LPTSTR gpcNetEnumBuf;
  32. extern RECT g_rcDlg;
  33. extern TCHAR g_szInitialCurDir[MAX_PATH];
  34. //
  35. // Global Variables.
  36. //
  37. WCHAR szmsgLBCHANGEW[] = LBSELCHSTRINGW;
  38. WCHAR szmsgSHAREVIOLATIONW[] = SHAREVISTRINGW;
  39. WCHAR szmsgFILEOKW[] = FILEOKSTRINGW;
  40. WCHAR szmsgCOLOROKW[] = COLOROKSTRINGW;
  41. WCHAR szmsgSETRGBW[] = SETRGBSTRINGW;
  42. WCHAR szCommdlgHelpW[] = HELPMSGSTRINGW;
  43. TCHAR szShellIDList[] = CFSTR_SHELLIDLIST;
  44. BOOL g_bMirroredOS = FALSE;
  45. //
  46. // Private message for WOW to indicate 32-bit logfont
  47. // needs to be thunked back to 16-bit log font.
  48. //
  49. CHAR szmsgWOWLFCHANGE[] = "WOWLFChange";
  50. //
  51. // Private message for WOW to indicate 32-bit directory needs to be
  52. // thunked back to 16-bit task directory.
  53. //
  54. CHAR szmsgWOWDIRCHANGE[] = "WOWDirChange";
  55. CHAR szmsgWOWCHOOSEFONT_GETLOGFONT[] = "WOWCHOOSEFONT_GETLOGFONT";
  56. CHAR szmsgLBCHANGEA[] = LBSELCHSTRINGA;
  57. CHAR szmsgSHAREVIOLATIONA[] = SHAREVISTRINGA;
  58. CHAR szmsgFILEOKA[] = FILEOKSTRINGA;
  59. CHAR szmsgCOLOROKA[] = COLOROKSTRINGA;
  60. CHAR szmsgSETRGBA[] = SETRGBSTRINGA;
  61. CHAR szCommdlgHelpA[] = HELPMSGSTRINGA;
  62. UINT g_cfCIDA;
  63. ////////////////////////////////////////////////////////////////////////////
  64. //
  65. // FInitColor
  66. //
  67. ////////////////////////////////////////////////////////////////////////////
  68. extern DWORD rgbClient;
  69. extern HBITMAP hRainbowBitmap;
  70. int FInitColor(
  71. HANDLE hInst)
  72. {
  73. cyCaption = (short)GetSystemMetrics(SM_CYCAPTION);
  74. cyBorder = (short)GetSystemMetrics(SM_CYBORDER);
  75. cxBorder = (short)GetSystemMetrics(SM_CXBORDER);
  76. cyVScroll = (short)GetSystemMetrics(SM_CYVSCROLL);
  77. cxVScroll = (short)GetSystemMetrics(SM_CXVSCROLL);
  78. cxSize = (short)GetSystemMetrics(SM_CXSIZE);
  79. rgbClient = GetSysColor(COLOR_3DFACE);
  80. hRainbowBitmap = 0;
  81. return (TRUE);
  82. hInst;
  83. }
  84. ////////////////////////////////////////////////////////////////////////////
  85. //
  86. // FInitFile
  87. //
  88. ////////////////////////////////////////////////////////////////////////////
  89. BOOL FInitFile(
  90. HANDLE hins)
  91. {
  92. bMouse = GetSystemMetrics(SM_MOUSEPRESENT);
  93. wWinVer = 0x0A0A;
  94. //
  95. // Initialize these to reality.
  96. //
  97. #if DPMICDROMCHECK
  98. wCDROMIndex = InitCDROMIndex((LPWORD)&wNumCDROMDrives);
  99. #endif
  100. //
  101. // special WOW messages
  102. //
  103. msgWOWLFCHANGE = RegisterWindowMessageA((LPSTR)szmsgWOWLFCHANGE);
  104. msgWOWDIRCHANGE = RegisterWindowMessageA((LPSTR)szmsgWOWDIRCHANGE);
  105. msgWOWCHOOSEFONT_GETLOGFONT = RegisterWindowMessageA((LPSTR)szmsgWOWCHOOSEFONT_GETLOGFONT);
  106. msgLBCHANGEA = RegisterWindowMessageA((LPSTR)szmsgLBCHANGEA);
  107. msgSHAREVIOLATIONA = RegisterWindowMessageA((LPSTR)szmsgSHAREVIOLATIONA);
  108. msgFILEOKA = RegisterWindowMessageA((LPSTR)szmsgFILEOKA);
  109. msgCOLOROKA = RegisterWindowMessageA((LPSTR)szmsgCOLOROKA);
  110. msgSETRGBA = RegisterWindowMessageA((LPSTR)szmsgSETRGBA);
  111. #ifdef UNICODE
  112. msgLBCHANGEW = RegisterWindowMessageW((LPWSTR)szmsgLBCHANGEW);
  113. msgSHAREVIOLATIONW = RegisterWindowMessageW((LPWSTR)szmsgSHAREVIOLATIONW);
  114. msgFILEOKW = RegisterWindowMessageW((LPWSTR)szmsgFILEOKW);
  115. msgCOLOROKW = RegisterWindowMessageW((LPWSTR)szmsgCOLOROKW);
  116. msgSETRGBW = RegisterWindowMessageW((LPWSTR)szmsgSETRGBW);
  117. #else
  118. msgLBCHANGEW = msgLBCHANGEA;
  119. msgSHAREVIOLATIONW = msgSHAREVIOLATIONA;
  120. msgFILEOKW = msgFILEOKA;
  121. msgCOLOROKW = msgCOLOROKA;
  122. msgSETRGBW = msgSETRGBA;
  123. #endif
  124. g_cfCIDA = RegisterClipboardFormat(szShellIDList);
  125. return (TRUE);
  126. }
  127. ////////////////////////////////////////////////////////////////////////////
  128. //
  129. // LibMain
  130. //
  131. // Initializes any instance specific data needed by functions in the
  132. // common dialogs.
  133. //
  134. // Returns: TRUE - success
  135. // FALSE - failure
  136. //
  137. ////////////////////////////////////////////////////////////////////////////
  138. // ccover needs to link to C-runtime, so we rename LibMain to DllMain
  139. #ifdef CCOVER
  140. #define LibMain DllMain
  141. #endif
  142. BOOL LibMain(
  143. HANDLE hModule,
  144. DWORD dwReason,
  145. LPVOID lpRes)
  146. {
  147. switch (dwReason)
  148. {
  149. case ( DLL_THREAD_ATTACH ) :
  150. case ( DLL_THREAD_DETACH ) :
  151. {
  152. //
  153. // Threads can only enter and leave the comdlg32 dll from the
  154. // Get{Open,Save}FileName apis, so the TLS lpCurDlg alloc is
  155. // done inside the InitFileDlg routine in fileopen.c
  156. //
  157. return (TRUE);
  158. break;
  159. }
  160. case ( DLL_PROCESS_ATTACH ) :
  161. {
  162. g_hinst = (HANDLE)hModule;
  163. if (!FInitColor(g_hinst) || !FInitFile(g_hinst))
  164. {
  165. goto CantInit;
  166. }
  167. DisableThreadLibraryCalls(hModule);
  168. //
  169. // msgHELP is sent whenever a help button is pressed in one of
  170. // the common dialogs (provided an owner was declared and the
  171. // call to RegisterWindowMessage doesn't fail).
  172. //
  173. msgHELPA = RegisterWindowMessageA((LPSTR)szCommdlgHelpA);
  174. #ifdef UNICODE
  175. msgHELPW = RegisterWindowMessageW((LPWSTR)szCommdlgHelpW);
  176. #else
  177. msgHELPW = msgHELPA;
  178. #endif
  179. //
  180. // Need a semaphore locally for managing array of disk info.
  181. //
  182. if (!InitializeCriticalSectionAndSpinCount(&g_csLocal, 0))
  183. {
  184. StoreExtendedError(CDERR_INITIALIZATION);
  185. goto CantInit;
  186. }
  187. //
  188. // Need a semaphore for control access to CreateThread.
  189. //
  190. if (!InitializeCriticalSectionAndSpinCount(&g_csNetThread, 0))
  191. {
  192. StoreExtendedError(CDERR_INITIALIZATION);
  193. goto CantInit;
  194. }
  195. //
  196. // Allocate a tls index for curdlg so we can make it per-thread.
  197. //
  198. if ((g_tlsiCurDlg = TlsAlloc()) != 0xFFFFFFFF)
  199. {
  200. // mark the list as empty
  201. TlsSetValue(g_tlsiCurDlg, (LPVOID) 0);
  202. }
  203. else
  204. {
  205. StoreExtendedError(CDERR_INITIALIZATION);
  206. goto CantInit;
  207. }
  208. //
  209. // Store the current directory on process attach.
  210. //
  211. GetCurrentDirectory(ARRAYSIZE(g_szInitialCurDir), g_szInitialCurDir);
  212. //
  213. // Allocate a tls index for extended error.
  214. //
  215. if ((g_tlsiExtError = TlsAlloc()) == 0xFFFFFFFF)
  216. {
  217. StoreExtendedError(CDERR_INITIALIZATION);
  218. goto CantInit;
  219. }
  220. //
  221. // Allocate a tls index for LangID so we can make it per-thread.
  222. // it heavily used by CDLoadString.
  223. //
  224. if ((g_tlsLangID = TlsAlloc()) != 0xFFFFFFFF)
  225. {
  226. // mark the list as Neutral
  227. TlsSetValue(g_tlsLangID, (LPVOID) MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  228. }
  229. else
  230. {
  231. StoreExtendedError(CDERR_INITIALIZATION);
  232. goto CantInit;
  233. }
  234. dwNumDisks = 0;
  235. gpcNetEnumBuf = NULL;
  236. //
  237. // NetEnumBuf allocated in ListNetDrivesHandler.
  238. //
  239. cbNetEnumBuf = WNETENUM_BUFFSIZE;
  240. hMPR = NULL;
  241. hMPRUI = NULL;
  242. hLNDEvent = NULL;
  243. //
  244. // For file open dialog.
  245. //
  246. g_rcDlg.left = g_rcDlg.right = g_rcDlg.top = g_rcDlg.bottom = 0;
  247. g_bMirroredOS = IS_MIRRORING_ENABLED();
  248. return (TRUE);
  249. break;
  250. }
  251. case ( DLL_PROCESS_DETACH ) :
  252. {
  253. //
  254. // We only want to do our clean up work if we are being called
  255. // with freelibrary, not if the process is ending.
  256. //
  257. if (lpRes == NULL)
  258. {
  259. TermFile();
  260. TermPrint();
  261. TermColor();
  262. TermFont();
  263. TlsFree(g_tlsiCurDlg);
  264. TlsFree(g_tlsiExtError);
  265. TlsFree(g_tlsLangID);
  266. DeleteCriticalSection(&g_csLocal);
  267. DeleteCriticalSection(&g_csNetThread);
  268. }
  269. return (TRUE);
  270. break;
  271. }
  272. }
  273. CantInit:
  274. return (FALSE);
  275. lpRes;
  276. }