home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Anthology
/
aDELPHI.iso
/
ActiveX
/
InaGrid_v2.0_32bit_ActiveX-FCN
/
data1.cab
/
InaEdit
/
InaEdit.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-07-19
|
9KB
|
328 lines
// InaEdit.cpp : Implementation of InaEdit and DLL registration.
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxctl.h> // MFC support for ActiveX Controls
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditControl
class CEditControl : public COleControl
{
DECLARE_DYNCREATE(CEditControl)
// Constructor
public:
CEditControl();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEditControl)
public:
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
//}}AFX_VIRTUAL
// Implementation
protected:
DECLARE_OLECREATE_EX(CEditControl) // Class factory and guid
DECLARE_OLETYPELIB(CEditControl) // GetTypeInfo
DECLARE_OLECTLTYPE(CEditControl) // Type name and misc status
// Subclassed control support
BOOL PreCreateWindow(CREATESTRUCT& cs);
BOOL IsSubclassedControl();
// Message maps
//{{AFX_MSG(CEditControl)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg UINT OnGetDlgCode();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Dispatch maps
//{{AFX_DISPATCH(CEditControl)
afx_msg long GetWindowStyle();
afx_msg void SetWindowStyle(long nNewValue);
afx_msg BOOL RecreateControl();
afx_msg BSTR GetCaption();
afx_msg void SetCaption(LPCTSTR lpszNewValue);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
CEdit& GetEdit() const
{ return *(CEdit*)this; }
// Event maps
//{{AFX_EVENT(CEditControl)
void FireOnNoFocus()
{FireEvent(eventidOnNoFocus,EVENT_PARAM(VTS_NONE));}
//}}AFX_EVENT
DECLARE_EVENT_MAP()
// Dispatch and event IDs
public:
enum {
//{{AFX_DISP_ID(CEditControl)
dispidWindowStyle = 1L,
dispidRecreateControl = 2L,
eventidOnNoFocus = 1L,
//}}AFX_DISP_ID
};
protected:
long m_Style;
};
COleControlModule NEAR theApp;
const GUID CDECL BASED_CODE _tlid =
{ 0x73f8e94a, 0x692c, 0x11d1, { 0x95, 0x1e, 0, 0xa0, 0x24, 0x83, 0x4f, 0xe6 } };
const WORD _wVerMajor = 2;
const WORD _wVerMinor = 0;
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
return NOERROR;
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);
return NOERROR;
}
IMPLEMENT_DYNCREATE(CEditControl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CEditControl, COleControl)
//{{AFX_MSG_MAP(CEditControl)
ON_WM_KILLFOCUS()
ON_WM_GETDLGCODE()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CEditControl, COleControl)
//{{AFX_DISPATCH_MAP(CEditControl)
DISP_PROPERTY_EX(CEditControl, "Style", GetWindowStyle, SetWindowStyle, VT_I4)
DISP_FUNCTION(CEditControl, "RecreateControl", RecreateControl, VT_BOOL, VTS_NONE)
DISP_STOCKPROP_HWND()
DISP_PROPERTY_EX_ID(CEditControl, "Caption", DISPID_CAPTION, GetCaption, SetCaption, VT_BSTR)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CEditControl, COleControl)
//{{AFX_EVENT_MAP(CEditControl)
EVENT_CUSTOM("OnNoFocus", FireOnNoFocus, VTS_NONE)
EVENT_STOCK_KEYDOWN()
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CEditControl, "INAEDIT.GridEditCtrl.1",
0x73f8e94d, 0x692c, 0x11d1, 0x95, 0x1e, 0, 0xa0, 0x24, 0x83, 0x4f, 0xe6)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CEditControl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DGridEdit =
{ 0x73f8e94b, 0x692c, 0x11d1, { 0x95, 0x1e, 0, 0xa0, 0x24, 0x83, 0x4f, 0xe6 } };
const IID BASED_CODE IID_DGridEditEvents =
{ 0x73f8e94c, 0x692c, 0x11d1, { 0x95, 0x1e, 0, 0xa0, 0x24, 0x83, 0x4f, 0xe6 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwGridEditOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CEditControl, IDS_GRIDEDIT, _dwGridEditOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CEditControl::CEditControlFactory::UpdateRegistry -
// Adds or removes system registry entries for CEditControl
BOOL CEditControl::CEditControlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_GRIDEDIT, IDB_GRIDEDIT,
afxRegApartmentThreading, _dwGridEditOleMisc, _tlid, _wVerMajor, _wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CEditControl::CEditControl - Constructor
CEditControl::CEditControl()
{
m_Style = 0;
InitializeIIDs(&IID_DGridEdit, &IID_DGridEditEvents);
}
/////////////////////////////////////////////////////////////////////////////
// CEditControl::OnDraw - Drawing function
void CEditControl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& /*rcInvalid*/)
{
DoSuperclassPaint(pdc, rcBounds);
}
/////////////////////////////////////////////////////////////////////////////
// CEditControl::PreCreateWindow - Modify parameters for CreateWindowEx
BOOL CEditControl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = _T("EDIT");
if (m_Style != 0)
cs.style = m_Style;
else
cs.style |= ES_AUTOHSCROLL;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
return COleControl::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEditControl::IsSubclassedControl - This is a subclassed control
BOOL CEditControl::IsSubclassedControl()
{
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CEditControl message handlers
void CEditControl::OnKillFocus(CWnd* pNewWnd)
{
COleControl::OnKillFocus(pNewWnd);
FireOnNoFocus();
}
BSTR CEditControl::GetCaption()
{
CString strResult;
GetWindowText(strResult);
return strResult.AllocSysString();
}
void CEditControl::SetCaption(LPCTSTR lpszNewValue)
{
SetWindowText(lpszNewValue);
GetEdit().SetSel(0,-1);
SetModifiedFlag();
}
UINT CEditControl::OnGetDlgCode()
{
return DLGC_WANTTAB | DLGC_WANTARROWS| DLGC_WANTALLKEYS | COleControl::OnGetDlgCode();
}
void CEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
USHORT snChar = (USHORT)nChar;
short nShiftState = NULL;
if(GetKeyState(VK_SHIFT) < 0) nShiftState |= SHIFT_MASK;
if(GetKeyState(VK_CONTROL) < 0) nShiftState |= CTRL_MASK;
if(GetKeyState(VK_MENU) < 0) nShiftState |= ALT_MASK;
FireKeyDown(&snChar, nShiftState);
}
long CEditControl::GetWindowStyle()
{
// TODO: Add your property handler here
return GetStyle();
}
void CEditControl::SetWindowStyle(long nNewValue)
{
// TODO: Add your property handler here
m_Style = nNewValue;
// SetModifiedFlag();
}
BOOL CEditControl::RecreateControl()
{
// TODO: Add your dispatch handler code here
RecreateControlWindow();
return m_hWnd != 0;
}