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.

151 lines
5.4 KiB

  1. // WzScrEng.cpp : Implementation of CWizardScriptingEngine
  2. #include "stdafx.h"
  3. #include "WizChain.h"
  4. #include "WzScrEng.h"
  5. // local proto(s)
  6. HBITMAP LoadPicture (LPOLESTR szURLorPath, long lWidth, long lHeight);
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CWizardScriptingEngine
  9. STDMETHODIMP CWizardScriptingEngine::Initialize(BSTR bstrWatermarkBitmapFile, BSTR bstrHeaderBitmapFile, BSTR bstrTitle, BSTR bstrHeader, BSTR bstrText, BSTR bstrFinishHeader, BSTR bstrFinishIntroText, BSTR bstrFinishText)
  10. {
  11. if (m_pCW != NULL)
  12. return E_UNEXPECTED; // should only be called once
  13. HRESULT hr = CComObject<CChainWiz>::CreateInstance (&m_pCW);
  14. if (hr != S_OK)
  15. return hr;
  16. if (!m_pCW)
  17. return E_FAIL;
  18. m_pCW->AddRef(); // CreateInstance above doesn't addref
  19. // try bitmaps first
  20. m_hbmLarge = (HBITMAP)LoadImageW (NULL, // no hinstance when loading from file
  21. (LPWSTR)bstrWatermarkBitmapFile, // filename
  22. IMAGE_BITMAP, // type of image
  23. 0, 0, // size (width and height)
  24. LR_LOADFROMFILE);
  25. m_hbmSmall = (HBITMAP)LoadImageW (NULL, // no hinstance when loading from file
  26. (LPWSTR)bstrHeaderBitmapFile, // filename
  27. IMAGE_BITMAP, // type of image
  28. 0, 0, // size (width and height)
  29. LR_LOADFROMFILE);
  30. // use IPicture
  31. if(!m_hbmLarge)
  32. m_hbmLarge = LoadPicture ((LPOLESTR)bstrWatermarkBitmapFile, 0, 0);
  33. if(!m_hbmSmall)
  34. m_hbmSmall = LoadPicture ((LPOLESTR)bstrHeaderBitmapFile, 49, 49);
  35. // TODO: should I add defaults when LoadImage calls above fail?
  36. hr = m_pCW->Initialize (m_hbmLarge, m_hbmSmall, (LPOLESTR)bstrTitle, (LPOLESTR)bstrHeader, (LPOLESTR)bstrText, (LPOLESTR)bstrFinishHeader, (LPOLESTR)bstrFinishIntroText, (LPOLESTR)bstrFinishText);
  37. return hr;
  38. }
  39. STDMETHODIMP CWizardScriptingEngine::AddWizardComponent(BSTR bstrClassIdOrProgId)
  40. {
  41. if (m_pCW == NULL)
  42. return E_UNEXPECTED;
  43. // if progid, get clsid
  44. OLECHAR * p = (OLECHAR *)bstrClassIdOrProgId;
  45. if (*p != L'{') {
  46. CLSID clsid;
  47. HRESULT hr = CLSIDFromProgID ((LPCOLESTR)bstrClassIdOrProgId, &clsid);
  48. if (hr != S_OK)
  49. return hr;
  50. OLECHAR szClsid[50]; // find a define for this
  51. StringFromGUID2 (clsid, szClsid, sizeof(szClsid)/sizeof(OLECHAR));
  52. return m_pCW->AddWizardComponent (szClsid);
  53. } else
  54. return m_pCW->AddWizardComponent ((LPOLESTR)bstrClassIdOrProgId);
  55. }
  56. STDMETHODIMP CWizardScriptingEngine::DoModal(long *lRet)
  57. {
  58. if (m_pCW == NULL)
  59. return E_UNEXPECTED;
  60. return m_pCW->DoModal (lRet);
  61. }
  62. STDMETHODIMP CWizardScriptingEngine::get_ScriptablePropertyBag(IDispatch **pVal)
  63. {
  64. if (m_pCW == NULL)
  65. return E_UNEXPECTED;
  66. return m_pCW->get_PropertyBag (pVal);
  67. }
  68. HBITMAP LoadPicture (LPOLESTR szURLorPath, long lWidth, long lHeight)
  69. { // idea: load picture using OleLoadPicturePath
  70. // play into memory dc, get back a hbitmap
  71. HBITMAP hbm = NULL;
  72. IPicture * pPic = NULL;
  73. HRESULT hr = OleLoadPicturePath (szURLorPath,
  74. NULL, // LPUNKNOWN punkCaller,
  75. 0, // DWORD dwReserved,
  76. (OLE_COLOR)-1, // OLE_COLOR clrReserved,
  77. __uuidof(IPicture), // REFIID
  78. (void**)&pPic); // LPVOID *
  79. if (pPic) {
  80. OLE_XSIZE_HIMETRIC xhi;
  81. OLE_YSIZE_HIMETRIC yhi;
  82. pPic->get_Width (&xhi);
  83. pPic->get_Height(&yhi);
  84. SIZEL him, pixel = {0};
  85. him.cx = xhi;
  86. him.cy = yhi;
  87. AtlHiMetricToPixel (&him, &pixel);
  88. if (lWidth == 0) lWidth = pixel.cx;
  89. if (lHeight == 0) lHeight = pixel.cy;
  90. HDC hdcNULL = GetDC (NULL);
  91. HDC hdc = CreateCompatibleDC (hdcNULL);
  92. hbm = CreateCompatibleBitmap (hdcNULL, lWidth, lHeight);
  93. ReleaseDC (NULL, hdcNULL);
  94. HBITMAP holdbm = (HBITMAP)SelectObject (hdc, (HGDIOBJ)hbm);
  95. // do palette action if any
  96. HPALETTE hpal = NULL;
  97. HPALETTE holdpal = NULL;
  98. hr = pPic->get_hPal ((OLE_HANDLE *)&hpal);
  99. if( SUCCEEDED(hr) && hpal)
  100. {
  101. holdpal = SelectPalette (hdc, hpal, FALSE);
  102. RealizePalette (hdc);
  103. hr = pPic->Render (hdc,
  104. 0,
  105. lHeight-1, // 0,
  106. lWidth,
  107. -lHeight, // lHeight,
  108. 0, 0,
  109. xhi, yhi,
  110. NULL); // lpcrect used only if metafiledc
  111. }
  112. SelectObject (hdc, (HGDIOBJ)holdbm);
  113. if (holdpal) {
  114. SelectPalette (hdc, holdpal, FALSE);
  115. DeleteObject ((HGDIOBJ)hpal);
  116. }
  117. if (hr != S_OK) {
  118. DeleteObject ((HGDIOBJ)hbm);
  119. hbm = NULL;
  120. }
  121. if( NULL != hdc )
  122. {
  123. ReleaseDC (NULL, hdc);
  124. }
  125. pPic->Release();
  126. }
  127. return hbm;
  128. }