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

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


Windows controls in OCX not visible in VB4 in design mode

Claus Michelsen -- cmi@cri.dk
Thursday, January 02, 1997

Environment: VC++ 4.2-flat, Win 95

I am trying to implement an OCX which contains several Windows controls
(such as edit, static, tree controls, etc.) but have problems with the fact
that an OCX developed in VC doesn't always have a window (e.g. in design
mode in VB4). I am currently creating the Windows controls in the OCX in
the following manor:

int CCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	m_static.Create(_T("&Test:"), WS_CHILD|WS_VISIBLE, 
		CRect(0, 0, 100, 20), this));
	m_edit.Create(WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER,
		CRect(0, 21, 100, 40), this, 100));
	
	return 0;
}

This will however not work when the OCX doesn't have a window since the
function is never called. Do I have to have a metafile I can show in design
mode, or what?

I really hope somebody can help me with this, because I am stuck.


Best regards,
Claus Michelsen
Software Engineer
CRI A/S, Denmark





Mike Blaszczak -- mikeblas@nwlink.com
Thursday, January 02, 1997

At 07:40 1/2/97 -0100, Claus Michelsen wrote:
>Environment: VC++ 4.2-flat, Win 95

>Do I have to have a metafile I can show in design
>mode, or what?

Yep.  OLE Controls are OLE objects; they might not get a window and
their container might ask them for a cached representation of their
data.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.




Mike Bryga -- MBryga@PickSys.com
Monday, January 06, 1997

Regarding:

> Environment: VC++ 4.2-flat, Win 95

> I am trying to implement an OCX which contains several Windows =
controls
> (such as edit, static, tree controls, etc.) but have problems with the =
fact
> that an OCX developed in VC doesn't always have a window (e.g. in =
design
> mode in VB4).=20

Claus,

I derived the following from Tom Armstrong's book on ClassWizard =
sub-classed Ole Controls - he also has a nice web site with lots of =
info. He adds a function DrawDesign() that is called by OnDrawMetafile() =
and conditionally by OnDraw() in design mode. It just paints the =
rectangle and the default object name at design time.

void CMyControl::OnDraw(
	CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	if (!AmbientUserMode())
		DrawDesign(pdc, rcBounds);
	else
		DoSuperclassPaint(pdc, rcBounds);
}

void CMyCOntrol::OnDrawMetafile(
	CDC* pdc, const CRect& rcBounds)
{
	DrawDesign(pdc, rcBounds);
}

void CMyControl::DrawDesign(
	CDC* pdc, const CRect& rcBounds)
{
	CString lpString =3D AmbientDisplayName();
	CBrush bkBrush(TranslateColor(GetBackColor()));
	pdc->FillRect(rcBouns, &bkBrush);
	pdc->SetTextColor(TranslateColor(GetForeColor()));
	pdc->SetBkMode(TRANSPARENT);
	pdc->SetTextAlign(TA_LEFT | TA_TOP);
	pdc->ExtTextOut(rcBounds.left + 1, rcBounds.top + 1,
				ETO_CLIPPED, rcBounds,
				lpString, lpString.GetLength(), NULL);
}

Hope this helps - I just typed it in, so I can't gaurantee it will =
compile or run.

Mike




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