// JP opened flex table

Click to See Complete Forum and Search --> : [RESOLVED] Working with rich edit box.


Suresh.hc
February 19th, 2007, 07:21 AM
Hello All,

I have some text in the rich edit box , and a specific word.


I want to highlight that word in the rich edit box , word can occur multiple time, so word has to be highlighted in all lines.

Can anyone please give me some idea how I can proceed with this task …

Thanking you,

ovidiucucu
February 19th, 2007, 10:20 AM
See Syntax Hilighting (http://www.codeguru.com/cpp/controls/richedit/syntaxhilighting/) topics in Codeguru articles.
They are using MFC, but you can pick some ideas from there.

Suresh.hc
February 20th, 2007, 01:11 AM
Hi ovidiucucu,

Thanks for the response.

Link which u have give in only for MFC application. But it helped a lot thank you.

I have done MFC function for highlighting the word.



void HilightWords(char* word,HWND hwnd)
{

CHARFORMAT2 cf;
memset(&cf, 0, sizeof(CHARFORMAT2));
cf.cbSize = sizeof(CHARFORMAT2);
cf.dwMask = CFM_BOLD;
cf.dwEffects = CFE_BOLD;
COLORREF clr =RGB(255, 10, 15) ;
cf.dwMask =CFM_COLOR;
cf.crTextColor = clr;

FINDTEXTEX findText;
int foundCount = 0;
int foundPos = 0;

int wordLen = lstrlen(word);

findText.chrg.cpMin = 0;
findText.chrg.cpMax = -1;
findText.lpstrText = word;


}




The above code has no problem its working fine.


To find the position of the word below code works in MFC.
What all the changes I have to make it to change it to Win 32 app.




foundPos = m_RichEdit.FindText(FR_WHOLEWORD, &findText);

while (foundPos != -1)
{
m_RichEdit.SetSel(foundPos, foundPos + wordLen);
m_ RichEdit.SetSelectionCharFormat(cf);
findText.chrg.cpMin = foundPos + wordLen;
foundPos = m_RichEdit.FindText(FR_WHOLEWORD, &findText);
}



I am trying the win 32 Api in this way but I am getting error



//Handle to the Rich edit box
HWND hwndRichEdit = GetDlgItem(hwnd, IDC_FILECONT);
foundPos = SendMessage(hwndRichEdit,EM_FINDTEXT,FR_WHOLEWORD,(LPARAM)&findText);

while (foundPos != -1)
{
SendMessage(hwndRichEdit,EM_EXSETSEL,0,foundPos + wordLen);
SendMessage(hwndRichEdit,EM_GETCHARFORMAT,SCF_SELECTION,cf);
findText.chrg.cpMin = foundPos + wordLen;
foundPos = SendMessage(hwndRichEdit,EM_FINDTEXT,FR_WHOLEWORD,(LPARAM)&findText);
}



Error :-

error C2664: 'SendMessageA' : cannot convert parameter 4 from 'struct CHARFORMAT2A' to 'long'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.


Can u please tell me what all changes I have to make to above code. ?



Thanking you ,
Suresh HC

golanshahar
February 20th, 2007, 03:19 AM
I dont know on which exact line of ::SendMessage() you get this error but what you need to do is simply cast the structure to (LPARAM).

Cheers

Suresh.hc
February 20th, 2007, 03:34 AM
Hi golanshahar,



i am getting error in this statment

SendMessage(hwndRichEdit,EM_GETCHARFORMAT,SCF_SELECTION,cf);


cf is

CHARFORMAT2 cf;

I tryed with this code but still i am getting error
SendMessage(hwndRichEdit,EM_GETCHARFORMAT,SCF_SELECTION,(LPARAM)cf);


error : -

error C2440: 'type cast' : cannot convert from 'struct CHARFORMAT2A' to 'long'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.


can u please check all the SendMessage statment and tell what all the changes i have to make ??

humptydumpty
February 20th, 2007, 07:25 AM
try this

CHARFORMAT2 cf2;
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);


Thanx

Suresh.hc
February 20th, 2007, 07:40 AM
Thanks humpty its working …. Thank you very much.

humptydumpty
February 20th, 2007, 11:55 PM
you welcome :p

//JP added flex table