⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cballprop.cpp

📁 最近在学习directshow, Directshow实务精选的源代码
💻 CPP
字号:
//
// CBallProp.cpp
//

#include <streams.h>

// Eliminate two expected level 4 warnings from the Microsoft compiler.
// The class does not have an assignment or copy operator, and so cannot
// be passed by value.  This is normal.  This file compiles clean at the
// highest (most picky) warning level (-W4).
#pragma warning(disable: 4511 4512)

#include <windowsx.h>
#include <stdio.h>

#include "Resource.h"            // ids used in the dialog
#include "CBallProp.h"       // our own class

//
// CreateInstance
//
// Override CClassFactory method.
// Set lpUnk to point to an IUnknown interface on a new NullIPProperties object
// Part of the COM object instantiation mechanism
//
CUnknown * WINAPI CBallProp::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
{
	CUnknown *punk = new CBallProp(lpunk, phr);
	if (punk == NULL) 
	{
		*phr = E_OUTOFMEMORY;
	}
	return punk;
}

// Constructs and initialises a object
CBallProp::CBallProp(LPUNKNOWN pUnk, HRESULT *phr) : 
CBasePropertyPage(NAME("Prop Page"),pUnk,IDD_DLG_PROP,IDS_TITLE)
{
	ASSERT(phr);
	mIBall = NULL;
}

// Override CBasePropertyPage method.
// Handles the messages for our property window
BOOL CBallProp::OnReceiveMessage(HWND hwnd, UINT uMsg,
									 WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_INITDIALOG:
	{
		// Get windows' handles
		mEditWidth   = GetDlgItem(hwnd, IDC_EDIT_IMAGE_WIDTH);
		mEditHeight  = GetDlgItem(hwnd, IDC_EDIT_IMAGE_HEIGHT);
		break;
	}

	case WM_COMMAND:
	{
		SetDirty();
		break;
	}

	}

	return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
} // OnReceiveMessage


// Override CBasePropertyPage method.
// Notification of which object this property page should display.
HRESULT CBallProp::OnConnect(IUnknown *pUnknown)
{
	HRESULT hr = pUnknown->QueryInterface(IID_IBall, (void **) &mIBall);
	if (FAILED(hr))
	{
		return E_NOINTERFACE;
	}
	ASSERT(mIBall);

	return NOERROR;
} // OnConnect


// Override CBasePropertyPage method.
// Release the private interface, release the upstream pin.
HRESULT CBallProp::OnDisconnect()
{
	// Release of Interface
	if (mIBall == NULL)
		return E_UNEXPECTED;
	mIBall->Release();
	mIBall = NULL;

	return NOERROR;

} // OnDisconnect


// We are being activated
HRESULT CBallProp::OnActivate()
{
	ReflectImageSize();

	return NOERROR;
} // Activate

//
// Sets m_hrDirtyFlag and notifies the property page site of the change
void CBallProp::SetDirty()
{
    m_bDirty = TRUE;
    if (m_pPageSite)
    {
        m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
    }
} // SetDirty


// Changes made should be kept
HRESULT CBallProp::OnApplyChanges()
{
	EnterImageSize();

	return NOERROR;
} // OnApplyChanges

void CBallProp::ReflectImageSize(void)
{
	if (mIBall)
	{
		int width = 0, height = 0;
		mIBall->GetImageSize(&width, &height);
		char value[100];
		sprintf(value, "%d", width);
		SetWindowText(mEditWidth, value);
		sprintf(value, "%d", height);
		SetWindowText(mEditHeight, value);
	}
}

void CBallProp::EnterImageSize(void)
{
	if (mIBall)
	{
		char strWidth[10], strHeight[10];
		int ret1 = GetWindowText(mEditWidth, strWidth, 10);
		int ret2 = GetWindowText(mEditHeight, strHeight, 10);
		if (ret1 && ret2)
		{
			mIBall->SetImageSize(atoi(strWidth), atoi(strHeight));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -