www.pudn.com > VirtualVCR-src-v2.6.9.zip > VideoCropProp.cpp
/*
Virtual VCR
Copyright (C) 2002 Shaun Faulds
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Acknowledgments:
This application and associated filters are based on the examples
from the Microsoft DirectX DirectShow SDK.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "resource.h"
#include "VideoCropUIDs.h"
#include "iVideoCrop.h"
#include "VideoCrop.h"
#include "VideoCropProp.h"
#include "VideoCropPropData.h"
//
// CreateInstance
//
// Used by the DirectShow base classes to create instances
//
CUnknown *CVideoCropProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
{
CUnknown *punk = new CVideoCropProperties(lpunk, phr);
if (punk == NULL)
{
*phr = E_OUTOFMEMORY;
}
return punk;
} // CreateInstance
//
// Constructor
//
CVideoCropProperties::CVideoCropProperties(LPUNKNOWN pUnk, HRESULT *phr) :
CBasePropertyPage(NAME("Video Crop Property Page"),
pUnk,IDD_VideoCropPropDlg,IDS_TITLE),
m_pVideoCrop(NULL)
{
} // (Constructor)
//
// OnReceiveMessage
//
// Handles the messages for our property window
//
BOOL CVideoCropProperties::OnReceiveMessage(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
ASSERT(m_pVideoCrop);
VideoCropPropData *data;
m_pVideoCrop->get_Data(data);
SendMessage(GetDlgItem( hwnd, IDC_CROP_LEFT_SPIN ),
UDM_SETRANGE, 0, MAKELPARAM(999, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_RIGHT_SPIN ),
UDM_SETRANGE, 0, MAKELPARAM(999, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_TOP_SPIN ),
UDM_SETRANGE, 0, MAKELPARAM(999, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_BOTTOM_SPIN ),
UDM_SETRANGE, 0, MAKELPARAM(999, 0));
/*
SendMessage(GetDlgItem( hwnd, IDC_CROP_TOP_SPIN ),
UDM_SETPOS, 0, (LPARAM) MAKELONG ((short) data->getTop()/2, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_BOTTOM_SPIN ),
UDM_SETPOS, 0, (LPARAM) MAKELONG ((short) data->getBottom()/2, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_LEFT_SPIN ),
UDM_SETPOS, 0, (LPARAM) MAKELONG ((short) data->getLeft()/2, 0));
SendMessage(GetDlgItem( hwnd, IDC_CROP_RIGHT_SPIN ),
UDM_SETPOS, 0, (LPARAM) MAKELONG ((short) data->getRight()/2, 0));
*/
TCHAR Cwidth[32];
input_width = data->getInputWidth();
if(input_width == 0)
wsprintf(Cwidth, TEXT("%s"), "N/C");
else
wsprintf(Cwidth, TEXT("%d"), data->getInputWidth());
SetDlgItemText(hwnd, IDC_INPUT_WIDTH, Cwidth);
input_height = data->getInputHeight();
if(input_height == 0)
wsprintf(Cwidth, TEXT("%s"), "N/C");
else
wsprintf(Cwidth, TEXT("%d"), data->getInputHeight());
SetDlgItemText(hwnd, IDC_INPUT_HEIGHT, Cwidth);
// Setup the text input
wsprintf(Cwidth, TEXT("%d"), data->getTop());
SetDlgItemText(hwnd, IDC_CROP_TOP, Cwidth);
wsprintf(Cwidth, TEXT("%d"), data->getLeft());
SetDlgItemText(hwnd, IDC_CROP_LEFT, Cwidth);
wsprintf(Cwidth, TEXT("%d"), data->getRight());
SetDlgItemText(hwnd, IDC_CROP_RIGHT, Cwidth);
wsprintf(Cwidth, TEXT("%d"), data->getBottom());
SetDlgItemText(hwnd, IDC_CROP_BOTTOM, Cwidth);
delete data;
return (LRESULT) 1;
}
case WM_COMMAND:
{
TCHAR text[32];
switch(LOWORD(wParam))
{
case IDC_SET_BUTTON:
{
int left = GetDlgItemInt(hwnd, IDC_CROP_LEFT, NULL, FALSE);
int right = GetDlgItemInt(hwnd, IDC_CROP_RIGHT, NULL, FALSE);
int top = GetDlgItemInt(hwnd, IDC_CROP_TOP, NULL, FALSE);
int bottom = GetDlgItemInt(hwnd, IDC_CROP_BOTTOM, NULL, FALSE);
VideoCropPropData *data = new VideoCropPropData(left, right, top, bottom, 0, 0);
m_pVideoCrop->set_Data(data);
delete data;
}
case IDC_CROP_TOP:
case IDC_CROP_BOTTOM:
{
if(HIWORD(wParam) != EN_UPDATE) break;
if(input_height != 0)
{
int top = GetDlgItemInt(hwnd, IDC_CROP_TOP, NULL, FALSE);
int bottom = GetDlgItemInt(hwnd, IDC_CROP_BOTTOM, NULL, FALSE);
wsprintf(text, TEXT("%d"), input_height - (top + bottom));
}
else
wsprintf(text, TEXT("%s"), "N/C");
SetDlgItemText(hwnd, IDC_OUTPUT_HEIGHT, text);
break;
}
case IDC_CROP_LEFT:
case IDC_CROP_RIGHT:
{
if(HIWORD(wParam) != EN_UPDATE) break;
if(input_width != 0)
{
int left = GetDlgItemInt(hwnd, IDC_CROP_LEFT, NULL, FALSE);
int right = GetDlgItemInt(hwnd, IDC_CROP_RIGHT, NULL, FALSE);
wsprintf(text, TEXT("%d"), input_width - (left + right));
}
else
wsprintf(text, TEXT("%s"), "N/C");
SetDlgItemText(hwnd, IDC_OUTPUT_WIDTH, text);
break;
}
}
return (LRESULT) 1;
}
/*
case WM_NOTIFY:
{
TCHAR text[32];
switch(wParam)
{
case IDC_CROP_TOP_SPIN:
{
LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
int value = 0 ;
if(lpnmud->iPos + lpnmud->iDelta < 0)
value = lpnmud->iPos;
else
value = lpnmud->iPos + lpnmud->iDelta;
wsprintf(text, TEXT("%d"), value);
SetDlgItemText(hwnd, IDC_OUTPUT_WIDTH, text);
//MessageBox(HWND_DESKTOP, "Scrol", "", MB_OK);
break;
}
}
}
*/
case WM_DESTROY:
{
/*
int left = GetDlgItemInt(hwnd, IDC_CROP_LEFT, NULL, FALSE);
int right = GetDlgItemInt(hwnd, IDC_CROP_RIGHT, NULL, FALSE);
int top = GetDlgItemInt(hwnd, IDC_CROP_TOP, NULL, FALSE);
int bottom = GetDlgItemInt(hwnd, IDC_CROP_BOTTOM, NULL, FALSE);
VideoCropPropData *data = new VideoCropPropData(left, right, top, bottom, 0, 0);
m_pVideoCrop->set_Data(data);
delete data;
*/
return (LRESULT) 1;
}
}
return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
} // OnReceiveMessage
//
// OnConnect
//
// Called when we connect to a transform filter
//
HRESULT CVideoCropProperties::OnConnect(IUnknown *pUnknown)
{
ASSERT(m_pVideoCrop == NULL);
HRESULT hr = pUnknown->QueryInterface(IID_IVideoCrop, (void **) &m_pVideoCrop);
if (FAILED(hr))
{
return E_NOINTERFACE;
}
ASSERT(m_pVideoCrop);
return NOERROR;
} // OnConnect
//
// OnDisconnect
//
// Likewise called when we disconnect from a filter
//
HRESULT CVideoCropProperties::OnDisconnect()
{
// Release of Interface after setting the appropriate old effect value
if (m_pVideoCrop == NULL) {
return E_UNEXPECTED;
}
m_pVideoCrop->Release();
m_pVideoCrop = NULL;
return NOERROR;
} // OnDisconnect
//
// OnActivate
//
// We are being activated
//
HRESULT CVideoCropProperties::OnActivate()
{
return NOERROR;
} // OnActivate
//
// OnDeactivate
//
// We are being deactivated
//
HRESULT CVideoCropProperties::OnDeactivate(void)
{
return NOERROR;
} // OnDeactivate
//
// OnApplyChanges
//
// Apply any changes so far made
//
HRESULT CVideoCropProperties::OnApplyChanges()
{
return NOERROR;
} // OnApplyChanges
void CVideoCropProperties::GetControlValues()
{
ASSERT(m_pVideoCrop);
}