2
/*--------------------------------------------------------
3
POPFIND.C -- Popup Editor Search and Replace Functions
4
--------------------------------------------------------*/
11
#define MAX_STRING_LEN 256
13
static char szFindText [MAX_STRING_LEN] ;
14
static char szReplText [MAX_STRING_LEN] ;
16
HWND PopFindFindDlg (HWND hwnd)
18
static FINDREPLACE fr ; // must be static for modeless dialog!!!
20
fr.lStructSize = sizeof (FINDREPLACE) ;
23
fr.Flags = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
24
fr.lpstrFindWhat = szFindText ;
25
fr.lpstrReplaceWith = NULL ;
26
fr.wFindWhatLen = sizeof (szFindText) ;
27
fr.wReplaceWithLen = 0 ;
30
fr.lpTemplateName = NULL ;
32
return FindText (&fr) ;
35
HWND PopFindReplaceDlg (HWND hwnd)
37
static FINDREPLACE fr ; // must be static for modeless dialog!!!
39
fr.lStructSize = sizeof (FINDREPLACE) ;
42
fr.Flags = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
43
fr.lpstrFindWhat = szFindText ;
44
fr.lpstrReplaceWith = szReplText ;
45
fr.wFindWhatLen = sizeof (szFindText) ;
46
fr.wReplaceWithLen = sizeof (szReplText) ;
49
fr.lpTemplateName = NULL ;
51
return ReplaceText (&fr) ;
54
BOOL PopFindFindText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE pfr)
57
PSTR pstrDoc, pstrPos ;
59
// Read in the edit document
61
iLength = GetWindowTextLength (hwndEdit) ;
63
if (NULL == (pstrDoc = (PSTR) malloc (iLength + 1)))
66
GetWindowText (hwndEdit, pstrDoc, iLength + 1) ;
68
// Search the document for the find string
70
pstrPos = strstr (pstrDoc + *piSearchOffset, pfr->lpstrFindWhat) ;
73
// Return an error code if the string cannot be found
78
// Find the position in the document and the new start offset
80
iPos = pstrPos - pstrDoc ;
81
*piSearchOffset = iPos + strlen (pfr->lpstrFindWhat) ;
83
// Select the found text
85
SendMessage (hwndEdit, EM_SETSEL, iPos, *piSearchOffset) ;
86
SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0) ;
91
BOOL PopFindNextText (HWND hwndEdit, int *piSearchOffset)
95
fr.lpstrFindWhat = szFindText ;
97
return PopFindFindText (hwndEdit, piSearchOffset, &fr) ;
100
BOOL PopFindReplaceText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE pfr)
104
if (!PopFindFindText (hwndEdit, piSearchOffset, pfr))
109
SendMessage (hwndEdit, EM_REPLACESEL, 0, (LPARAM) pfr->lpstrReplaceWith) ;
114
BOOL PopFindValidFind (void)
116
return *szFindText != '\0' ;