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.

163 lines
5.7 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: MSMFImg.cpp */
  4. /* Description: Implementation of CMSMFImg Static Image class */
  5. /* Author: David Janecek */
  6. /*************************************************************************/
  7. #include "stdafx.h"
  8. #include "MSMFCnt.h"
  9. #include "MSMFImg.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CMSMFImg
  12. /*************************************************************************/
  13. /* Function: CMSMFImg */
  14. /*************************************************************************/
  15. CMSMFImg::CMSMFImg(){
  16. Init();
  17. }/* end of function CMSMFSldr */
  18. /*************************************************************************/
  19. /* Function: Init */
  20. /* Description: Initializes variable states. */
  21. /*************************************************************************/
  22. void CMSMFImg::Init(){
  23. m_blitType = DISABLE;
  24. m_clrBackColor = ::GetSysColor(COLOR_BTNFACE);
  25. #if 0 // used for getting the windowed case working DJ
  26. m_bWindowOnly = TRUE;
  27. #endif
  28. }/* end of function Init */
  29. /*************************************************************************/
  30. /* Function: ~CMSMFImg */
  31. /* Description: Cleanup the stuff we allocated here rest will be done */
  32. /* in the button destructor. */
  33. /*************************************************************************/
  34. CMSMFImg::~CMSMFImg(){
  35. //Init();
  36. ATLTRACE(TEXT("In the IMG Object destructor!\n"));
  37. }/* end of function CMSMFSldr */
  38. /*************************************************************************/
  39. /* Function: OnDraw */
  40. /* Description: Does the basic drawing */
  41. /* First draws the background the the thumb at the specific position. */
  42. /*************************************************************************/
  43. HRESULT CMSMFImg::OnDraw(ATL_DRAWINFO& di){
  44. HRESULT hr = S_OK;
  45. BOOL bRet = TRUE;
  46. HDC hdc = di.hdcDraw;
  47. RECT rcClient = *(RECT*)di.prcBounds;
  48. HPALETTE hNewPal = NULL;
  49. if (!m_BackBitmap.IsEmpty()){
  50. hNewPal = CBitmap::GetSuperPal();
  51. }
  52. else {
  53. hNewPal = m_BackBitmap.GetPal();
  54. }/* end of if statement */
  55. if (::IsWindow(m_hWnd)){ //in other words not windowless
  56. CBitmap::SelectRelizePalette(hdc, hNewPal);
  57. }/* end of if statement */
  58. // DRAW THE BACKGROUND
  59. if (!m_BackBitmap.IsEmpty()){
  60. bRet = m_BackBitmap.PaintTransparentDIB(hdc, &rcClient,
  61. &rcClient);
  62. }
  63. else {
  64. COLORREF clr;
  65. ::OleTranslateColor (m_clrBackColor, CBitmap::GetSuperPal(), &clr);
  66. HBRUSH hbrBack = ::CreateSolidBrush(clr);
  67. if(NULL == hbrBack){
  68. hr = E_FAIL;
  69. return(hr);
  70. }/* end of if statement */
  71. ::FillRect(hdc, &rcClient, hbrBack);
  72. ::DeleteObject(hbrBack);
  73. }/* end of if statement */
  74. return (hr);
  75. }/* end of function OnDraw */
  76. /*************************************************************************/
  77. /* Function: OnDispChange */
  78. /* Description: Forwards this message to all the controls. */
  79. /*************************************************************************/
  80. LRESULT CMSMFImg::OnDispChange(UINT uMsg, WPARAM wParam, LPARAM lParam,
  81. BOOL& bHandled){
  82. LONG lRes =0;
  83. long cBitsPerPixel = (long) wParam;
  84. long cxScreen = LOWORD(lParam);
  85. long cyScreen = HIWORD(lParam);
  86. m_BackBitmap.OnDispChange(cBitsPerPixel, cxScreen, cyScreen);
  87. return(lRes);
  88. }/* end of function OnDispChange */
  89. /*************************************************************************/
  90. /* Function: PutImage */
  91. /* Description: Sets the image of the background. */
  92. /*************************************************************************/
  93. HRESULT CMSMFImg::PutImage(BSTR strFilename){
  94. HRESULT hr = S_OK;
  95. m_bstrBackFilename = strFilename;
  96. bool fGrayOut = false;
  97. hr = m_BackBitmap.PutImage(strFilename, m_hRes, FALSE, m_blitType,
  98. MAINTAIN_ASPECT_RATIO);
  99. if(FAILED(hr)){
  100. return(hr);
  101. }/* end of if statement */
  102. InvalidateRgn(); // our helper function
  103. return(hr);
  104. }/* end of function PutImage */
  105. /*************************************************************************/
  106. /* Function: get_Image */
  107. /*************************************************************************/
  108. STDMETHODIMP CMSMFImg::get_Image(BSTR *pstrFilename){
  109. *pstrFilename = m_bstrBackFilename.Copy();
  110. return S_OK;
  111. }/* end of function get_Image */
  112. /*************************************************************************/
  113. /* Function: put_Image */
  114. /*************************************************************************/
  115. STDMETHODIMP CMSMFImg::put_Image(BSTR strFilename){
  116. return (PutImage(strFilename));
  117. }/* end of function put_BackStatic */
  118. /*************************************************************************/
  119. /* End of file: MSMFImg.cpp */
  120. /*************************************************************************/