📄 sfilter.cpp
字号:
}
// =================================================================
// INetCfgProperties
// =================================================================
STDMETHODIMP CSampleFilter::SetContext(
IUnknown * pUnk)
{
TraceMsg(L"--> CSampleFilter::SetContext\n");
HRESULT hr = S_OK;
// release previous context, if any
ReleaseObj(m_pUnkContext);
m_pUnkContext = NULL;
if (pUnk) // set the new context
{
m_pUnkContext = pUnk;
m_pUnkContext->AddRef();
ZeroMemory(&m_guidAdapter, sizeof(m_guidAdapter));
// here we assume that we are going to be called only for
// a LAN connection since the sample IM works only with
// LAN devices
INetLanConnectionUiInfo * pLanConnUiInfo;
hr = m_pUnkContext->QueryInterface(
IID_INetLanConnectionUiInfo,
reinterpret_cast<PVOID *>(&pLanConnUiInfo));
if (S_OK == hr)
{
hr = pLanConnUiInfo->GetDeviceGuid(&m_guidAdapter);
ReleaseObj(pLanConnUiInfo);
}
}
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::MergePropPages
//
// Purpose: Supply our property page to system
//
// Arguments:
// pdwDefPages [out] pointer to num default pages
// pahpspPrivate [out] pointer to array of pages
// pcPages [out] pointer to num pages
// hwndParent [in] handle of parent window
// szStartPage [in] pointer to
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::MergePropPages(
IN OUT DWORD* pdwDefPages,
OUT LPBYTE* pahpspPrivate,
OUT UINT* pcPages,
IN HWND hwndParent,
OUT PCWSTR* szStartPage)
{
TraceMsg(L"--> CSampleFilter::MergePropPages\n");
HRESULT hr = S_OK;
HPROPSHEETPAGE* ahpsp = NULL;
m_eApplyAction = eActPropertyUI;
// We don't want any default pages to be shown
*pdwDefPages = 0;
*pcPages = 0;
*pahpspPrivate = NULL;
ahpsp = (HPROPSHEETPAGE*)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE));
if (ahpsp)
{
PROPSHEETPAGE psp = {0};
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_DEFAULT;
psp.hInstance = _Module.GetModuleInstance();
psp.pszTemplate = MAKEINTRESOURCE(IDD_SAMPLE_FILTER_GENERAL);
psp.pfnDlgProc = (DLGPROC) SampleFilterDialogProc;
psp.pfnCallback = (LPFNPSPCALLBACK) SampleFilterPropSheetPageProc;
// for Win64, use LONG_PTR instead of LPARAM
psp.lParam = (LPARAM) this;
psp.pszHeaderTitle = NULL;
psp.pszHeaderSubTitle = NULL;
ahpsp[0] = ::CreatePropertySheetPage(&psp);
*pcPages = 1;
*pahpspPrivate = (LPBYTE) ahpsp;
}
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::ValidateProperties
//
// Purpose: Validate changes to property page
//
// Arguments:
// hwndSheet [in] window handle of property sheet
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::ValidateProperties(HWND hwndSheet)
{
TraceMsg(L"--> CSampleFilter::ValidateProperties\n");
// Accept any change to Param1
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::CancelProperties
//
// Purpose: Cancel changes to property page
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::CancelProperties(VOID)
{
TraceMsg(L"--> CSampleFilter::CancelProperties\n");
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::ApplyProperties
//
// Purpose: Apply value of controls on property page
// to internal memory structure
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes: We do this work in OnOk so no need to do it here again.
//
STDMETHODIMP CSampleFilter::ApplyProperties(VOID)
{
TraceMsg(L"--> CSampleFilter::ApplyProperties\n");
return S_OK;
}
// =================================================================
// INetCfgBindNotify
// =================================================================
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::QueryBindingPath
//
// Purpose: Allow or veto a binding path involving us
//
// Arguments:
// dwChangeFlag [in] type of binding change
// pncbi [in] pointer to INetCfgBindingPath object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::QueryBindingPath(DWORD dwChangeFlag,
INetCfgBindingPath* pncbp)
{
TraceMsg(L"--> CSampleFilter::QueryBindingPath\n");
WCHAR buffer[256];
// we do not want to veto any binding path
memset(buffer, 0, 256 * sizeof(WCHAR));
GetCurrentDirectory(256, buffer);
TraceMsg(L"BLA 3\n");
TraceMsg(L"%s\n", buffer);
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::NotifyBindingPath
//
// Purpose: System tells us by calling this function which
// binding path involving us has just been formed.
//
// Arguments:
// dwChangeFlag [in] type of binding change
// pncbp [in] pointer to INetCfgBindingPath object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::NotifyBindingPath(DWORD dwChangeFlag,
INetCfgBindingPath* pncbp)
{
TraceMsg(L"--> CSampleFilter::NotifyBindingPath 0000\n");
IEnumNetCfgBindingInterface *iBindInterfaceEnum = NULL;
INetCfgBindingInterface *iBindInterface = NULL;
LPWSTR name = NULL;
ULONG dwIfaceCount;
pncbp->EnumBindingInterfaces(&iBindInterfaceEnum);
while(S_OK == iBindInterfaceEnum->Next(1, &iBindInterface, &dwIfaceCount) && (dwIfaceCount == 1)) {
// %ls
iBindInterface->GetName(&name);
TraceMsg(L"%ls\n", name);
}
return S_OK;
}
// ------------ END OF NOTIFY OBJECT FUNCTIONS --------------------
// -----------------------------------------------------------------
// Property Sheet related functions
//
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::OnInitDialog
//
// Purpose: Initialize controls
//
// Arguments:
// hWnd [in] window handle
//
// Returns:
//
// Notes:
//
LRESULT CSampleFilter::OnInitDialog(IN HWND hWnd)
{
// Param1 edit box
return PSNRET_NOERROR;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::OnOk
//
// Purpose: Do actions when OK is pressed
//
// Arguments:
// hWnd [in] window handle
//
// Returns:
//
// Notes:
//
LRESULT CSampleFilter::OnOk(IN HWND hWnd)
{
TraceMsg(L"--> CSampleFilter::OnOk\n");
return PSNRET_NOERROR;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::OnCancel
//
// Purpose: Do actions when CANCEL is pressed
//
// Arguments:
// hWnd [in] window handle
//
// Returns:
//
// Notes:
//
LRESULT CSampleFilter::OnCancel(IN HWND hWnd)
{
TraceMsg(L"--> CSampleFilter::OnCancel\n");
return FALSE;
}
// ----------------------------------------------------------------------
//
// Function: SampleFilterDialogProc
//
// Purpose: Dialog proc
//
// Arguments:
// hWnd [in] see win32 documentation
// uMsg [in] see win32 documentation
// wParam [in] see win32 documentation
// lParam [in] see win32 documentation
//
// Returns:
//
// Notes:
//
LRESULT
CALLBACK
SampleFilterDialogProc (
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PROPSHEETPAGE* ppsp;
LRESULT lRes = 0;
static PROPSHEETPAGE* psp = NULL;
CSampleFilter* psf;
if (uMsg == WM_INITDIALOG)
{
ppsp = (PROPSHEETPAGE *)lParam;
psf = (CSampleFilter *)ppsp->lParam;
SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)psf);
lRes = psf->OnInitDialog(hWnd);
return lRes;
}
else
{
psf = (CSampleFilter *)::GetWindowLongPtr(hWnd, DWLP_USER);
// Until we get WM_INITDIALOG, just return FALSE
if (!psf)
{
return FALSE;
}
}
if (WM_COMMAND == uMsg)
{
if (EN_CHANGE == HIWORD(wParam))
{
// Set the property sheet changed flag if any of our controls
// get changed. This is important so that we get called to
// apply our property changes.
//
PropSheet_Changed(GetParent(hWnd), hWnd);
}
}
else if (WM_NOTIFY == uMsg)
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (pnmh->code)
{
case PSN_SETACTIVE:
lRes = 0; // accept activation
break;
case PSN_KILLACTIVE:
// ok to loose being active
SetWindowLongPtr(hWnd, DWLP_MSGRESULT, FALSE);
lRes = TRUE;
break;
case PSN_APPLY:
lRes = psf->OnOk(hWnd);
break;
case PSN_RESET:
lRes = psf->OnCancel(hWnd);
break;
default:
lRes = FALSE;
break;
}
}
return lRes;
}
// ----------------------------------------------------------------------
//
// Function: SampleFilterPropSheetPageProc
//
// Purpose: Prop sheet proc
//
// Arguments:
// hWnd [in] see win32 documentation
// uMsg [in] see win32 documentation
// ppsp [in] see win32 documentation
//
// Returns:
//
// Notes:
//
UINT CALLBACK SampleFilterPropSheetPageProc(HWND hWnd, UINT uMsg,
LPPROPSHEETPAGE ppsp)
{
UINT uRet = TRUE;
return uRet;
}
// -----------------------------------------------------------------
//
// Utility Functions
//
HRESULT HrGetBindingInterfaceComponents (
INetCfgBindingInterface* pncbi,
INetCfgComponent** ppnccUpper,
INetCfgComponent** ppnccLower)
{
HRESULT hr=S_OK;
// Initialize output parameters
*ppnccUpper = NULL;
*ppnccLower = NULL;
INetCfgComponent* pnccUpper;
INetCfgComponent* pnccLower;
hr = pncbi->GetUpperComponent(&pnccUpper);
if (SUCCEEDED(hr))
{
hr = pncbi->GetLowerComponent(&pnccLower);
if (SUCCEEDED(hr))
{
*ppnccUpper = pnccUpper;
*ppnccLower = pnccLower;
}
else
{
ReleaseObj(pnccUpper);
}
}
return hr;
}
HRESULT HrOpenAdapterParamsKey(GUID* pguidAdapter,
HKEY* phkeyAdapter)
{
HRESULT hr=S_OK;
return hr;
}
#if DBG
static void TraceMsg(PCWSTR szFormat, ...)
{
static WCHAR szTempBuf[4096];
va_list arglist;
va_start(arglist, szFormat);
_vstprintf(szTempBuf, szFormat, arglist);
OutputDebugString(szTempBuf);
va_end(arglist);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -