j***@gmail.com
2006-04-27 06:09:54 UTC
Hi everybody:
I'm working under Windows XP + SP2 + VC6, C language, using WIN32
function (NOT MFC).
I load library by: LoadLibraryEx("RICHED32.DLL",NULL,0);
I use window class: RICHEDIT_CLASS
Now I'm wring a function Insert(text, font, text_color) to insert some
text to this common control with given font and text_color, but I do
not want the default color and font be effected. That is, when I type
sth in rich edit control, it use the default font and color:
void Insert (text, font, text_color)
{
CHARFORMAT dft_cft;
SendMessage(hwnd,EM_GETCHARFORMAT ,
SCF_SELECTION,(LPARAM)&dft_cft); // save default font and color
.......................//here we insert the text
//then we reset the rich edit control's every insertion point's font
and color
{
int new_sel_range;
int i;
int n;
SendMessage(hwnd,EM_SETSEL,0,-1); //select all
new_sel_range = SendMessage(hwnd,EM_GETSEL,0,0);
n = HIWORD(new_sel_range)-2; //n is the number of chars in
rich edit now
for(i=0;i<=n;++i){
SendMessage(hwnd,EM_SETSEL,i,i); //select at position i
SendMessage(hwnd,EM_SETCHARFORMAT ,
SCF_SELECTION,(LPARAM)&dft_cft);//set insertion point i to use default
font and color
}
}
}
But I'm sad to find that it does not work. After Insert is called, if
I type sth in rich edit control, the char will follow the font and
color of its previous neighbourhood,that is, the char just before it!
So what's wrong? Any advice is welcome, thx.
I'm working under Windows XP + SP2 + VC6, C language, using WIN32
function (NOT MFC).
I load library by: LoadLibraryEx("RICHED32.DLL",NULL,0);
I use window class: RICHEDIT_CLASS
Now I'm wring a function Insert(text, font, text_color) to insert some
text to this common control with given font and text_color, but I do
not want the default color and font be effected. That is, when I type
sth in rich edit control, it use the default font and color:
void Insert (text, font, text_color)
{
CHARFORMAT dft_cft;
SendMessage(hwnd,EM_GETCHARFORMAT ,
SCF_SELECTION,(LPARAM)&dft_cft); // save default font and color
.......................//here we insert the text
//then we reset the rich edit control's every insertion point's font
and color
{
int new_sel_range;
int i;
int n;
SendMessage(hwnd,EM_SETSEL,0,-1); //select all
new_sel_range = SendMessage(hwnd,EM_GETSEL,0,0);
n = HIWORD(new_sel_range)-2; //n is the number of chars in
rich edit now
for(i=0;i<=n;++i){
SendMessage(hwnd,EM_SETSEL,i,i); //select at position i
SendMessage(hwnd,EM_SETCHARFORMAT ,
SCF_SELECTION,(LPARAM)&dft_cft);//set insertion point i to use default
font and color
}
}
}
But I'm sad to find that it does not work. After Insert is called, if
I type sth in rich edit control, the char will follow the font and
color of its previous neighbourhood,that is, the char just before it!
So what's wrong? Any advice is welcome, thx.