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.

339 lines
9.0 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. InitializeCriticalSection(&g_csLocal);
  183. //
  184. // Need a semaphore for control access to CreateThread.
  185. //
  186. InitializeCriticalSection(&g_csNetThread);
  187. //
  188. // Allocate a tls index for curdlg so we can make it per-thread.
  189. //
  190. if ((g_tlsiCurDlg = TlsAlloc()) != 0xFFFFFFFF)
  191. {
  192. // mark the list as empty
  193. TlsSetValue(g_tlsiCurDlg, (LPVOID) 0);
  194. }
  195. else
  196. {
  197. StoreExtendedError(CDERR_INITIALIZATION);
  198. goto CantInit;
  199. }
  200. //
  201. // Store the current directory on process attach.
  202. //
  203. GetCurrentDirectory(ARRAYSIZE(g_szInitialCurDir), g_szInitialCurDir);
  204. //
  205. // Allocate a tls index for extended error.
  206. //
  207. if ((g_tlsiExtError = TlsAlloc()) == 0xFFFFFFFF)
  208. {
  209. StoreExtendedError(CDERR_INITIALIZATION);
  210. goto CantInit;
  211. }
  212. //
  213. // Allocate a tls index for LangID so we can make it per-thread.
  214. // it heavily used by CDLoadString.
  215. //
  216. if ((g_tlsLangID = TlsAlloc()) != 0xFFFFFFFF)
  217. {
  218. // mark the list as Neutral
  219. TlsSetValue(g_tlsLangID, (LPVOID) MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  220. }
  221. else
  222. {
  223. StoreExtendedError(CDERR_INITIALIZATION);
  224. goto CantInit;
  225. }
  226. dwNumDisks = 0;
  227. gpcNetEnumBuf = NULL;
  228. //
  229. // NetEnumBuf allocated in ListNetDrivesHandler.
  230. //
  231. cbNetEnumBuf = WNETENUM_BUFFSIZE;
  232. hMPR = NULL;
  233. hMPRUI = NULL;
  234. hLNDEvent = NULL;
  235. //
  236. // For file open dialog.
  237. //
  238. g_rcDlg.left = g_rcDlg.right = g_rcDlg.top = g_rcDlg.bottom = 0;
  239. g_bMirroredOS = IS_MIRRORING_ENABLED();
  240. return (TRUE);
  241. break;
  242. }
  243. case ( DLL_PROCESS_DETACH ) :
  244. {
  245. //
  246. // We only want to do our clean up work if we are being called
  247. // with freelibrary, not if the process is ending.
  248. //
  249. if (lpRes == NULL)
  250. {
  251. TermFile();
  252. TermPrint();
  253. TermColor();
  254. TermFont();
  255. TlsFree(g_tlsiCurDlg);
  256. TlsFree(g_tlsiExtError);
  257. TlsFree(g_tlsLangID);
  258. DeleteCriticalSection(&g_csLocal);
  259. DeleteCriticalSection(&g_csNetThread);
  260. }
  261. return (TRUE);
  262. break;
  263. }
  264. }
  265. CantInit:
  266. return (FALSE);
  267. lpRes;
  268. }