Codejock Forums Homepage
Forum Home Forum Home > General > XAML Snippets > Samples and Demo Applications
  New Posts New Posts RSS Feed - MFC. Extract text from markup
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MFC. Extract text from markup

 Post Reply Post Reply
Author
Message
zaksoft View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2003
Location: Italy
Status: Offline
Points: 162
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaksoft Quote  Post ReplyReply Direct Link To This Post Topic: MFC. Extract text from markup
    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

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
zaksoft View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2003
Location: Italy
Status: Offline
Points: 162
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaksoft Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
zaksoft View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2003
Location: Italy
Status: Offline
Points: 162
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaksoft Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
zaksoft View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2003
Location: Italy
Status: Offline
Points: 162
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaksoft Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.