C language > Beginner questions

What is wrong ?

(1/2) > >>

Grincheux:

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


--- Code: ---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) ;
}

--- End code ---

jj2007:

--- Quote from: Grincheux on March 19, 2015, 07:29:49 PM ---Do I have to convert the input string to UniCode?
--- End quote ---

Very unlikely, but why don't you test it?

CFred:
Did you solve this problem? I am having a similar problem with EM_FINDTEXT.

John Z:
Hi Grincheux,


--- Quote from: Grincheux on March 19, 2015, 07:29:49 PM ---Need your help?

--- End quote ---

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
?

CFred:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version