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.

148 lines
3.7 KiB

  1. // MainWnd.cpp: implementation of the CMainWnd class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "pch.h"
  5. #include "resource.h"
  6. #include "Page1.h"
  7. #include "MainWnd.h"
  8. #include "pagefact.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // CMainWnd
  11. //////////////////////////////////////////////////////////////////////
  12. CMainWnd::CMainWnd(void)
  13. {
  14. }
  15. CMainWnd::~CMainWnd(void)
  16. {
  17. }
  18. void CMainWnd::OnFinalMessage(HWND /*hwnd*/)
  19. {
  20. CloseTaskSheet();
  21. PostQuitMessage(0);
  22. }
  23. LRESULT CMainWnd::OnInitMenuPopup(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  24. {
  25. const UINT uEnable = MF_BYCOMMAND | MF_ENABLED;
  26. const UINT uDisable = MF_BYCOMMAND | MF_DISABLED | MF_GRAYED;
  27. if (0 == LOWORD(lParam))
  28. {
  29. HMENU hMenu = (HMENU)wParam;
  30. BOOL bSheetOpen = m_spTaskSheet ? TRUE : FALSE;
  31. EnableMenuItem(hMenu, ID_TEST_DOMODAL, bSheetOpen ? uDisable : uEnable);
  32. EnableMenuItem(hMenu, ID_TEST_DOMODELESS, bSheetOpen ? uDisable : uEnable);
  33. EnableMenuItem(hMenu, ID_TEST_CLOSEMODELESS, bSheetOpen ? uEnable : uDisable);
  34. }
  35. return 0;
  36. }
  37. LRESULT CMainWnd::OnDoModal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  38. {
  39. CreateTaskSheet(FALSE);
  40. return 0;
  41. }
  42. LRESULT CMainWnd::OnDoModeless(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  43. {
  44. CreateTaskSheet(TRUE);
  45. return 0;
  46. }
  47. LRESULT CMainWnd::OnCloseModeless(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  48. {
  49. CloseTaskSheet();
  50. return 0;
  51. }
  52. LRESULT CMainWnd::OnExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  53. {
  54. SendMessage(WM_CLOSE);
  55. return 0;
  56. }
  57. HRESULT CMainWnd::CreateTaskSheet(BOOL bModeless)
  58. {
  59. HRESULT hr;
  60. // For sanity
  61. CloseTaskSheet();
  62. hr = m_spTaskSheet.CoCreateInstance(__uuidof(TaskSheet));
  63. if (SUCCEEDED(hr))
  64. {
  65. CComPtr<IPropertyBag> spProps = NULL;
  66. hr = m_spTaskSheet->GetPropertyBag(IID_IPropertyBag, (void**)&spProps);
  67. if (SUCCEEDED(hr))
  68. {
  69. CComVariant var(L"Task Sheet Test");
  70. spProps->Write(TS_PROP_TITLE, &var);
  71. var = 600;
  72. spProps->Write(TS_PROP_WIDTH, &var);
  73. var = 400;
  74. spProps->Write(TS_PROP_HEIGHT, &var);
  75. var = 400;
  76. spProps->Write(TS_PROP_MINWIDTH, &var);
  77. var = 250;
  78. spProps->Write(TS_PROP_MINHEIGHT, &var);
  79. WCHAR szTemp[MAX_PATH];
  80. wnsprintfW(szTemp, ARRAYSIZE(szTemp), L"res://taskapp.exe/%d/%d", RT_BITMAP, IDB_WATERMARK);
  81. var = szTemp;
  82. //var = L"file://c:\\windows\\ua_bkgnd.bmp";
  83. spProps->Write(TS_PROP_WATERMARK, &var);
  84. // Note: Make modeless be resizable and modal not-resizable,
  85. // just to exercise both resizable and not.
  86. // Ditto for showing the statusbar.
  87. var = bModeless;
  88. spProps->Write(TS_PROP_MODELESS, &var);
  89. spProps->Write(TS_PROP_RESIZABLE, &var);
  90. spProps->Write(TS_PROP_STATUSBAR, &var);
  91. ITaskPageFactory *pPageFactory = NULL;
  92. hr = CPageFactory::CreateInstance(&pPageFactory);
  93. if (SUCCEEDED(hr))
  94. {
  95. hr = m_spTaskSheet->Run(pPageFactory, CLSID_CPage1, m_hWnd);
  96. pPageFactory->Release();
  97. }
  98. }
  99. if (!bModeless)
  100. m_spTaskSheet.Release();
  101. }
  102. return hr;
  103. }
  104. HRESULT CMainWnd::CloseTaskSheet()
  105. {
  106. HRESULT hr = E_UNEXPECTED;
  107. if (m_spTaskSheet)
  108. {
  109. hr = m_spTaskSheet->Close();
  110. m_spTaskSheet.Release();
  111. }
  112. return hr;
  113. }