XPropertiesWnd.cpp
上传用户:yangzi5763
上传日期:2007-01-02
资源大小:239k
文件大小:5k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. /************************************
  2.   REVISION LOG ENTRY
  3.   Revision By: Mihai Filimon
  4.   Revised on 11/19/98 12:06:34 AM
  5.   Comments: XPropertiesWnd.cpp : Implementation of CXPropertiesWndApp and DLL registration.
  6.  ************************************/
  7. #include "stdafx.h"
  8. #include "XPropertiesWnd.h"
  9. #include "gdi.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. CXPropertiesWndApp NEAR theApp;
  16. const GUID CDECL BASED_CODE _tlid =
  17. { 0x7b914a58, 0x6271, 0x11d2, { 0x86, 0xb8, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9 } };
  18. const WORD _wVerMajor = 1;
  19. const WORD _wVerMinor = 0;
  20. const TCHAR _cPagesSeparator = TCHAR('#');
  21. const UINT _nIDFirstListView = 1000;
  22. ////////////////////////////////////////////////////////////////////////////
  23. // CXPropertiesWndApp::InitInstance - DLL initialization
  24. BOOL CXPropertiesWndApp::InitInstance()
  25. {
  26. BOOL bInit = COleControlModule::InitInstance();
  27. if (bInit)
  28. {
  29. AfxEnableControlContainer();
  30. }
  31. return bInit;
  32. }
  33. ////////////////////////////////////////////////////////////////////////////
  34. // CXPropertiesWndApp::ExitInstance - DLL termination
  35. int CXPropertiesWndApp::ExitInstance()
  36. {
  37. return COleControlModule::ExitInstance();
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Function name : RegisterActiveX
  41. // Description     : Call to register ActiveX control
  42. // Return type : BOOL 
  43. // Argument         : LPCTSTR lpszActiveXFileName
  44. BOOL RegisterActiveX(LPCTSTR lpszActiveXFileName, LPCTSTR lpszFRegister = _T("DllRegisterServer"))
  45. {
  46. HINSTANCE hInstance = NULL;
  47. CString sAXFileName(lpszActiveXFileName);
  48. static TCHAR BASED_CODE szFilter[] = _T("ActiveX Controls (*.ocx)|*.ocx||");
  49. do 
  50. {
  51. if ((hInstance = LoadLibrary(sAXFileName)) == NULL)
  52. {
  53. CString warning;
  54. warning.Format(_T("Load library not found, or failed."));
  55. AfxMessageBox(warning);
  56. CFileDialog fd(TRUE, NULL, sAXFileName, NULL, szFilter , NULL);
  57. if (fd.DoModal() == IDOK)
  58. sAXFileName = fd.GetFileName();
  59. else break;
  60. }
  61. else
  62. {
  63. FARPROC lpDllEntryPoint = GetProcAddress(hInstance, (LPCSTR)lpszFRegister);
  64. if (lpDllEntryPoint != NULL)
  65. {
  66. (*lpDllEntryPoint)();
  67. return TRUE;
  68. }
  69. else
  70. {
  71. FreeLibrary(hInstance);
  72. hInstance = NULL;
  73. }
  74. }
  75. } while (hInstance == NULL);
  76. return FALSE;
  77. }
  78. // Function name : Preview
  79. // Description     : preview a window into a bitmap
  80. // Return type : CBitmap* 
  81. // Argument         : CWnd* pWnd
  82. // Argument         : COLORREF colorBkGnd
  83. CBitmap* Preview(CWnd* pWnd, COLORREF colorBkGnd)
  84. {
  85. CBitmap *pBitmap = NULL, bitmapNonClient;
  86. CWnd *pDrawWnd = pWnd;
  87. ASSERT (pWnd);
  88. if (pDrawWnd && ::IsWindow(pDrawWnd->m_hWnd))
  89. {
  90. CRect rectWindow; pDrawWnd->GetWindowRect(rectWindow);
  91. CRect rectClient; pDrawWnd->GetClientRect(rectClient);
  92. CPoint p(0,0);
  93. pDrawWnd->ClientToScreen(&p);
  94. rectClient.OffsetRect(p.x - rectWindow.left, p.y - rectWindow.top);
  95. CGdiStack stack;
  96. CDC* pDC = pDrawWnd->GetDC();
  97. CDC dcMemSourceNonClient, dcMemDestination;
  98. if (dcMemSourceNonClient.CreateCompatibleDC(pDC))
  99. if (dcMemDestination.CreateCompatibleDC(pDC))
  100. if (pBitmap = new CBitmap())
  101. if (pBitmap->CreateCompatibleBitmap(pDC, rectWindow.Width(), rectWindow.Height()))
  102. if (bitmapNonClient.CreateCompatibleBitmap(pDC, rectWindow.Width(), rectWindow.Height()))
  103. {
  104. CBrush brBkGnd(colorBkGnd);
  105. stack.Push(&dcMemSourceNonClient, &bitmapNonClient);
  106. stack.Push(&dcMemSourceNonClient, &brBkGnd);
  107. dcMemSourceNonClient.PatBlt(0,0,rectWindow.Width(), rectWindow.Height(), PATCOPY);
  108. stack.Push(&dcMemDestination, pBitmap);
  109. if (pWnd)
  110. pDrawWnd->Print(&dcMemSourceNonClient, PRF_NONCLIENT);
  111. dcMemDestination.BitBlt(0,0,rectWindow.Width(), rectWindow.Height(), &dcMemSourceNonClient, 0,0, SRCCOPY);
  112. if (pWnd)
  113. {
  114. CPoint pLT(0,0);
  115. pDrawWnd->ClientToScreen(&pLT);
  116. dcMemDestination.SetViewportOrg(pLT.x - rectWindow.left, pLT.y - rectWindow.top);
  117. pDrawWnd->Print(&dcMemDestination, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND);
  118. }
  119. stack.Pop();
  120. stack.Pop();
  121. stack.Pop();
  122. brBkGnd.DeleteObject();
  123. bitmapNonClient.DeleteObject();
  124. dcMemSourceNonClient.DeleteDC();
  125. dcMemDestination.DeleteDC();
  126. }
  127. pDrawWnd->ReleaseDC(pDC);
  128. }
  129. return pBitmap;
  130. }
  131. // DllRegisterServer - Adds entries to the system registry
  132. // Function name : DllRegisterServer
  133. // Description     : Call to register ActiveX control
  134. // Return type : STDAPI 
  135. // Argument         : void
  136. STDAPI DllRegisterServer(void)
  137. {
  138. AFX_MANAGE_STATE(_afxModuleAddrThis);
  139. /* if (!RegisterActiveX(_T("xFloorWnd.ocx")))
  140. return ResultFromScode(SELFREG_E_TYPELIB);*/
  141. if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
  142. return ResultFromScode(SELFREG_E_TYPELIB);
  143. if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  144. return ResultFromScode(SELFREG_E_CLASS);
  145. return NOERROR;
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. // DllUnregisterServer - Removes entries from the system registry
  149. STDAPI DllUnregisterServer(void)
  150. {
  151. AFX_MANAGE_STATE(_afxModuleAddrThis);
  152. if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
  153. return ResultFromScode(SELFREG_E_TYPELIB);
  154. if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  155. return ResultFromScode(SELFREG_E_CLASS);
  156. return NOERROR;
  157. }