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.

254 lines
5.3 KiB

  1. #include "pch.h"
  2. #include "resource.h"
  3. extern PCTSTR GetMemDbDat (VOID);
  4. HANDLE g_hHeap;
  5. HWND g_ParentWnd;
  6. HINSTANCE g_hInst;
  7. HINF g_Win95UpgInf;
  8. TCHAR g_WinDir[MAX_TCHAR_PATH];
  9. TCHAR g_System32Dir[MAX_TCHAR_PATH];
  10. TCHAR g_TempDir[MAX_TCHAR_PATH];
  11. TCHAR g_ProfileDir[MAX_TCHAR_PATH];
  12. PCTSTR g_SourceDir;
  13. static TCHAR WinDir[MAX_TCHAR_PATH];
  14. static TCHAR TempDir[MAX_TCHAR_PATH];
  15. static TCHAR ProfileDir[MAX_TCHAR_PATH];
  16. static TCHAR System32Dir[MAX_TCHAR_PATH];
  17. static TCHAR WkstaMigInf[MAX_TCHAR_PATH];
  18. //
  19. // Define structure we pass around to describe a billboard.
  20. //
  21. typedef struct _BILLBOARD_PARAMS {
  22. LPCTSTR Message;
  23. HWND Owner;
  24. DWORD NotifyThreadId;
  25. } BILLBOARD_PARAMS, *PBILLBOARD_PARAMS;
  26. //
  27. // Custom window messages
  28. //
  29. #define WMX_BILLBOARD_DISPLAYED (WM_USER+243)
  30. #define WMX_BILLBOARD_TERMINATE (WM_USER+244)
  31. BOOL
  32. BillboardDlgProc(
  33. IN HWND hdlg,
  34. IN UINT msg,
  35. IN WPARAM wParam,
  36. IN LPARAM lParam
  37. )
  38. {
  39. switch(msg) {
  40. case WM_INITDIALOG:
  41. {
  42. PBILLBOARD_PARAMS BillParams = (PBILLBOARD_PARAMS) lParam;
  43. PWSTR p;
  44. BOOL b;
  45. g_ParentWnd = hdlg;
  46. SetDlgItemText (hdlg, IDT_STATIC_1, BillParams->Message);
  47. CenterWindow (hdlg, NULL);
  48. PostMessage(hdlg,WMX_BILLBOARD_DISPLAYED,0,(LPARAM)BillParams->NotifyThreadId);
  49. }
  50. break;
  51. case WMX_BILLBOARD_DISPLAYED:
  52. PostThreadMessage(
  53. (DWORD)lParam,
  54. WMX_BILLBOARD_DISPLAYED,
  55. TRUE,
  56. (LPARAM)hdlg
  57. );
  58. break;
  59. case WMX_BILLBOARD_TERMINATE:
  60. EndDialog(hdlg,0);
  61. break;
  62. default:
  63. return(FALSE);
  64. }
  65. return(TRUE);
  66. }
  67. DWORD
  68. BillboardThread(
  69. IN PVOID ThreadParam
  70. )
  71. {
  72. PBILLBOARD_PARAMS BillboardParams;
  73. int i;
  74. BillboardParams = ThreadParam;
  75. i = DialogBoxParam(
  76. g_hInst,
  77. MAKEINTRESOURCE(IDD_BILLBOARD1),
  78. BillboardParams->Owner,
  79. BillboardDlgProc,
  80. (LPARAM)BillboardParams
  81. );
  82. return(0);
  83. }
  84. HWND
  85. DisplayBillboard(
  86. IN HWND Owner,
  87. IN LPCTSTR Message
  88. )
  89. {
  90. HANDLE ThreadHandle;
  91. DWORD ThreadId;
  92. BILLBOARD_PARAMS ThreadParams;
  93. HWND hwnd;
  94. MSG msg;
  95. hwnd = NULL;
  96. //
  97. // The billboard will exist in a separate thread so it will
  98. // always be responsive.
  99. //
  100. ThreadParams.Message = Message;
  101. ThreadParams.Owner = Owner;
  102. ThreadParams.NotifyThreadId = GetCurrentThreadId();
  103. ThreadHandle = CreateThread(
  104. NULL,
  105. 0,
  106. BillboardThread,
  107. &ThreadParams,
  108. 0,
  109. &ThreadId
  110. );
  111. if(ThreadHandle) {
  112. //
  113. // Wait for the billboard to tell us its window handle
  114. // or that it failed to display the billboard dialog.
  115. //
  116. do {
  117. GetMessage(&msg,NULL,0,0);
  118. if(msg.message == WMX_BILLBOARD_DISPLAYED) {
  119. if(msg.wParam) {
  120. hwnd = (HWND)msg.lParam;
  121. Sleep(1500); // let the user see it even on fast machines
  122. }
  123. } else {
  124. DispatchMessage(&msg);
  125. }
  126. } while(msg.message != WMX_BILLBOARD_DISPLAYED);
  127. CloseHandle(ThreadHandle);
  128. }
  129. return(hwnd);
  130. }
  131. VOID
  132. KillBillboard(
  133. IN HWND BillboardWindowHandle
  134. )
  135. {
  136. if(IsWindow(BillboardWindowHandle)) {
  137. PostMessage(BillboardWindowHandle,WMX_BILLBOARD_TERMINATE,0,0);
  138. }
  139. }
  140. BOOL
  141. MyInitLibs (
  142. PCSTR Path OPTIONAL
  143. )
  144. {
  145. DWORD ThreadId;
  146. PCWSTR UnicodePath;
  147. CHAR TempDirA[MAX_MBCHAR_PATH];
  148. g_hHeap = GetProcessHeap();
  149. g_hInst = GetModuleHandle(NULL);
  150. if (!Path) {
  151. GetWindowsDirectoryA (TempDirA, MAX_MBCHAR_PATH);
  152. Path = TempDirA;
  153. }
  154. DisplayBillboard (GetDesktopWindow(), TEXT("Test application started"));
  155. //
  156. // Official init
  157. //
  158. FirstInitRoutine (g_hInst);
  159. InitLibs (g_hInst, DLL_PROCESS_ATTACH, NULL);
  160. FinalInitRoutine();
  161. //
  162. // Redirect settings
  163. //
  164. UnicodePath = ConvertAtoW (Path);
  165. StringCopy (WinDir, UnicodePath);
  166. StringCopy (TempDir, WinDir);
  167. StringCopy (AppendWack (TempDir), TEXT("setup"));
  168. StringCopy (ProfileDir, WinDir);
  169. StringCopy (AppendWack (ProfileDir), TEXT("Profiles"));
  170. StringCopy (System32Dir, WinDir);
  171. StringCopy (AppendWack (System32Dir), TEXT("system32"));
  172. StringCopy (WkstaMigInf, UnicodePath);
  173. StringCopy (AppendWack (WkstaMigInf), TEXT("wkstamig.inf"));
  174. StringCopy (g_WinDir, WinDir);
  175. StringCopy (g_TempDir, TempDir);
  176. g_SourceDir = WinDir;
  177. StringCopy (g_ProfileDir, ProfileDir);
  178. StringCopy (g_System32Dir, System32Dir);
  179. g_WkstaMigInf = WinDir;
  180. MemDbLoad (GetMemDbDat());
  181. FreeConvertedStr (UnicodePath);
  182. return TRUE;
  183. }
  184. VOID
  185. MyTerminateLibs (
  186. VOID
  187. )
  188. {
  189. FirstCleanupRoutine();
  190. TerminateLibs (g_hInst, DLL_PROCESS_DETACH, NULL);
  191. FinalCleanupRoutine();
  192. }