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.

179 lines
5.3 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: preview.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: RickTu
  10. *
  11. * DATE: 11/02/00
  12. *
  13. * DESCRIPTION: Class which backs up the template preview window
  14. *
  15. *****************************************************************************/
  16. #ifndef _PRINT_PHOTOS_PREVIEW_H_
  17. #define _PRINT_PHOTOS_PREVIEW_H_
  18. #define PW_SETNEWTEMPLATE (WM_USER+1) // wParam holds index of template that was chosen
  19. class CWizardInfoBlob;
  20. class CPreviewBitmap;
  21. extern ATOM g_cPreviewClassWnd;
  22. #define PREVIEW_WIDTH 200
  23. #define PREVIEW_HEIGHT 260
  24. typedef struct {
  25. HBITMAP hPrevBmp;
  26. BOOL bValid;
  27. BOOL bBitmapGenerationInProgress;
  28. CPreviewBitmap * pPreviewBitmap;
  29. } PREVIEW_STATE, *LPPREVIEW_STATE;
  30. #define PV_MSG_PREVIEW_BITMAP_AVAILABLE (WM_USER+100) // wParam is template index
  31. // lParam holds hBitmap of image to show.
  32. // hBitmap must be freed by receiver of message.
  33. #define PV_MSG_GENERATE_NEW_PREVIEW (WM_USER+101) // wParam is template index
  34. #define PV_NO_LAST_TEMPLATE_CHOSEN -1
  35. class CPreviewWindow
  36. {
  37. public:
  38. static CPreviewWindow* s_GetPW(HWND hwnd, UINT uMsg, LPARAM lParam)
  39. {
  40. WIA_PUSH_FUNCTION_MASK((0x10000000,TEXT("CPreviewWindow::s_GetPW()")));
  41. if ((uMsg == WM_CREATE) || (uMsg == WM_NCCREATE))
  42. {
  43. WIA_TRACE((TEXT("got WM_CREATE or WM_NCCREATE")));
  44. if (lParam)
  45. {
  46. WIA_TRACE((TEXT("Setting GWLP_USERDATA to be 0x%x"),((LPCREATESTRUCT)lParam)->lpCreateParams));
  47. SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams );
  48. }
  49. }
  50. return (CPreviewWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  51. }
  52. static LRESULT s_PreviewWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  53. {
  54. WIA_PUSH_FUNCTION_MASK((0x10000000,TEXT("CPreviewWindow::s_PreviewWndProc( 0x%x, 0x%x, 0x%x, 0x%x)"),hwnd,uMsg,wParam,lParam));
  55. CPreviewWindow *pw = CPreviewWindow::s_GetPW(hwnd, uMsg, lParam);
  56. if (pw)
  57. {
  58. return pw->DoHandleMessage(hwnd, uMsg, wParam, lParam);
  59. }
  60. else
  61. {
  62. WIA_ERROR((TEXT("Got back NULL pw!")));
  63. }
  64. return FALSE;
  65. }
  66. static VOID s_RegisterClass( HINSTANCE hInstance )
  67. {
  68. WIA_PUSH_FUNCTION_MASK((0x100,TEXT("CPreviewWindow::s_RegisterClass()")));
  69. if (!g_cPreviewClassWnd)
  70. {
  71. WNDCLASSEX wcex = {0};
  72. wcex.cbSize = sizeof(wcex);
  73. wcex.style = CS_HREDRAW | CS_VREDRAW;
  74. wcex.lpfnWndProc = CPreviewWindow::s_PreviewWndProc;
  75. wcex.hInstance = hInstance;
  76. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  77. wcex.lpszClassName = TEXT("PhotoPrintingPreviewWindowClass");
  78. ::g_cPreviewClassWnd = RegisterClassEx(&wcex);
  79. if (!::g_cPreviewClassWnd)
  80. {
  81. WIA_ERROR((TEXT("Couldn't register class, GLE = %d"),GetLastError()));
  82. }
  83. }
  84. }
  85. public:
  86. CPreviewWindow( CWizardInfoBlob * pWizInfo );
  87. ~CPreviewWindow();
  88. LRESULT DoHandleMessage( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  89. LRESULT OnSetNewTemplate( WPARAM wParam, HDC hdc = NULL );
  90. VOID DrawBitmap( HBITMAP hBitmap, HDC hdc = NULL );
  91. HBITMAP GetPreviewBitmap( INT iTemplate );
  92. VOID GenerateNewPreview( INT iTemplate );
  93. VOID GenerateWorkingBitmap( HWND hwnd );
  94. VOID ShowStillWorking( HWND hwnd );
  95. VOID InvalidateAllPreviews();
  96. VOID ShutDownBackgroundThreads();
  97. VOID StallBackgroundThreads();
  98. VOID RestartBackgroundThreads();
  99. private:
  100. LRESULT _OnNewPreviewAvailable( WPARAM wParam, LPARAM lParam );
  101. LRESULT _OnPaint();
  102. LRESULT _OnSize( WPARAM wParam, LPARAM lParam );
  103. VOID _InitList();
  104. private:
  105. CWizardInfoBlob * _pWizInfo;
  106. INT _LastTemplate;
  107. PREVIEW_STATE * _hPreviewList;
  108. INT _NumTemplates;
  109. HWND _hwnd;
  110. HWND _hwndProgress;
  111. CSimpleCriticalSection _csList;
  112. HBITMAP _hStillWorkingBitmap;
  113. BOOL _bThreadsAreStalled;
  114. };
  115. #define PVB_MSG_START (WM_USER+200)
  116. #define PVB_MSG_GENERATE_PREVIEW (PVB_MSG_START)
  117. #define PVB_MSG_EXIT_THREAD (PVB_MSG_START+1)
  118. #define PVB_MSG_END (PVB_MSG_EXIT_THREAD)
  119. class CPreviewBitmap
  120. {
  121. public:
  122. CPreviewBitmap( CWizardInfoBlob * pWizInfo, HWND hwnd, INT iTemplateIndex );
  123. ~CPreviewBitmap();
  124. VOID Invalidate();
  125. HRESULT GetPreview();
  126. VOID MessageQueueCreated();
  127. VOID GeneratePreview();
  128. VOID StallThread();
  129. VOID RestartThread();
  130. static DWORD CPreviewBitmap::s_PreviewBitmapWorkerThread(void *pv);
  131. private:
  132. HWND _hwndPreview;
  133. INT _iTemplateIndex;
  134. CWizardInfoBlob * _pWizInfo;
  135. CSimpleCriticalSection _csItem;
  136. HANDLE _hWorkThread;
  137. DWORD _dwWorkThreadId;
  138. HANDLE _hEventForMessageQueueCreation;
  139. BOOL _bThreadIsStalled;
  140. };
  141. #endif