📄 polyprop.cpp
字号:
/*
* POLYPROP.CPP
* Polyline Property Page Chapter 24
*
* Server module code and class code CPolyPropertyPage class.
*
* Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Microsoft
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#define INITGUIDS
#include "polyprop.h"
//Count number of objects and number of locks.
ULONG g_cObj=0;
ULONG g_cLock=0;
HINSTANCE g_hInst=NULL; //For resources
#ifdef WIN32
TCHAR g_szObj[]=TEXT("Object");
#else
TCHAR g_szObjHi[]=TEXT("ObjectHi");
TCHAR g_szObjLo[]=TEXT("ObjectLo");
#endif
/*
* LibMain(32)
*
* Purpose:
* Entry point conditionally compiled for Win32 and Windows
* 3.1. Provides the proper structure for each environment.
*/
#ifdef WIN32
BOOL WINAPI LibMain32(HINSTANCE hInstance, ULONG ulReason
, LPVOID pvReserved)
{
g_hInst=hInstance;
if (DLL_PROCESS_DETACH==ulReason)
{
return TRUE;
}
else
{
if (DLL_PROCESS_ATTACH!=ulReason)
return TRUE;
}
return TRUE;
}
#else
int PASCAL LibMain(HINSTANCE hInstance, WORD wDataSeg
, WORD cbHeapSize, LPSTR lpCmdLine)
{
if (0!=cbHeapSize)
UnlockData(0);
g_hInst=hInstance;
return (int)hInstance;
}
#endif
/*
* DllGetClassObject
* DllCanUnloadNow
* Standard COM exports for DLL servers.
*/
HRESULT APIENTRY DllGetClassObject(REFCLSID rclsid, REFIID riid
, PPVOID ppv)
{
CPolyPPFactory *pPF;
HRESULT hr;
if (CLSID_PolylinePropPage!=rclsid)
return ResultFromScode(E_FAIL);
//Check that we can provide the interface
if (IID_IUnknown!=riid && IID_IClassFactory!=riid)
return ResultFromScode(E_NOINTERFACE);
//Return our factory's IClassFactory
pPF=new CPolyPPFactory();
if (NULL==pPF)
return ResultFromScode(E_OUTOFMEMORY);
//If the factory hasn't the interface, delete it
hr=pPF->QueryInterface(riid, ppv);
if (FAILED(hr))
delete pPF;
else
g_cObj++;
return hr;
}
STDAPI DllCanUnloadNow(void)
{
SCODE sc;
//Our answer is whether there are any object or locks
sc=(0L==g_cObj && 0L==g_cLock) ? S_OK : S_FALSE;
return ResultFromScode(sc);
}
/*
* CPolyPPFactory::CPolyPPFactory
* CPolyPPFactory::~CPolyPPFactory
* CPolyPPFactory::QueryInterface
* CPolyPPFactory::AddRef
* CPolyPPFactory::Release
*/
CPolyPPFactory::CPolyPPFactory(void)
{
m_cRef=0L;
return;
}
CPolyPPFactory::~CPolyPPFactory(void)
{
return;
}
STDMETHODIMP CPolyPPFactory::QueryInterface(REFIID riid, PPVOID ppv)
{
*ppv=NULL;
if (IID_IUnknown==riid || IID_IClassFactory==riid)
*ppv=this;
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CPolyPPFactory::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CPolyPPFactory::Release(void)
{
if (0!=--m_cRef)
return m_cRef;
delete this;
g_cObj--;
return 0;
}
/*
* CPolyPPFactory::CreateInstance
* CPolyPPFactory::LockServer
*/
STDMETHODIMP CPolyPPFactory::CreateInstance(LPUNKNOWN pUnkOuter
, REFIID riid, PPVOID ppvObj)
{
PCPolyPropPage pObj;
HRESULT hr;
*ppvObj=NULL;
hr=ResultFromScode(E_OUTOFMEMORY);
//No aggregation supported
if (NULL!=pUnkOuter)
return ResultFromScode(CLASS_E_NOAGGREGATION);
//Create the object passing function to notify on destruction.
pObj=new CPolyPropPage(g_hInst);
if (NULL==pObj)
return hr;
if (pObj->Init())
hr=pObj->QueryInterface(riid, ppvObj);
//Kill the object if initial creation or Init failed.
if (FAILED(hr))
delete pObj;
else
g_cObj++;
return hr;
}
STDMETHODIMP CPolyPPFactory::LockServer(BOOL fLock)
{
if (fLock)
g_cLock++;
else
g_cLock--;
return NOERROR;
}
/***
*** CPolyPropPage implementation
***/
/*
* CPolyPropPage::CPolyPropPage
* CPolyPropPage::~CPolyPropPage
*
* Constructor Parameters:
* hInst HINSTANCE of the module
*/
CPolyPropPage::CPolyPropPage(HINSTANCE hInst)
{
m_cRef=0L;
m_hInst=hInst;
m_hDlg=NULL;
//Default sizes
m_cx=300;
m_cy=100;
m_pIPropertyPageSite=NULL;
m_ppObj=NULL;
m_cObjects=0;
m_uIDLastLine=ID_LINESOLID;
m_crLastBack=0;
m_crLastLine=0;
m_fDirty=FALSE;
return;
}
CPolyPropPage::~CPolyPropPage(void)
{
if (NULL!=m_hDlg)
DestroyWindow(m_hDlg);
FreeAllObjects();
ReleaseInterface(m_pIPropertyPageSite);
return;
}
/*
* CPolyPropPage::QueryInterface
* CPolyPropPage::AddRef
* CPolyPropPage::Release
*/
STDMETHODIMP CPolyPropPage::QueryInterface(REFIID riid, PPVOID ppv)
{
*ppv=NULL;
if (IID_IUnknown==riid || IID_IPropertyPage==riid)
*ppv=this;
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CPolyPropPage::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CPolyPropPage::Release(void)
{
if (0!=--m_cRef)
return m_cRef;
g_cObj--;
delete this;
return 0;
}
/*
* CPolyPropPage::Init
*
* Purpose:
* Performs initialization operations that might fail.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if initialization successful, FALSE
* otherwise.
*/
BOOL CPolyPropPage::Init(void)
{
//Nothing to do
return TRUE;
}
/*
* CPolyPropPage::FreeAllObjects
*
* Purpose:
* Releases all the objects from IPropertyPage::SetObjects
*
* Parameters:
* None
*/
void CPolyPropPage::FreeAllObjects(void)
{
UINT i;
if (NULL==m_ppObj)
return;
for (i=0; i < m_cObjects; i++)
ReleaseInterface(m_ppObj[i]);
delete [] m_ppObj;
m_ppObj=NULL;
m_cObjects=0;
return;
}
/*
* CPolyPropPage::SetPageSite
*
* Purpose:
* Provides the property page with the IPropertyPageSite
* that contains it. SetPageSite(NULL) will be called as
* part of the close sequence.
*
* Parameters:
* pPageSite LPPROPERTYPAGESITE pointer to the site.
*/
STDMETHODIMP CPolyPropPage::SetPageSite
(LPPROPERTYPAGESITE pPageSite)
{
if (NULL==pPageSite)
ReleaseInterface(m_pIPropertyPageSite)
else
{
HWND hDlg;
RECT rc;
m_pIPropertyPageSite=pPageSite;
m_pIPropertyPageSite->AddRef();
//We ignore locales
/*
* Load the dialog and determine the size it will be to
* return through GetPageSize. We just create the dialog
* here and destroy it again to retrieve the size,
* leaving Activate to create it for real.
*/
hDlg=CreateDialogParam(m_hInst
, MAKEINTRESOURCE(IDD_POLYLINEPROPS), GetDesktopWindow()
, (DLGPROC)PolyPropPageProc, 0L);
//If creation fails, use default values set in constructor
if (NULL!=hDlg)
{
GetWindowRect(hDlg, &rc);
m_cx=rc.right-rc.left;
m_cy=rc.bottom-rc.top;
DestroyWindow(hDlg);
}
}
return NOERROR;
}
/*
* CPolyPropPage::Activate
*
* Purpose:
* Instructs the property page to create a window in which to
* display its contents, using the given parent window and
* rectangle. The window should be initially visible.
*
* Parameters:
* hWndParent HWND of the parent window.
* prc LPCRECT of the rectangle to use.
* fModal BOOL indicating whether the frame is modal.
*/
STDMETHODIMP CPolyPropPage::Activate(HWND hWndParent
, LPCRECT prc, BOOL fModal)
{
if (NULL!=m_hDlg)
return ResultFromScode(E_UNEXPECTED);
m_hDlg=CreateDialogParam(m_hInst
, MAKEINTRESOURCE(IDD_POLYLINEPROPS)
, hWndParent, PolyPropPageProc, (LPARAM)this);
if (NULL==m_hDlg)
return ResultFromScode(E_OUTOFMEMORY);
//Move the page into position and show it.
SetWindowPos(m_hDlg, NULL, prc->left, prc->top
, prc->right-prc->left, prc->bottom-prc->top, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -