15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Subclassing an OLE control

Ramachandra Rao -- chandu@ampersand.soft.net
Tuesday, July 02, 1996



Environment : VC++ 4.0  WindowsNT 3.51

Hi
	I want to trap the scroll bar event of a grid( OLE control) for which
I am subclassing the grid. Here is my code

In MyDialog.h
{
	CMyWnd mywnd;    // CMyWnd is a class derived from CWnd
}

BOOL CMyDialog::OnInitDialog()
{       
	mywnd.SubClassDlgItem(IDC_GRID1, this); //   IDC_GRID1 is my grid id
	CDialog::OnInitDialog();
}



	GetDlgItem(pParent->m_hWnd, nID) is returning NULL . The control id 
is correct and it belongs to the same dialog. It works fine with the
windows controls but not with the OLE controls( grid ).So does that
have any implications?
If so, how do I subclass an OLE control.?


				Thanks everyone
				Chandu





David.Lowndes@bj.co.uk
Monday, July 08, 1996

[Mini-digest: 2 responses]

>	I want to trap the scroll bar event of a grid( OLE control) for which
>I am subclassing the grid. Here is my code
>
>In MyDialog.h
>{
>	CMyWnd mywnd;    // CMyWnd is a class derived from CWnd
>}
>
>BOOL CMyDialog::OnInitDialog()
>{       
>	mywnd.SubClassDlgItem(IDC_GRID1, this); //   IDC_GRID1 is my grid id
>	CDialog::OnInitDialog();
>}
>
>
>
>	GetDlgItem(pParent->m_hWnd, nID) is returning NULL .

Chandu,

I don't know if this is the answer to your problem, but I think you're trying
to use "mywnd" before it's been initialised by the DDX. Try this instead.

BOOL CMyDialog::OnInitDialog()
{       
	CDialog::OnInitDialog();
	mywnd.SubClassDlgItem(IDC_GRID1, this); //   IDC_GRID1 is my grid id
}

Dave Lowndes
-----From: "John Elsbree" 

Chandu -

True, ::GetDlgItem will return NULL, because the hwnd of the control may not 
actually have an ID of IDC_GRID1. Because it's an OLE control, it chooses for 
itself what its own ID will be, regardless of what's in the dialog template. 
There's no OLE interface through which a container to can the ID of the 
control, so it doesn't.

However, the container does maintain its own copy of what it thinks the ID 
should be (based on what was in the dialog template). That's why the remainder 
of the code in SubclassDlgItem (the stuff inside the #ifndef 
_AFX_NO_OCC_SUPPORT) exists. Have you traced through that code?

John ("not speaking for Microsoft") Elsbree





| Вернуться в корень Архива |