Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I have created an MFC ole control in c++ and I have an issue when I paste the control onto a blank Word Page (Word 2013) it is bigger than the page size.

If I reduce the drawing before I copy it onto the clipboard, it works fine.

I have seen an event named :
BOOL CMeasGraphCtrl::OnSetExtent(LPSIZEL lpSizeL)
but I do not get access to the client site rectangle size during the paste procedure.

I wonder if somebody has already worked in this area to reduce the control size if it is outside the client container size.

How to reach the 'container size' to adjust it to fit the container size properly ?
Does somebody have an idea how to auto adjust the control size ?

Thank you very much in advance.
Best regards,
MiQi

What I have tried:

I have done the following experimentation:

BOOL CMeasGraphCtrl::OnSetExtent(LPSIZEL lpSizeL)
{
	BOOL	bRet = FALSE;
	if (m_bChangingExtent)  // Prevent infinite recursion!
		return FALSE;

        // after converting lpSizeL to pixels, it returns me the correct size of the control I copied on the winform window.

	SIZEL sizeHiMetric;
	_AfxXformSizeInHimetricToPixels(NULL, lpSizeL, &sizeHiMetric);

	SIZEL sizeExtentPixels;
	SIZEL sizeExtentHimetric;
	sizeExtentPixels.cx = m_cxExtent;
	sizeExtentPixels.cy = m_cyExtent;
	_AfxXformSizeInPixelsToHimetric(NULL, &sizeExtentPixels, &sizeExtentHimetric);

	int cx, cy;
	SIZEL controlSizePixels;
	SIZEL controlSizHiMetric;
	GetControlSize(&cx, &cy);
	controlSizePixels.cx = cx;
	controlSizePixels.cy = cy;
	_AfxXformSizeInPixelsToHimetric(NULL, &controlSizePixels, &controlSizHiMetric);
        
        // I never get a valid pointer to this information (it remains null).
	if (m_pInPlaceSite != nullptr)
	{
		RECT rcClientRect;
		GetClientRect(&rcClientRect);



		SIZEL controlSize;
		SIZEL controlSizeHiMetric;

		controlSize.cx = cx;
		controlSize.cy = cy;
		AtlPixelToHiMetric(&controlSize, &controlSizeHiMetric);

		RECT rcRectInContainer;
		GetRectInContainer(&rcRectInContainer);

		ClipCaretRect(&rcRectInContainer);
	}

	bRet = COleControl::OnSetExtent(lpSizeL);

	return bRet;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900