Pelles C forum
C language => Beginner questions => Topic started by: Grincheux on March 19, 2015, 07:29:49 PM
-
Normally that would research a string into the richedit editor. But it's not what I get.
EM_FINDTEXTEX returns 0 and both cpMin, cpMax = 0.
Do I have to convert the input string to UniCode?
In WM_INITDIALOG I have the string I want to search. The problem isin the case IDC_BUTTON_01
Need your help?
Thanks in advance
LRESULT CALLBACK FindDlgProc(HWND __hWnd,UINT __uMsg,WPARAM __wParam,LPARAM __lParam)
{
int _iID ;
HWND _hEdit ;
TCITEM _Tci ;
LPEDI_FIND_STRING _lpEdit_Find ;
_iID = LOWORD(__wParam) ;
switch (__uMsg)
{
case WM_INITDIALOG : SendMessage(GetDlgItem(__hWnd,IDC_STATIC_01),WM_SETFONT,(WPARAM) hFont_00,TRUE) ;
SendMessage(GetDlgItem(__hWnd,IDC_EDIT_01),WM_SETFONT,(WPARAM) hFont_00,TRUE) ;
memset(&Edit_Find,0,sizeof(EDI_FIND_STRING)) ;
Edit_Find.Text.cb = MAX_STRING ;
Edit_Find.Text.codepage = CP_ACP ;
Edit_Find.Text.flags = GT_SELECTION ;
Edit_Find.Text.lpDefaultChar = NULL ;
Edit_Find.Text.lpUsedDefChar = NULL ;
_Tci.mask = TCIF_PARAM ;
TabCtrl_GetItem(hTabTop,TabCtrl_GetCurSel(hTabTop),&_Tci) ;
_hEdit = ((LPEDI_WORK) _Tci.lParam)->hEdit ;
SendMessage(_hEdit,EM_GETTEXTEX,(WPARAM) &Edit_Find.Text,(LPARAM) Edit_Find.szString) ;
SendMessage(_hEdit,EM_GETTEXTRANGE,0,(LPARAM) &Edit_Find.TextRange) ;
SetDlgItemText(__hWnd,IDC_EDIT_01,(LPSTR) Edit_Find.szString) ;
CheckRadioButton(__hWnd,IDC_RADIO_01,IDC_RADIO_03,IDC_RADIO_02) ;
return (TRUE) ;
case WM_COMMAND : switch(_iID)
{
case IDC_BUTTON_01 : _lpEdit_Find = &Edit_Find ;
Edit_Find.bFind = 0 ;
if(IsDlgButtonChecked(__hWnd,IDC_CHECK_01) == BST_CHECKED)
Edit_Find.bFind |= FR_WHOLEWORD ;
if(IsDlgButtonChecked(__hWnd,IDC_CHECK_02) == BST_CHECKED)
Edit_Find.bFind |= FR_MATCHCASE ;
if(IsDlgButtonChecked(__hWnd,IDC_RADIO_03) == BST_CHECKED)
{
Edit_Find.Find.chrg.cpMin = 0 ;
Edit_Find.Find.chrg.cpMax = -1 ;
}
else
{
if(IsDlgButtonChecked(__hWnd,IDC_RADIO_02) == BST_CHECKED)
{
Edit_Find.bFind |= FR_DOWN ;
Edit_Find.Find.chrg.cpMin = Edit_Find.TextRange.chrg.cpMax ;
Edit_Find.Find.chrg.cpMax = -1 ;
}
else
{
Edit_Find.Find.chrg.cpMin = 0 ;
Edit_Find.Find.chrg.cpMax = Edit_Find.TextRange.chrg.cpMin ;
}
}
GetDlgItemText(__hWnd,IDC_EDIT_01,Edit_Find.szString,MAX_STRING) ;
Edit_Find.Find.lpstrText = Edit_Find.szString ;
SendMessage(hEdit,EM_FINDTEXTEX,(WPARAM) Edit_Find.bFind,(LPARAM) &Edit_Find.Find) ;
break ;
case IDOK : if(HIWORD(__wParam) == BN_CLICKED)
{
EndDialog(__hWnd,TRUE) ;
return (TRUE) ;
}
}
}
return (FALSE) ;
}
-
Do I have to convert the input string to UniCode?
Very unlikely, but why don't you test it?
-
Did you solve this problem? I am having a similar problem with EM_FINDTEXT.
-
Hi Grincheux,
Need your help?
Well unfortunately too much missing to try the code BUT are you selecting the text to search before initiating the search?
Edit_Find.Text.flags = GT_SELECTION <-- means search only selected text
might try GT_DEFAULT
Best initial Guess ---
John Z
Also .... would be helpful to actually check the return values from the SendMessage and GetDlgItemText functions...IMHO
Are you using
#define UNICODE
#define _UNICODE
?
-
Thanks, JohnZ. I tried a simplified version of my program and found that it needs to have unicode defined.
What's very annoying is that the lpstrText parameter of FINDTEXT did not flag up an error when I used non-unicode text.
I have a massive program that I had been developing and now I will have to change it to use unicode throughout.
-
Hi CFred,
I don't think you need to change your whole program. Just use the older version or Rich-Edit as long
as no Unicode characters are expected.
There are two:
RichEdit20W
and
RICHEDIT
The latter being ASCII. At version 1.5 RichEdit went unicode
Also you can force RichEdit20 to be ASCII or UNICODE- from MS
"The name of the Microsoft Rich Edit 1.0 window class is RichEdit. Microsoft Rich Edit 2.0 has both ANSI and Unicode window classes RichEdit20A and RichEdit20W, respectively. To specify the appropriate rich edit window class, use the RICHEDIT_CLASS constant, which the Richedit.h file defines depending on the definition of the UNICODE compile flag."
You can force the desired RichEdit20 by using RICHEDIT_CLASS which will automatically sest the class depending on the having or not having UNICODE defined.
John Z
-
Thanks, John Z.
Before I saw your latest reply I tried using FINDTEXT in its own module with only that module set up for Unicode and I found that FINDTEXT seems to work without any issues (I have the rich text control in a separate module that uses RichEdit50W).