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.

244 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bkthrdlg.c
  5. Abstract:
  6. Routines that implement a billboard-type dialog, for displaying
  7. a message while the program carries out some action.
  8. Author:
  9. Ted Miller (tedm) 5-Jan-1995
  10. Revision History:
  11. --*/
  12. #include "books.h"
  13. //
  14. // Define structure used internally to communicate information
  15. // to the billboard dialog procedure.
  16. //
  17. typedef struct _BILLBOARDPARAMS {
  18. PTHREAD_START_ROUTINE ThreadEntry;
  19. PWSTR Caption;
  20. PWSTR Text;
  21. PVOID UserData;
  22. HWND OwnerWindow;
  23. } BILLBOARDPARAMS, *PBILLBOARDPARAMS;
  24. //
  25. // Custom window message the dialog sends to itself
  26. // to indicate that WM_INITDIALOG is done.
  27. //
  28. // lParam = thread handle of action worker thread
  29. //
  30. #define WMX_I_AM_READY (WM_USER+567)
  31. //
  32. // Name of property we use to store thread parameters.
  33. //
  34. PWSTR ThreadParamsPropertyName = L"__threadparams";
  35. INT_PTR
  36. CALLBACK
  37. DlgProcBillboard(
  38. IN HWND hdlg,
  39. IN UINT msg,
  40. IN WPARAM wParam,
  41. IN LPARAM lParam
  42. )
  43. /*++
  44. Routine Description:
  45. Dialog procedure for the 'billboard-with-associated-action'
  46. dialog. When the dialog is initializing we create a worker thread
  47. to perform the action. This allows us to remain responsive to the
  48. user without yielding, etc.
  49. Arguments:
  50. hdlg - supplies handle of dialog box
  51. msg - supplies the message on which the dialog procedure is to act
  52. wParam - supplies message-dependent data
  53. lParam - supplies message-dependent data
  54. Return Value:
  55. Message-dependent.
  56. --*/
  57. {
  58. PBILLBOARDPARAMS Params;
  59. HANDLE h;
  60. DWORD ThreadId;
  61. PACTIONTHREADPARAMS params;
  62. switch(msg) {
  63. case WM_INITDIALOG:
  64. Params = (PBILLBOARDPARAMS)lParam;
  65. CenterDialogInWindow(hdlg,Params->OwnerWindow);
  66. //
  67. // Set the text fields.
  68. //
  69. SetWindowText(hdlg,Params->Caption);
  70. SetDlgItemText(hdlg,IDT_BILLBOARD_TEXT,Params->Text);
  71. //
  72. // Create the thread parameters
  73. //
  74. params = MyMalloc(sizeof(ACTIONTHREADPARAMS));
  75. if (params) {
  76. SetProp(hdlg,ThreadParamsPropertyName,(HANDLE)params);
  77. params->hdlg = hdlg;
  78. params->UserData = Params->UserData;
  79. } else {
  80. OutOfMemory();
  81. }
  82. //
  83. // Create the worker thread. The worker thread
  84. // should have a sleep(100) as its first thing to let the
  85. // billboard finish coming up. And when it's done it has
  86. // to send us a WM_COMMAND as notification.
  87. //
  88. h = CreateThread(
  89. NULL,
  90. 0,
  91. Params->ThreadEntry,
  92. params,
  93. CREATE_SUSPENDED,
  94. &ThreadId
  95. );
  96. if(h == NULL) {
  97. OutOfMemory();
  98. } else {
  99. PostMessage(hdlg,WMX_I_AM_READY,0,(LPARAM)h);
  100. }
  101. break;
  102. case WMX_I_AM_READY:
  103. //
  104. // Dialog is displayed; kick off the worker thread.
  105. //
  106. ResumeThread((HANDLE)lParam);
  107. CloseHandle((HANDLE)lParam);
  108. break;
  109. case WM_COMMAND:
  110. //
  111. // End the dialog.
  112. //
  113. if(LOWORD(wParam) == IDOK) {
  114. {
  115. HANDLE tmpparams = GetProp(hdlg,ThreadParamsPropertyName);
  116. if (tmpparams) {
  117. MyFree((PVOID)tmpparams);
  118. }
  119. }
  120. EndDialog(hdlg,(int)lParam);
  121. return(FALSE);
  122. }
  123. break;
  124. default:
  125. return(FALSE);
  126. }
  127. return(TRUE);
  128. }
  129. DWORD
  130. ActionWithBillboard(
  131. IN PTHREAD_START_ROUTINE ThreadEntry,
  132. IN HWND OwnerWindow,
  133. IN UINT CaptionStringId,
  134. IN UINT TextStringId,
  135. IN PVOID UserData
  136. )
  137. /*++
  138. Routine Description:
  139. Main entry point for carrying out an action with a 'please wait'
  140. dialog box.
  141. Arguments:
  142. ThreadEntry - supplies the address of a worker thread that will carry
  143. out the action.
  144. OwnerWindow - supplies the window handle of the window that is to own
  145. the billboard dialog.
  146. CaptionStringId - supplies the resource string id of the string to be
  147. used as the billboard caption.
  148. TextStringId - supplies the resource string id of the string ot be
  149. used as the billboard text.
  150. UserData - supplies a caller-defined value that is meaningful to the
  151. worker thread. This valus is passed to the thread as the UserData
  152. member of the ACTIONTHREADPARAMS structure.
  153. Return Value:
  154. The value returned by the action's worker thread.
  155. --*/
  156. {
  157. BILLBOARDPARAMS p;
  158. DWORD i;
  159. //
  160. // Load the two strings and create a params structure.
  161. //
  162. p.Caption = MyLoadString(CaptionStringId);
  163. p.Text = MyLoadString(TextStringId);
  164. p.ThreadEntry = ThreadEntry;
  165. p.UserData = UserData;
  166. p.OwnerWindow = OwnerWindow;
  167. i = (DWORD)DialogBoxParam(
  168. hInst,
  169. MAKEINTRESOURCE(DLG_BILLBOARD),
  170. OwnerWindow,
  171. DlgProcBillboard,
  172. (LPARAM)&p
  173. );
  174. MyFree(p.Text);
  175. MyFree(p.Caption);
  176. return i;
  177. }