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.

245 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: moveui.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 5-21-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "moveme.h"
  18. #include "dialogs.h"
  19. typedef enum _UI_THREAD_STATE {
  20. ThreadBlock,
  21. ThreadRunUi,
  22. ThreadExit
  23. } UI_THREAD_STATE ;
  24. typedef struct _UI_THREAD_INFO {
  25. HWND hWnd ;
  26. HANDLE UiWait ;
  27. HANDLE CallerWait ;
  28. UI_THREAD_STATE State ;
  29. ULONG CurrentString ;
  30. ULONG Flags ;
  31. ULONG Percentage ;
  32. PWSTR Title ;
  33. } UI_THREAD_INFO ;
  34. #define WM_READSTATE WM_USER + 1
  35. UI_THREAD_INFO UiThreadInfo ;
  36. HINSTANCE Module ;
  37. INT_PTR
  38. CALLBACK
  39. FeedbackDlg(
  40. HWND hDlg,
  41. UINT Message,
  42. WPARAM wParam,
  43. LPARAM lParam
  44. )
  45. {
  46. WCHAR Text[ MAX_PATH ];
  47. switch ( Message )
  48. {
  49. case WM_COMMAND:
  50. break;
  51. case WM_INITDIALOG:
  52. UiThreadInfo.hWnd = hDlg ;
  53. SetWindowText( hDlg, UiThreadInfo.Title );
  54. SetDlgItemText( hDlg, IDD_MIGRATING_TEXT, L"" );
  55. SendMessage( GetDlgItem( hDlg, IDD_MIGRATING_PROGRESS ),
  56. PBM_SETSTEP, (WPARAM) 1, 0 );
  57. SetEvent( UiThreadInfo.CallerWait );
  58. return TRUE ;
  59. case WM_READSTATE:
  60. LoadString( Module, UiThreadInfo.CurrentString, Text, MAX_PATH );
  61. SetDlgItemText( hDlg, IDD_MIGRATING_TEXT, Text );
  62. SendMessage( GetDlgItem( hDlg, IDD_MIGRATING_PROGRESS ),
  63. PBM_SETPOS, (WPARAM) UiThreadInfo.Percentage, 0 );
  64. UpdateWindow( GetDlgItem( hDlg, IDD_MIGRATING_PROGRESS ) );
  65. UpdateWindow( hDlg );
  66. return TRUE ;
  67. default:
  68. break;
  69. }
  70. return FALSE ;
  71. }
  72. DWORD
  73. UiThread(
  74. PVOID Ignored
  75. )
  76. {
  77. DebugLog(( DEB_TRACE_UI, "UI Thread starting\n" ));
  78. SetEvent( UiThreadInfo.CallerWait );
  79. while ( 1 )
  80. {
  81. DebugLog(( DEB_TRACE_UI, "State = %d\n", UiThreadInfo.State ));
  82. if ( UiThreadInfo.State == ThreadBlock )
  83. {
  84. WaitForSingleObjectEx( UiThreadInfo.UiWait, INFINITE, FALSE );
  85. continue;
  86. }
  87. if ( UiThreadInfo.State == ThreadExit )
  88. {
  89. ExitThread( 0 );
  90. }
  91. if ( UiThreadInfo.State == ThreadRunUi )
  92. {
  93. DialogBox( Module,
  94. MAKEINTRESOURCE( IDD_MIGRATING ),
  95. NULL,
  96. FeedbackDlg );
  97. ResetEvent( UiThreadInfo.UiWait );
  98. UiThreadInfo.State = ThreadBlock ;
  99. }
  100. }
  101. return 0;
  102. }
  103. BOOL
  104. CreateUiThread(
  105. VOID
  106. )
  107. {
  108. HANDLE hThread ;
  109. DWORD Tid ;
  110. if ( MoveOptions & MOVE_NO_UI )
  111. {
  112. return TRUE ;
  113. }
  114. Module = GetModuleHandle( NULL );
  115. ZeroMemory( &UiThreadInfo, sizeof( UiThreadInfo ) );
  116. UiThreadInfo.UiWait = CreateEvent( NULL, FALSE, FALSE, NULL );
  117. UiThreadInfo.CallerWait = CreateEvent( NULL, FALSE, FALSE, NULL );
  118. UiThreadInfo.State = ThreadBlock ;
  119. hThread = CreateThread( NULL, 0,
  120. UiThread, 0,
  121. 0, &Tid );
  122. if ( hThread )
  123. {
  124. CloseHandle( hThread );
  125. WaitForSingleObjectEx( UiThreadInfo.CallerWait, INFINITE, FALSE );
  126. return TRUE ;
  127. }
  128. return FALSE ;
  129. }
  130. VOID
  131. StopUiThread(
  132. VOID
  133. )
  134. {
  135. if ( MoveOptions & MOVE_NO_UI )
  136. {
  137. return ;
  138. }
  139. if ( UiThreadInfo.State == ThreadRunUi )
  140. {
  141. SendMessage( UiThreadInfo.hWnd, WM_CLOSE, 0, 0 );
  142. }
  143. UiThreadInfo.State = ThreadExit ;
  144. SetEvent( UiThreadInfo.UiWait );
  145. }
  146. VOID
  147. RaiseUi(
  148. HWND Parent,
  149. LPWSTR Title
  150. )
  151. {
  152. if ( MoveOptions & MOVE_NO_UI )
  153. {
  154. return;
  155. }
  156. UiThreadInfo.State = ThreadRunUi ;
  157. UiThreadInfo.Title = Title ;
  158. DebugLog(( DEB_TRACE_UI, "Raise: State = %d, pulsing event\n",
  159. UiThreadInfo.State ));
  160. ResetEvent( UiThreadInfo.CallerWait );
  161. SetEvent( UiThreadInfo.UiWait );
  162. WaitForSingleObjectEx( UiThreadInfo.CallerWait, INFINITE, FALSE );
  163. }
  164. VOID
  165. UpdateUi(
  166. DWORD StringId,
  167. DWORD Percentage
  168. )
  169. {
  170. if ( MoveOptions & MOVE_NO_UI )
  171. {
  172. return;
  173. }
  174. if ( UiThreadInfo.State == ThreadRunUi )
  175. {
  176. UiThreadInfo.CurrentString = StringId ;
  177. UiThreadInfo.Percentage = Percentage ;
  178. SendMessage( UiThreadInfo.hWnd, WM_READSTATE, 0, 0 );
  179. }
  180. if ( Percentage == 100 )
  181. {
  182. EndDialog( UiThreadInfo.hWnd, IDOK );
  183. }
  184. }