Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need your help
Please help me

I want to make a mfc application with richedit4.1(MSFTEDIT.dll)
I need a feature that can control line space with its content's real height.
I succeeded to control linespacing with text content's real height
(using CHARFORMAT's yHeight value)

but...... I need an idea 'cause it doesn't work with OLE object.

What I want to know is

1. if a line what I selected have some OLE objects like bitmap image, How can I know that. I want to know a boolean result the OLE object is exist or not in the line what I selected(range or point).

2. if I can get the boolean value of the OLE's existing. How can I get the existing object's height?

I use PARAFORMAT2 structure with bLineSpacingRule value '4' cause I need some values lower than single line spacing value. But it doesn't work with OLE object and forces line spacing value with it's text content's height

here is some code of my program.

C++
void CMyRichEditCtrl::SetSelectDyLineSpacingWithPercent(int nHeight, int nPercent)
{
    PARAFORMAT2 paraFormat;
    PARAFORMAT2 FAR *lpFmt = &paraFormat;
    int result;
    double nTemp;
    
    nTemp = nHeight * (nPercent*0.01);
         
    paraFormat.dySpaceAfter     = 0;
    paraFormat.cbSize           = sizeof(PARAFORMAT2);   
    paraFormat.dwMask           = PFM_LINESPACING|PFM_SPACEAFTER ;
    paraFormat.dyLineSpacing    = (int)nTemp;
    paraFormat.bLineSpacingRule = 4;
           
    result = SendMessage(EM_SETPARAFORMAT, 0, (long )lpFmt);   
    	
    SetFocus();    
}


C++
void CMyDlg::OnChangeRowGap()
{
	UpdateData(TRUE);

	CString strSize;
	int nIndex = 0;
	long nCurStart, nCurEnd;
	long nLineStart, nLineEnd;
	long nLineHeight;
	long nHighest;
	int nStartLine, nEndLine, nLineLength;
	int i, j;

	CHARFORMAT cf;

	m_richedit.GetSel(nCurStart, nCurEnd);
	nIndex = m_cboRowGap.GetCurSel();
	m_cboRowGap.GetLBText(nIndex, strSize);

	if(nCurStart != nCurEnd)
	{
		nStartLine = m_richedit.LineFromChar(nCurStart);
		nEndLine = m_richedit.LineFromChar(nCurEnd);

		for(i = nStartLine; i <= nEndLine; i++)
		{
			nLineLength = m_richedit.LineLength(i);
			nLineStart = m_richedit.LineIndex(i);
			nLineEnd = nLineStart + nLineLength;
			nHighest = 0;

			for(j = nLineStart; j < nLineEnd; j++)
			{
				m_richedit.SetSel(j, j);
				m_richedit.GetSelectionCharFormat(cf);

				nLineHeight = cf.yHeight;

				if(nHighest < nLineHeight)
				{
					nHighest = nLineHeight;
				}
			}
			m_richedit.SetSel(nLineStart,nLineStart);
			m_richedit.SetSelectDyLineSpacingWithPercent( nHighest, atoi(strSize) );
		}

		m_richedit.SetSel(nCurStart, nCurEnd);
	}
	else
	{
		nStartLine = m_richedit.LineFromChar(nCurStart);
		nLineLength = m_strLine.GetLength();
		nLineStart = m_richedit.LineIndex(nStartLine);
		nLineEnd = nLineStart + nLineLength;

		for(i = nLineStart; i < nLineEnd; i++)
		{
			m_richedit.SetSel(i, i);
			m_richedit.GetSelectionCharFormat(cf);

			nLineHeight = cf.yHeight;

			if(nHighest < nLineHeight)
			{
				nHighest = nLineHeight;
			}
		}

		m_richedit.SetSel(nCurStart, nCurEnd);
		m_richedit.SetSelectDyLineSpacingWithPercent(nHighest,atoi(strSize));
	}	

	Invalidate(FALSE);

	m_richedit.SetFocus();
}

if I selected a line with only text it doesn't matter.
but I selected a line with OLE object, the line's real height is not the text's height.
So I need informations that the line what I selected has OLE objects or not
and if the line has OLE object, I need to get the object's height.

do you have any idea?
I need your help

thank you for your concerntration
have a nice day
Posted
Updated 4-Nov-14 15:43pm
v5

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