-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.asm
159 lines (116 loc) · 3.84 KB
/
search.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
; #########################################################################
CallSearchDlg proc
invoke DialogBoxParam,hInstance,300,hWnd,ADDR SearchProc,0
ret
CallSearchDlg endp
; #########################################################################
SearchProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
LOCAL hEdit :DWORD
LOCAL cr :CHARRANGE
mov cr.cpMin, 0
mov cr.cpMax, 0
.if uMsg == WM_INITDIALOG
szText dlgTitle," Find Text"
invoke SendMessage,hWin,WM_SETTEXT,0,ADDR dlgTitle
invoke GetDlgItem,hWin,3093
mov hCheck1, eax
invoke GetDlgItem,hWin,3094
mov hCheck2, eax
.if CaseFlag == 1
invoke SendMessage,hCheck1,BM_SETCHECK,BST_CHECKED,0
.endif
.if WholeWord == 1
invoke SendMessage,hCheck2,BM_SETCHECK,BST_CHECKED,0
.endif
.elseif uMsg == WM_COMMAND
.if wParam == 3091 ; cancel button
jmp OutaHere
.elseif wParam == IDOK ; default enter key
jmp FindMe
.elseif wParam == 3090 ; find button
FindMe:
invoke GetDlgItem,hWin,3092
mov hEdit, eax
invoke SendMessage,hEdit,WM_GETTEXTLENGTH,0,0
mov TextLen, eax
.if TextLen == 0
return 0
.else
invoke SendMessage,hCheck1,BM_GETCHECK,0,0
.if eax == BST_CHECKED
mov CaseFlag, 1
.else
mov CaseFlag, 0
.endif
invoke SendMessage,hCheck2,BM_GETCHECK,0,0
.if eax == BST_CHECKED
mov WholeWord, 1
.else
mov WholeWord, 0
.endif
inc TextLen
invoke SendMessage,hEdit,WM_GETTEXT,TextLen,ADDR SearchText
invoke TextFind,ADDR SearchText,TextLen
jmp OutaHere
.endif
.elseif wParam == IDCANCEL ; default escape button
jmp OutaHere
.endif
.elseif uMsg == WM_CLOSE
OutaHere:
invoke EndDialog,hWin,0
.endif
mov eax, 0
ret
SearchProc endp
; #########################################################################
TextFind proc lpBuffer:DWORD, len:DWORD
LOCAL tp :DWORD
LOCAL tl :DWORD
LOCAL sch:DWORD
LOCAL ft :FINDTEXT
LOCAL Cr :CHARRANGE
invoke SendMessage,hRichEd,EM_EXGETSEL,0,ADDR Cr
inc Cr.cpMin ; inc starting pos by 1 so not searching
; same position repeatedly
m2m ft.chrg.cpMin, Cr.cpMin ; start pos
m2m ft.chrg.cpMax, -1 ; end of text
m2m ft.lpstrText, lpBuffer ; string to search for
invoke SendMessage,hRichEd,WM_GETTEXTLENGTH,0,0
mov tl, eax
; 0 = case insensitive
; 2 = FT_WHOLEWORD
; 4 = FT_MATCHCASE
; 6 = FT_WHOLEWORD or FT_MATCHCASE
mov sch, 0
.if CaseFlag == 1
or sch, 4
or sch, FR_DOWN
.endif
.if WholeWord == 1
or sch, 2
or sch, FR_DOWN
.endif
invoke SendMessage,hRichEd,EM_FINDTEXT,sch,ADDR ft
mov tp, eax
.if tp == -1
mov Cr.cpMin, 0
szText nomatch,"No further matches"
invoke MessageBox,hWnd,ADDR nomatch,ADDR szDisplayName,MB_OK
ret
.endif
m2m Cr.cpMin,tp ; put start pos into structure
dec len ; dec length for zero terminator
mov eax, len
add tp,eax ; add length to character pos
m2m Cr.cpMax,tp ; put end pos into structure
; ------------------------------------
; set the selection to the search word
; ------------------------------------
invoke SendMessage,hRichEd,EM_EXSETSEL,0,ADDR Cr
ret
TextFind endp
; #########################################################################