📄 bcfcontrolctl.cpp
字号:
//=--------------------------------------------------------------------------=
// BCFControlCtl.Cpp
//=--------------------------------------------------------------------------=
// Copyright 1995 Microsoft Corporation. All Rights Reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//=--------------------------------------------------------------------------=
//
//
//
#include "IPServer.H"
#include "Guids.H"
#include "BCFControlCtl.H"
#include "LocalObj.H"
#include "Util.H"
#include "Globals.H"
#include "Resource.H"
// for ASSERT and FAIL
//
SZTHISFILE
//=--------------------------------------------------------------------------=
// all the events in this control
//
// TODO: add events here ...
//
VARTYPE rgPI4PBSTR [] = { VT_BSTR | VT_BYREF, VT_I4 | VT_BYREF };
EVENTINFO m_rgBCFControlEvents [] =
{
{ eventidChange, 2, rgPI4PBSTR }
};
//=--------------------------------------------------------------------------=
// array describing all of our property pages. these clsids are typically
// in guids.h
//
// TODO: add any additional property page guids here ...
//
const GUID *rgBCFControlPropPages [] = {
&CLSID_BCFControlGeneralPage
};
//=--------------------------------------------------------------------------=
// Custum Verb information
//
// TODO: add any custom verbs here in an array, using the VERBINFO structure.
// then mark the controld def'n in BCFControlCtl.H with
// this verb array
//
//=--------------------------------------------------------------------------=
// CBCFControlControl::Create
//=--------------------------------------------------------------------------=
// global static function that creates an instance of the control an returns
// an IUnknown pointer for it.
//
// Parameters:
// IUnknown * - [in] controlling unknown for aggregation
//
// Output:
// IUnknown * - new object.
//
// Notes:
//
IUnknown *CBCFControlControl::Create
(
IUnknown *pUnkOuter
)
{
// make sure we return the private unknown so that we support aggegation
// correctly!
//
CBCFControlControl *pNew = new CBCFControlControl(pUnkOuter);
return pNew->PrivateUnknown();
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::CBCFControlControl
//=--------------------------------------------------------------------------=
// "Being born is like being kidnapped. And then sold into slavery."
// - andy warhol (1928 - 87)
//
// Parameters:
// IUnknown * - [in]
//
// Notes:
//
#pragma warning(disable:4355) // using 'this' in constructor
CBCFControlControl::CBCFControlControl
(
IUnknown *pUnkOuter
)
: CInternetControl(pUnkOuter, OBJECT_TYPE_CTLBCFCONTROL, (IDispatch *)this)
{
// initialize anything here ...
//
memset(&m_state, 0, sizeof(BCFCONTROLCTLSTATE));
memset(&m_DefaultState, 0, sizeof(BCFCONTROLCTLSTATE));
// NULL terminate the string reference
m_lptstrCaption = new TCHAR[1];
m_lptstrCaption[0] = '\0';
// set the alignment to the default of left
m_DefaultState.lAlignment = m_state.lAlignment = EALIGN_LEFT;
// set the backcolor to the system default
m_DefaultState.ocBackColor = m_state.ocBackColor = 0x80000000 | COLOR_WINDOW;
// set the ready state of the control
m_state.lReadyState = READYSTATE_LOADING;
// NULL terminate the string reference
m_lptstrTextDataPath = new TCHAR[1];
m_lptstrTextDataPath[0] = '\0';
// clear the font
m_pFont = NULL;
// clear the brush
hOldBrush = hBrush = NULL;
// clear the flag
bRetrievedDimensions = FALSE;
// set to the first element
ulFORMATETCElement = 0;
// clear the storage medium
sTextStgMedium.hGlobal = NULL;
// register a custom clipboard format
m_uiCustomFormat = ::RegisterClipboardFormat("BCFControlCtlCustomFormat");
// clear the storage medium
sCustomStgMedium.hGlobal = NULL;
}
#pragma warning(default:4355) // using 'this' in constructor
//=--------------------------------------------------------------------------=
// CBCFControlControl::~CBCFControlControl
//=--------------------------------------------------------------------------=
// "We all labour against our own cure, for death is the cure of all diseases"
// - Sir Thomas Browne (1605 - 82)
//
// Notes:
//
CBCFControlControl::~CBCFControlControl ()
{
// if we have a string
if(m_lptstrCaption)
// destroy the string
delete [] m_lptstrCaption;
// if we have a string
if(m_lptstrTextDataPath)
// destroy the string
delete [] m_lptstrTextDataPath;
}
//=--------------------------------------------------------------------------=
// CBCFControlControl:RegisterClassData
//=--------------------------------------------------------------------------=
// register the window class information for your control here.
// this information will automatically get cleaned up for you on DLL shutdown.
//
// Output:
// BOOL - FALSE means fatal error.
//
// Notes:
//
BOOL CBCFControlControl::RegisterClassData
(
void
)
{
WNDCLASS wndclass;
// TODO: register any additional information you find interesting here.
// this method is only called once for each type of control
//
memset(&wndclass, 0, sizeof(WNDCLASS));
wndclass.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
wndclass.lpfnWndProc = COleControl::ControlWindowProc;
wndclass.hInstance = g_hInstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszClassName = WNDCLASSNAMEOFCONTROL(OBJECT_TYPE_CTLBCFCONTROL);
return RegisterClass(&wndclass);
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::BeforeCreateWindow
//=--------------------------------------------------------------------------=
// called just before the window is created. Great place to set up the
// window title, etc, so that they're passed in to the call to CreateWindowEx.
// speeds things up slightly.
//
// Parameters:
// DWORD * - [out] dwWindowFlags
// DWORD * - [out] dwExWindowFlags
// LPSTR - [out] name of window to create
//
// Output:
// BOOL - false means fatal error
//
// Notes:
//
BOOL CBCFControlControl::BeforeCreateWindow
(
DWORD *pdwWindowStyle,
DWORD *pdwExWindowStyle,
LPSTR pszWindowTitle
)
{
// TODO: users should set the values of *pdwWindowStyle, *pdwExWindowStyle,
// and pszWindowTitle so that the call to CreateWindowEx can use them. setting
// them here instead of calling SetWindowStyle in WM_CREATE is a huge perf win
// if you don't use this function, then you can probably just remove it.
//
return TRUE;
}
BOOL CBCFControlControl::AfterCreateWindow(void)
{
// if we have a window handle
if(m_hwnd)
// register the control as a drag and drop target
::RegisterDragDrop(m_hwnd, (IDropTarget *) this);
return TRUE;
}
void CBCFControlControl::BeforeDestroyWindow(void)
{
// if we have a window handle
if(m_hwnd)
// revoke the control as a drag and drop target
::RevokeDragDrop(m_hwnd);
// if there is an old brush
if(hOldBrush)
{
// get the DC
HDC hDC = this->OcxGetDC();
// select the old brush back
::SelectObject(hDC, hOldBrush);
// release the DC
this->OcxReleaseDC(hDC);
}
// if we created a brush
if(hBrush)
// destroy the brush we created
::DeleteObject(hBrush);
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::InternalQueryInterface
//=--------------------------------------------------------------------------=
// qi for things only we support.
//
// Parameters:
// Parameters:
// REFIID - [in] interface they want
// void ** - [out] where they want to put the resulting object ptr.
//
// Output:
// HRESULT - S_OK, E_NOINTERFACE
//
// Notes:
//
HRESULT CBCFControlControl::InternalQueryInterface(REFIID riid, void **ppvObjOut)
{
IUnknown *pUnk;
*ppvObjOut = NULL;
// TODO: if you want to support any additional interrfaces, then you should
// indicate that here. never forget to call COleControl's version in the
// case where you don't support the given interface.
//
if(DO_GUIDS_MATCH(riid, IID_IBCFControl))
pUnk = (IUnknown *)(IBCFControl *)this;
else if(DO_GUIDS_MATCH(riid, IID_IPerPropertyBrowsing))
pUnk = (IUnknown *)(IPerPropertyBrowsing *)this;
else if(DO_GUIDS_MATCH(riid, IID_IDataObject))
pUnk = (IUnknown *)(IDataObject *)this;
else if(DO_GUIDS_MATCH(riid, IID_IEnumFORMATETC))
pUnk = (IUnknown *)(IEnumFORMATETC *)this;
else if(DO_GUIDS_MATCH(riid, IID_IDropSource))
pUnk = (IUnknown *)(IDropSource *)this;
else if(DO_GUIDS_MATCH(riid, IID_IDropTarget))
pUnk = (IUnknown *)(IDropTarget *)this;
else
return COleControl::InternalQueryInterface(riid, ppvObjOut);
pUnk->AddRef();
*ppvObjOut = (void *)pUnk;
return S_OK;
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::LoadTextState
//=--------------------------------------------------------------------------=
// load in our text state for this control.
//
// Parameters:
// IPropertyBag * - [in] property bag to read from
// IErrorLog * - [in] errorlog object to use with proeprty bag
//
// Output:
// HRESULT
//
// Notes:
// - NOTE: if you have a binary object, then you should pass an unknown
// pointer to the property bag, and it will QI it for IPersistStream, and
// get said object to do a Load()
//
STDMETHODIMP CBCFControlControl::LoadTextState
(
IPropertyBag *pPropertyBag,
IErrorLog *pErrorLog
)
{
HRESULT hr;
VARIANT v;
::VariantInit(&v);
v.vt = VT_BSTR;
hr = pPropertyBag->Read(OLESTRFROMANSI("Caption"), &v, pErrorLog);
if(SUCCEEDED(hr))
{
// get a ANSI string from the BSTR
MAKE_ANSIPTR_FROMWIDE(lpctstrCaption, v.bstrVal);
// free the BSTR that was passed in
::SysFreeString(v.bstrVal);
// if we have a string
if(lpctstrCaption != NULL)
{
// if we have a string
if(m_lptstrCaption)
{
// delete the existing string
delete [] m_lptstrCaption;
// clear the reference just to be safe
m_lptstrCaption = NULL;
}
// allocate a new string
m_lptstrCaption = new TCHAR[lstrlen(lpctstrCaption) + 1];
// assign the string to our member variable
lstrcpy(m_lptstrCaption, lpctstrCaption);
}
}
::VariantInit(&v);
v.vt = VT_I4;
hr = pPropertyBag->Read(OLESTRFROMANSI("Alignment"), &v, pErrorLog);
if(SUCCEEDED(hr))
m_state.lAlignment = v.lVal;
::VariantInit(&v);
v.vt = VT_I4;
hr = pPropertyBag->Read(OLESTRFROMANSI("BackColor"), &v, pErrorLog);
if(SUCCEEDED(hr))
m_state.ocBackColor = v.lVal;
::VariantInit(&v);
v.vt = VT_BSTR;
hr = pPropertyBag->Read(OLESTRFROMANSI("TextDataPath"), &v, pErrorLog);
if(SUCCEEDED(hr))
{
// get a ANSI string from the BSTR
MAKE_ANSIPTR_FROMWIDE(lpctstrTextDataPath, v.bstrVal);
// free the BSTR that was passed in
::SysFreeString(v.bstrVal);
// if we have a string
if(lpctstrTextDataPath != NULL)
{
// if we have a string
if(m_lptstrTextDataPath)
{
// delete the existing string
delete [] m_lptstrTextDataPath;
// clear the reference just to be safe
m_lptstrTextDataPath = NULL;
}
// allocate a new string
m_lptstrTextDataPath = new TCHAR[lstrlen(lpctstrTextDataPath) + 1];
// assign the string to our member variable
lstrcpy(m_lptstrTextDataPath, lpctstrTextDataPath);
}
}
this->InvalidateControl(NULL);
this->m_fDirty = TRUE;
// always return S_OK
return S_OK;
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::LoadBinaryState
//=--------------------------------------------------------------------------=
// loads in our binary state using streams.
//
// Parameters:
// IStream * - [in] stream to write to.
//
// Output:
// HRESULT
//
// Notes:
//
STDMETHODIMP CBCFControlControl::LoadBinaryState
(
IStream *pStream
)
{
HRESULT hr = S_OK;
// read the state of the control
hr = pStream->Read(&m_state, sizeof(m_state), NULL);
// create a string of the appropriate size this includes the NULL
m_lptstrCaption = new TCHAR[m_state.lCaptionLength];
// read the string and NULL
hr = pStream->Read(m_lptstrCaption, m_state.lCaptionLength, NULL);
// create a string of the appropriate size this includes the NULL
m_lptstrTextDataPath = new TCHAR[m_state.lTextDataPathLength];
// read the string and NULL
hr = pStream->Read(m_lptstrTextDataPath, m_state.lTextDataPathLength, NULL);
// redraw the control
this->InvalidateControl(NULL);
this->m_fDirty = TRUE;
return S_OK;
}
//=--------------------------------------------------------------------------=
// CBCFControlControl::SaveTextState
//=--------------------------------------------------------------------------=
// saves out the text state for this control using a property bag.
//
// Parameters:
// IPropertyBag * - [in] the property bag with which to work.
// BOOL - [in] if TRUE, then write out ALL properties, even
// if they're their the default value ...
//
// Output:
// HRESULT
//
// Notes:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -