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.

816 lines
26 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: CstUtils.h */
  4. /* Description: Utilities that we can share across mutliple modules. */
  5. /* Author: David Janecek */
  6. /*************************************************************************/
  7. #ifndef __MSMFCSTUTILS_H_
  8. #define __MSMFCSTUTILS_H_
  9. #ifdef _WMP
  10. #include "wmp.h" // for wmp integration
  11. #endif
  12. const bool gcfGrayOut = false;
  13. #define WM_USER_FOCUS (WM_USER + 0x10)
  14. #define USE_MF_OVERWRITES \
  15. HRESULT InvalidateRgn(bool fErase = false){return MFInvalidateRgn(fErase);} \
  16. HRESULT FireViewChange(){return MFFireViewChange();} \
  17. HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect){return MFInPlaceActivate(iVerb, prcPosRect);} \
  18. HRESULT SetCapture(bool bCapture){return MFSetCapture(bCapture);} \
  19. HRESULT SetFocus(bool bFocus){return MFSetFocus(bFocus);} \
  20. HWND GetWindow(){return MFGetWindow();} \
  21. HRESULT ForwardWindowMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, LONG& lRes,\
  22. bool fForwardInWndls = false){return MFForwardWindowMessage(uMsg, wParam, lParam, lRes, \
  23. fForwardInWndls);}
  24. #define USE_MF_RESOURCEDLL \
  25. STDMETHOD(get_ResourceDLL)(/*[out, retval]*/ BSTR *pVal){return get_MFResourceDLL(pVal);} \
  26. STDMETHOD(put_ResourceDLL)(/*[in]*/ BSTR newVal){return put_MFResourceDLL(newVal);}
  27. #define USE_MF_WINDOWLESS_ACTIVATION \
  28. STDMETHOD(get_Windowless)(VARIANT_BOOL *pVal){return get_MFWindowless(pVal);} \
  29. STDMETHOD(put_Windowless)(VARIANT_BOOL newVal){return put_MFWindowless(newVal);}
  30. #define USE_MF_TRANSPARENT_FLAG \
  31. STDMETHOD(get_TransparentBlit)(TransparentBlitType *pVal){return get_MFTransparentBlit(pVal);}\
  32. STDMETHOD(put_TransparentBlit)(TransparentBlitType newVal){return put_MFTransparentBlit(newVal);}
  33. #define USE_MF_CLASSSTYLE \
  34. static CWndClassInfo& GetWndClassInfo(){ \
  35. static HBRUSH wcBrush = ::CreateSolidBrush(RGB(0,0,0)); \
  36. static CWndClassInfo wc = {{ sizeof(WNDCLASSEX), 0 /*CS_OWNDC*/, StartWindowProc, \
  37. 0, 0, NULL, NULL, NULL, wcBrush /* (HBRUSH)(COLOR_WINDOW + 1) */, \
  38. NULL, TEXT("MSMFCtlClass"), NULL }, \
  39. NULL, NULL, IDC_ARROW, TRUE, 0, _T("") }; \
  40. return wc; \
  41. }/* end of function GetWndClassInfo */
  42. /*************************************************************************/
  43. /* Defines */
  44. /* Could not find these under windows headers, so if there is a conflict */
  45. /* it is good idea to ifdef these out. */
  46. /*************************************************************************/
  47. #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
  48. #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
  49. template <class T>
  50. class ATL_NO_VTABLE CMSMFCntrlUtils{
  51. /*************************************************************************/
  52. /* PUBLIC MEMBER FUNCTIONS */
  53. /*************************************************************************/
  54. public:
  55. /*************************************************************************/
  56. /* Function: CMSMFCntrlUtils */
  57. /*************************************************************************/
  58. CMSMFCntrlUtils(){
  59. m_hRes = NULL;
  60. m_blitType = TRANSPARENT_TOP_LEFT; // DISABLE used to be the correct default TODO
  61. m_fNoFocusGrab = true; // to enable standalone "windowed" focus handeling please
  62. // make this flag a property
  63. }/* end of function CMSMFCntrlUtils */
  64. /*************************************************************************/
  65. /* Function: ~CMSMFCntrlUtils */
  66. /*************************************************************************/
  67. virtual ~CMSMFCntrlUtils(){
  68. if(NULL != m_hRes){
  69. ::FreeLibrary(m_hRes); // unload our resource library
  70. }/* end of if statement */
  71. m_hRes = NULL;
  72. }/* end of function ~CMSMFCntrlUtils */
  73. /*************************************************************************/
  74. /* Message Map */
  75. /*************************************************************************/
  76. typedef CMSMFCntrlUtils< T > thisClass;
  77. BEGIN_MSG_MAP(thisClass)
  78. MESSAGE_HANDLER(WM_ERASEBKGND, CMSMFCntrlUtils::MFOnErase)
  79. END_MSG_MAP()
  80. /*************************************************************************/
  81. /* Function: MFOnErase */
  82. /* Description: Avoids erasing backround to avoid flashing. */
  83. /*************************************************************************/
  84. LRESULT MFOnErase(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  85. bHandled = TRUE;
  86. return 0;
  87. }/* end of function MFOnErase */
  88. /*************************************************************************/
  89. /* Function: get_MFResourceDLL */
  90. /* Description: Returns the string of the loaded resource DLL. */
  91. /*************************************************************************/
  92. STDMETHOD(get_MFResourceDLL)(BSTR *pVal){
  93. *pVal = m_strResDLL.Copy();
  94. return S_OK;
  95. }/* end of function get_MFResourceDLL */
  96. /*************************************************************************/
  97. /* Function: put_MFResourceDLL */
  98. /* Description: Loads the resource DLL. */
  99. /*************************************************************************/
  100. STDMETHOD(put_MFResourceDLL)(BSTR strFileName){
  101. HRESULT hr = LoadResourceDLL(strFileName);
  102. // see if we loaded it
  103. if(FAILED(hr)){
  104. return(hr);
  105. }/* end of if statement */
  106. // update the cached variable value
  107. m_strResDLL = strFileName;
  108. return(hr);
  109. }/* end of function put_MFResourceDLL */
  110. /*************************************************************************/
  111. /* Function: get_MFWindowless */
  112. /* Description: Gets if we we tried to be windowless activated or not. */
  113. /*************************************************************************/
  114. STDMETHODIMP get_MFWindowless(VARIANT_BOOL *pVal){
  115. HRESULT hr = S_OK;
  116. try {
  117. T* pT = static_cast<T*>(this);
  118. if(NULL == pVal){
  119. throw(E_POINTER);
  120. }/* end of if statement */
  121. *pVal = pT->m_bWindowOnly == FALSE ? VARIANT_FALSE: VARIANT_TRUE;
  122. }/* end of try statement */
  123. catch(HRESULT hrTmp){
  124. hr = hrTmp;
  125. }/* end of catch statement */
  126. catch(...){
  127. hr = E_UNEXPECTED;
  128. }/* end of catch statement */
  129. return(hr);
  130. }/* end of function get_MFWindowless */
  131. /*************************************************************************/
  132. /* Function: put_MFWindowless */
  133. /* Description: This sets the windowless mode, should be set from the */
  134. /* property bag. */
  135. /*************************************************************************/
  136. STDMETHODIMP put_MFWindowless(VARIANT_BOOL newVal){
  137. HRESULT hr = S_OK;
  138. try {
  139. T* pT = static_cast<T*>(this);
  140. if(VARIANT_FALSE == newVal){
  141. pT->m_bWindowOnly = TRUE;
  142. }
  143. else {
  144. pT->m_bWindowOnly = FALSE;
  145. }/* end of if statement */
  146. // TODO: This function should fail after we inplace activated !!
  147. }/* end of try statement */
  148. catch(HRESULT hrTmp){
  149. hr = hrTmp;
  150. }/* end of catch statement */
  151. catch(...){
  152. hr = E_UNEXPECTED;
  153. }/* end of catch statement */
  154. return(hr);
  155. }/* end of function put_MFWindowless */
  156. /*************************************************************************/
  157. /* Function: get_MFTransparentBlit */
  158. /* Description: Gets current state of the transperent blit. */
  159. /*************************************************************************/
  160. STDMETHODIMP get_MFTransparentBlit(TransparentBlitType *pVal){
  161. HRESULT hr = S_OK;
  162. try {
  163. T* pT = static_cast<T*>(this);
  164. *pVal = pT->m_blitType;
  165. }
  166. catch(HRESULT hrTmp){
  167. hr = hrTmp;
  168. }/* end of catch statement */
  169. catch(...){
  170. hr = E_UNEXPECTED;
  171. }/* end of catch statement */
  172. return(hr);
  173. }/* end of function get_MFTransparentBlit */
  174. /*************************************************************************/
  175. /* Function: put_MFTransparentBlit */
  176. /* Description: Sets the state of the transperent blit. */
  177. /*************************************************************************/
  178. STDMETHODIMP put_MFTransparentBlit(TransparentBlitType newVal){
  179. HRESULT hr = S_OK;
  180. try {
  181. T* pT = static_cast<T*>(this);
  182. pT->m_blitType = newVal;
  183. }
  184. catch(HRESULT hrTmp){
  185. hr = hrTmp;
  186. }/* end of catch statement */
  187. catch(...){
  188. hr = E_UNEXPECTED;
  189. }/* end of catch statement */
  190. return(hr);
  191. }/* end of function put_MFTransparentBlit */
  192. /*************************************************************************/
  193. /* Function: MFInvalidateRgn */
  194. /* Description: Invalidates the whole rect in case we need to repaint it.*/
  195. /*************************************************************************/
  196. HRESULT MFInvalidateRgn(bool fErase = false){
  197. HRESULT hr = S_OK;
  198. T* pT = static_cast<T*>(this);
  199. if(pT->m_bWndLess){
  200. pT->m_spInPlaceSite->InvalidateRgn(NULL ,fErase ? TRUE: FALSE);
  201. }
  202. else {
  203. if(NULL == pT->m_hWnd){
  204. hr = E_FAIL;
  205. return(hr);
  206. }/* end of if statement */
  207. if(::IsWindow(pT->m_hWnd)){
  208. ::InvalidateRgn(pT->m_hWnd, NULL, fErase ? TRUE: FALSE); // see if we can get by by not erasing..
  209. }
  210. else {
  211. hr = E_UNEXPECTED;
  212. }/* end of if statement */
  213. }/* end of if statement */
  214. return(hr);
  215. }/* end of function MFInvalidateRgn */
  216. /*************************************************************************/
  217. /* Function: MFFireViewChange */
  218. /* Description: Overloaded base function, which would try to repaint the */
  219. /* whole container. Just like to repaint the control area instead. */
  220. /*************************************************************************/
  221. inline HRESULT MFFireViewChange(){ // same as FireView change but optimized
  222. T* pT = static_cast<T*>(this);
  223. if (pT->m_bInPlaceActive){
  224. // Active
  225. if (pT->m_hWndCD != NULL){
  226. ::InvalidateRect(pT->m_hWndCD, NULL, TRUE); // Window based
  227. }
  228. else if (pT->m_spInPlaceSite != NULL){
  229. pT->m_spInPlaceSite->InvalidateRect(&pT->m_rcPos, TRUE); // Do not invalidate the whole container
  230. }/* end of if statement */
  231. }
  232. else {// Inactive
  233. pT->SendOnViewChange(DVASPECT_CONTENT);
  234. }/* end of if statement */
  235. return S_OK;
  236. }/* end of function MFFireViewChange */
  237. /*************************************************************************/
  238. /* Function: MFForwardWindowMessage */
  239. /* Description: Forward the message to the parent window. */
  240. /*************************************************************************/
  241. HRESULT MFForwardWindowMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, LONG& lRes,
  242. bool fForwardInWndls = false){
  243. HRESULT hr = S_OK;
  244. T* pT = static_cast<T*>(this);
  245. lRes = 0;
  246. if(false == fForwardInWndls){
  247. if(pT->m_bWndLess || (!::IsWindow(pT->m_hWnd))){
  248. hr = S_FALSE;
  249. return (hr);
  250. }/* end of if statement */
  251. }/* end of if statement */
  252. HWND hwnd = NULL;
  253. hr = GetParentHWND(&hwnd);
  254. if(FAILED(hr)){
  255. return(hr);
  256. }/* end of if statement */
  257. lRes = ::SendMessage(hwnd, uMsg, wParam, lParam);
  258. return(hr);
  259. }/* end of function MFForwardWindowMessage */
  260. /*************************************************************************/
  261. /* Function: InPlaceActivate */
  262. /* Description: Modified InPlaceActivate so WMP can startup. */
  263. /*************************************************************************/
  264. HRESULT MFInPlaceActivate(LONG iVerb, const RECT* /*prcPosRect*/){
  265. HRESULT hr;
  266. T* pT = static_cast<T*>(this);
  267. if (pT->m_spClientSite == NULL){
  268. return S_OK;
  269. }/* end of if statement */
  270. CComPtr<IOleInPlaceObject> pIPO;
  271. pT->ControlQueryInterface(IID_IOleInPlaceObject, (void**)&pIPO);
  272. ATLASSERT(pIPO != NULL);
  273. if (!pT->m_bNegotiatedWnd){
  274. if (!pT->m_bWindowOnly)
  275. // Try for windowless site
  276. hr = pT->m_spClientSite->QueryInterface(IID_IOleInPlaceSiteWindowless, (void **)&pT->m_spInPlaceSite);
  277. if (pT->m_spInPlaceSite){
  278. pT->m_bInPlaceSiteEx = TRUE;
  279. // CanWindowlessActivate returns S_OK or S_FALSE
  280. if ( pT->m_spInPlaceSite->CanWindowlessActivate() == S_OK ){
  281. pT->m_bWndLess = TRUE;
  282. pT->m_bWasOnceWindowless = TRUE;
  283. }
  284. else
  285. {
  286. pT->m_bWndLess = FALSE;
  287. }/* end of if statement */
  288. }
  289. else {
  290. pT->m_spClientSite->QueryInterface(IID_IOleInPlaceSiteEx, (void **)&pT->m_spInPlaceSite);
  291. if (pT->m_spInPlaceSite)
  292. pT->m_bInPlaceSiteEx = TRUE;
  293. else
  294. hr = pT->m_spClientSite->QueryInterface(IID_IOleInPlaceSite, (void **)&pT->m_spInPlaceSite);
  295. }/* end of if statement */
  296. }/* end of if statement */
  297. ATLASSERT(pT->m_spInPlaceSite);
  298. if (!pT->m_spInPlaceSite)
  299. return E_FAIL;
  300. pT->m_bNegotiatedWnd = TRUE;
  301. if (!pT->m_bInPlaceActive){
  302. BOOL bNoRedraw = FALSE;
  303. if (pT->m_bWndLess)
  304. pT->m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, ACTIVATE_WINDOWLESS);
  305. else {
  306. if (pT->m_bInPlaceSiteEx)
  307. pT->m_spInPlaceSite->OnInPlaceActivateEx(&bNoRedraw, 0);
  308. else {
  309. hr = pT->m_spInPlaceSite->CanInPlaceActivate();
  310. // CanInPlaceActivate returns S_FALSE or S_OK
  311. if (FAILED(hr))
  312. return hr;
  313. if ( hr != S_OK )
  314. {
  315. // CanInPlaceActivate returned S_FALSE.
  316. return( E_FAIL );
  317. }
  318. pT->m_spInPlaceSite->OnInPlaceActivate();
  319. }/* end of if statement */
  320. }/* end of if statement */
  321. }/* end of if statement */
  322. pT->m_bInPlaceActive = TRUE;
  323. // get location in the parent window,
  324. // as well as some information about the parent
  325. //
  326. OLEINPLACEFRAMEINFO frameInfo;
  327. RECT rcPos, rcClip;
  328. CComPtr<IOleInPlaceFrame> spInPlaceFrame;
  329. CComPtr<IOleInPlaceUIWindow> spInPlaceUIWindow;
  330. frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  331. HWND hwndParent;
  332. // DJ - GetParentHWND per MNnovak
  333. if (SUCCEEDED( GetParentHWND(&hwndParent) )){
  334. pT->m_spInPlaceSite->GetWindowContext(&spInPlaceFrame,
  335. &spInPlaceUIWindow, &rcPos, &rcClip, &frameInfo);
  336. if (!pT->m_bWndLess){
  337. if (pT->m_hWndCD){
  338. ::ShowWindow(pT->m_hWndCD, SW_SHOW);
  339. if (!::IsChild(pT->m_hWndCD, ::GetFocus()))
  340. ::SetFocus(pT->m_hWndCD);
  341. }
  342. else{
  343. HWND h = pT->CreateControlWindow(hwndParent, rcPos);
  344. ATLASSERT(h != NULL); // will assert if creation failed
  345. ATLASSERT(h == pT->m_hWndCD);
  346. h; // avoid unused warning
  347. }/* end of if statement */
  348. }/* end of if statement */
  349. pIPO->SetObjectRects(&rcPos, &rcClip);
  350. }/* end of if statement */
  351. CComPtr<IOleInPlaceActiveObject> spActiveObject;
  352. pT->ControlQueryInterface(IID_IOleInPlaceActiveObject, (void**)&spActiveObject);
  353. // Gone active by now, take care of UIACTIVATE
  354. if (pT->DoesVerbUIActivate(iVerb)){
  355. if (!pT->m_bUIActive){
  356. pT->m_bUIActive = TRUE;
  357. hr = pT->m_spInPlaceSite->OnUIActivate();
  358. if (FAILED(hr))
  359. return hr;
  360. pT->SetControlFocus(TRUE);
  361. // set ourselves up in the host.
  362. //
  363. if (spActiveObject)
  364. {
  365. if (spInPlaceFrame)
  366. spInPlaceFrame->SetActiveObject(spActiveObject, NULL);
  367. if (spInPlaceUIWindow)
  368. spInPlaceUIWindow->SetActiveObject(spActiveObject, NULL);
  369. }
  370. if (spInPlaceFrame)
  371. spInPlaceFrame->SetBorderSpace(NULL);
  372. if (spInPlaceUIWindow)
  373. spInPlaceUIWindow->SetBorderSpace(NULL);
  374. }/* end of if statement */
  375. }/* end of if statement */
  376. pT->m_spClientSite->ShowObject();
  377. return S_OK;
  378. }/* end of function MFInPlaceActivate */
  379. /*************************************************************************/
  380. /* PROTECTED MEMBER FUNCTIONS */
  381. /*************************************************************************/
  382. protected:
  383. /*************************************************************************/
  384. /* Function: MFGetWindow */
  385. /* Description: Gets the window. If we are windowless we pass */
  386. /* down the parent container window, which is really in a sense parent. */
  387. /*************************************************************************/
  388. HWND MFGetWindow(){
  389. HWND hwnd = NULL;
  390. T* pT = static_cast<T*>(this);
  391. if(pT->m_bWndLess){
  392. GetParentHWND(&hwnd);
  393. return(hwnd);
  394. }/* end of if statement */
  395. //ATLASSERT(::IsWindow(m_hWnd));
  396. return pT->m_hWnd;
  397. }/* end of function MFGetWindow */
  398. /*************************************************************************/
  399. /* Function: GetParentHWND */
  400. /* Description: Gets the parent window HWND where we are operating. */
  401. /*************************************************************************/
  402. HRESULT GetParentHWND(HWND* pWnd){
  403. HRESULT hr = S_OK;
  404. T* pT = static_cast<T*>(this);
  405. IOleClientSite *pClientSite;
  406. IOleContainer *pContainer;
  407. IOleObject *pObject;
  408. hr = pT->GetClientSite(&pClientSite);
  409. if(FAILED(hr)){
  410. return(hr);
  411. }/* end of if statement */
  412. IOleWindow *pOleWindow;
  413. do {
  414. hr = pClientSite->QueryInterface(IID_IOleWindow, (LPVOID *) &pOleWindow);
  415. if(FAILED(hr)){
  416. return(hr);
  417. }/* end of if statement */
  418. hr = pOleWindow->GetWindow(pWnd);
  419. pOleWindow->Release();
  420. // if pClientSite is windowless, go get its container
  421. if (FAILED(hr)) {
  422. HRESULT hrTemp = pClientSite->GetContainer(&pContainer);
  423. if(FAILED(hrTemp)){
  424. return(hrTemp);
  425. }/* end of if statement */
  426. pClientSite->Release();
  427. hrTemp = pContainer->QueryInterface(IID_IOleObject, (LPVOID*)&pObject);
  428. if(FAILED(hrTemp)){
  429. return(hrTemp);
  430. }/* end of if statement */
  431. pContainer->Release();
  432. hrTemp = pObject->GetClientSite(&pClientSite);
  433. if(FAILED(hrTemp)){
  434. return(hrTemp);
  435. }/* end of if statement */
  436. }
  437. } while (FAILED(hr));
  438. pClientSite->Release();
  439. return(hr);
  440. }/* end of function GetParentHWND */
  441. /*************************************************************************/
  442. /* Function: GetCapture */
  443. /* Description: Gets the capture state. S_FALSE no capture S_OK has */
  444. /* capture. */
  445. /*************************************************************************/
  446. HRESULT GetCapture(){
  447. HRESULT hr = E_UNEXPECTED;
  448. T* pT = static_cast<T*>(this);
  449. if(pT->m_bWndLess){
  450. hr = pT->m_spInPlaceSite->GetCapture();
  451. }
  452. else {
  453. if(NULL == pT->m_hWnd){
  454. hr = E_FAIL;
  455. return(hr);
  456. }/* end of if statement */
  457. if(::IsWindow(pT->m_hWnd)){
  458. HWND h = ::GetCapture();
  459. if(pT->m_hWnd == h){
  460. hr = S_OK;
  461. }
  462. else {
  463. hr = S_FALSE;
  464. }/* end of if statement */
  465. }
  466. else {
  467. hr = E_UNEXPECTED;
  468. }/* end of if statement */
  469. }/* end of if statement */
  470. return(hr);
  471. }/* end of function GetCapture */
  472. /*************************************************************************/
  473. /* Function: GetFocus */
  474. /* Description: Gets the focus state. S_FALSE no capture S_OK has */
  475. /* a focus. */
  476. /*************************************************************************/
  477. HRESULT GetFocus(){
  478. HRESULT hr = E_UNEXPECTED;
  479. T* pT = static_cast<T*>(this);
  480. if(pT->m_bWndLess || m_fNoFocusGrab){
  481. hr = pT->m_spInPlaceSite->GetFocus();
  482. }
  483. else {
  484. if(NULL == pT->m_hWnd){
  485. hr = E_FAIL;
  486. return(hr);
  487. }/* end of if statement */
  488. if(::IsWindow(pT->m_hWnd)){
  489. HWND h = ::GetFocus();
  490. if(pT->m_hWnd == h){
  491. hr = S_OK;
  492. }
  493. else {
  494. hr = S_FALSE;
  495. }/* end of if statement */
  496. }
  497. else {
  498. hr = E_UNEXPECTED;
  499. }/* end of if statement */
  500. }/* end of if statement */
  501. return(hr);
  502. }/* end of function GetFocus */
  503. /*************************************************************************/
  504. /* Function: MFSetFocus */
  505. /* Description: Sets the focus for the keyboard. */
  506. /*************************************************************************/
  507. HRESULT MFSetFocus(bool fFocus){
  508. HRESULT hr = S_OK;
  509. T* pT = static_cast<T*>(this);
  510. if(pT->m_bWndLess || m_fNoFocusGrab){
  511. pT->m_spInPlaceSite->SetFocus(fFocus ? TRUE: FALSE);
  512. }
  513. else {
  514. if(NULL == pT->m_hWnd){
  515. hr = E_FAIL;
  516. return(hr);
  517. }/* end of if statement */
  518. if(::IsWindow(pT->m_hWnd)){
  519. if(fFocus){
  520. ::SetFocus(pT->m_hWnd);
  521. }
  522. else {
  523. }/* end of if statement */
  524. }
  525. else {
  526. hr = E_UNEXPECTED;
  527. }/* end of if statement */
  528. }/* end of if statement */
  529. return(hr);
  530. }/* end of function MFSetFocus */
  531. /*************************************************************************/
  532. /* Function: MFSetCapture */
  533. /* Description: Sets the capture for the mouse. */
  534. /*************************************************************************/
  535. HRESULT MFSetCapture(bool bCapture){
  536. HRESULT hr = S_OK;
  537. T* pT = static_cast<T*>(this);
  538. #ifdef _DEBUG
  539. if(bCapture){
  540. ATLTRACE("SETTING mouse capture! \n");
  541. }
  542. else {
  543. ATLTRACE("RELEASING mouse capture! \n");
  544. }/* end of if statement */
  545. #endif
  546. if(pT->m_bWndLess){
  547. pT->m_spInPlaceSite->SetCapture(bCapture ? TRUE: FALSE);
  548. }
  549. else {
  550. if(NULL == pT->m_hWnd){
  551. hr = E_FAIL;
  552. return(hr);
  553. }/* end of if statement */
  554. if(::IsWindow(pT->m_hWnd)){
  555. if(bCapture){
  556. ::SetCapture(pT->m_hWnd);
  557. }
  558. else {
  559. // note this might case problems if multiple ActiveX controls
  560. // in the container have a capture
  561. ::ReleaseCapture();
  562. }/* end of if statement */
  563. }
  564. else {
  565. hr = E_UNEXPECTED;
  566. }/* end of if statement */
  567. }/* end of if statement */
  568. return(hr);
  569. }/* end of function MFSetCapture */
  570. /*************************************************************************/
  571. /* Function: LoadResourceDLL */
  572. /* Description: The path is relative to this module exe */
  573. /*************************************************************************/
  574. HRESULT LoadResourceDLL(BSTR strResDLLName){
  575. HRESULT hr = E_UNEXPECTED;
  576. if(NULL != m_hRes){
  577. ::FreeLibrary(m_hRes); // unload our resource library if we had some loaded
  578. }/* end of if statement */
  579. #if 0 // use relative path
  580. TCHAR szModule[_MAX_PATH+10];
  581. ::GetModuleFileName(_Module.m_hInstResource, szModule, _MAX_PATH);
  582. *( _tcsrchr( szModule, '\\' ) + 1 ) = TEXT('\0');
  583. // now attempt to load the library, since it is not ActiveX control
  584. USES_CONVERSION;
  585. _tcscat( szModule, OLE2T(strResDLLName));
  586. m_hRes = ::LoadLibrary(szModule);
  587. #else
  588. USES_CONVERSION;
  589. m_hRes = ::LoadLibrary(OLE2T(strResDLLName));
  590. #endif
  591. if (!m_hRes){
  592. hr = HRESULT_FROM_WIN32(::GetLastError());
  593. ATLTRACE(TEXT("Failed to load resource DLL\n"));
  594. }
  595. else {
  596. hr = S_OK;
  597. }/* end of if statement */
  598. return (hr);
  599. }/* end of function LoadResourceDLL */
  600. // variables
  601. protected:
  602. HINSTANCE m_hRes;
  603. CComBSTR m_strResDLL;
  604. TransparentBlitType m_blitType;
  605. bool m_fNoFocusGrab; // disable grabbing focus for windowed controls
  606. };
  607. #endif //__MSMFCSTUTILS_H_
  608. /*************************************************************************/
  609. /* End of file: CstUtils.h */
  610. /*************************************************************************/