Print Page | Close Window

MFC. Extract text from markup

Printed From: Codejock Forums
Category: General
Forum Name: Samples and Demo Applications
Forum Description: Post your samples and demo applications here.
URL: http://forum.codejock.com/forum_posts.asp?TID=10694
Printed Date: 21 November 2024 at 9:53am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: MFC. Extract text from markup
Posted By: zaksoft
Subject: MFC. Extract text from markup
Date Posted: 20 May 2008 at 4:09am
I have the need to get text from a makup control. This control is a preview of some information and it's very fancy to present to user information in a rich way, but I also need to store these information on request... At this point I can of course rebuild all information without markup.. but the better way (for me of course) is to have a command that remove <bold>, <grid> and so on from the full string.
 
Any hint ?
 
TIA


-------------
VS2022 - MFC MBCS Statically linked

XTP 23.1 Static Link

---------------------------------------------------------

Davide Zaccanti - ZakSoft - www.zaksoft.com




Replies:
Posted By: Oleg
Date Posted: 20 May 2008 at 1:45pm
Hi,
 
Here some start:
 
if (pUIElement)
 {
  for (int i = 0; i < pUIElement->GetVisualChildrenCount(); i++)
  {
   CXTPMarkupVisual* pVisual = pUIElement->GetVisualChild(i);
   if (pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun)))
   {
    CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual;
    CString str = p->GetText();
...   
}
  [ CallRec(pVisual);]

  }
 }
 
so you need call it recursively and find all Runs.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: zaksoft
Date Posted: 28 May 2008 at 3:00am
to your markupstatic.cpp code in markup sample I've added this function:
 
void CMarkupStatic::GetInnerText( CString& sContent, CXTPMarkupVisual* pParent){

ASSERT( pParent);

for (int i = 0; i < pParent->GetVisualChildrenCount(); i++)

{

CXTPMarkupVisual* pVisual = pParent->GetVisualChild( i);

ASSERT( pVisual);

if ( pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun)))

{

CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual;

sContent += p->GetText();

}

GetInnerText( sContent, pVisual);

}

}

Called as

GetInnerText( sContent, m_pUIElement);

but the resulting string is empty... what's wrong ? can you please help me ?
 
TIA


-------------
VS2022 - MFC MBCS Statically linked

XTP 23.1 Static Link

---------------------------------------------------------

Davide Zaccanti - ZakSoft - www.zaksoft.com



Posted By: zaksoft
Date Posted: 03 June 2008 at 1:45pm
Anyone can help me in make the previous code working ?
 
TIA


-------------
VS2022 - MFC MBCS Statically linked

XTP 23.1 Static Link

---------------------------------------------------------

Davide Zaccanti - ZakSoft - www.zaksoft.com



Posted By: Oleg
Date Posted: 03 June 2008 at 2:16pm
Hi,
 
Here working version. Sorry need Logical Childs:
 

void CMarkupStatic::GetInnerText( CString& sContent, CXTPMarkupObject* pParent)

{

ASSERT( pParent);

for (int i = 0; i < pParent->GetLogicalChildrenCount(); i++)

{

CXTPMarkupObject* pVisual = pParent->GetLogicalChild(i);

ASSERT( pVisual);

if ( pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun)))

{

CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual;

sContent += p->GetText();

}

 

GetInnerText( sContent, pVisual);

}

}



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: zaksoft
Date Posted: 03 June 2008 at 4:08pm
thank you, this code works and with some small enhancements I've added the auto-recognition of TaskPanel end to add a CR+LF to break block of text (and also spaces betwwen block).
 
What I'm not able to do is insert line feed after a row of a grid, infact using border as marker a line feed is added after each column.
 
two questions:
 
1) Any suggestion to detect end of row ?
2) Do you plan o add a more generic and well done function to extract text in future release ?
 
Thank you agin for your support.


-------------
VS2022 - MFC MBCS Statically linked

XTP 23.1 Static Link

---------------------------------------------------------

Davide Zaccanti - ZakSoft - www.zaksoft.com




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net