The MASM Forum

General => The Campus => Topic started by: xandaz on November 07, 2021, 08:04:58 AM

Title: Perfectlly working FindText routine
Post by: xandaz on November 07, 2021, 08:04:58 AM
    Here it is: .elseif uMsg==edi ; FINDMSGSTRING
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
invoke GetWindowLong,eax,GWL_USERDATA

mov edi,eax
mov esi,lParam

assume  esi:PTR FINDREPLACE

                xor            ebx,ebx
test [esi.FINDREPLACE].Flags,FR_DIALOGTERM
jnz end_find
      mov ft.chrg.cpMax,-1
push [esi.FINDREPLACE].lpstrFindWhat
pop ft.lpstrText
test [esi].Flags,FR_DOWN
jz skip_1
or ebx,FR_DOWN
skip_1:
test [esi].Flags,FR_MATCHCASE
jz skip_2
or ebx,FR_MATCHCASE
skip_2:
test [esi].Flags,FR_WHOLEWORD
jz skip_3
or ebx,FR_WHOLEWORD
skip_3:
mov crange.cpMin,rv(SendMessage,[edi.MdiStruct.hEdit],EM_FINDTEXTEX,ebx,addr ft)
cmp eax,-1
je end_find_2
push crange.cpMin
pop ft.chrg.cpMin
test [esi].Flags,FR_DOWN
jz skip_4
inc ft.chrg.cpMin
jmp skip_5
skip_4:
dec ft.chrg.cpMin
skip_5:
invoke SendMessage,[edi.MdiStruct.hEdit],EM_EXSETSEL,0,addr ft.chrgText
invoke SendMessage,[edi.MdiStruct.hEdit],EM_HIDESELECTION,FALSE,0
invoke SendMessage,[edi.MdiStruct].hEdit,EM_SCROLLCARET,0,0
jmp end_find_2
end_find:
mov ft.chrg.cpMin,0
mov crange.cpMin,0
mov eax,TRUE
ret
end_find_2:
Title: Re: Perfectlly working FindText routine
Post by: mikeburr on November 07, 2021, 12:25:25 PM
i think its prob good practice to end the assume ... assume esi:NOTHING as from recollection its easy to get nesting.. 3 Levels ?? of assume then it fails
regards mikeb
Title: Re: Perfectlly working FindText routine
Post by: xandaz on November 07, 2021, 07:40:21 PM
   yeah. missed that. you're right
Title: Re: Perfectlly working FindText routine
Post by: jj2007 on November 07, 2021, 09:00:54 PM
The ASSUME is not needed at all. In general, it just obfuscates code and should be avoided.
push [esi.FINDREPLACE].lpstrFindWhat
pop ft.lpstrText
test [esi.FINDREPLACE].Flags,FR_DOWN
jz skip_1
or ebx,FR_DOWN
skip_1:
test [esi.FINDREPLACE].Flags,FR_MATCHCASE
Title: Re: Perfectlly working FindText routine
Post by: xandaz on November 07, 2021, 09:22:53 PM
   Surelly. Nice!
Title: Re: Perfectlly working FindText routine
Post by: mikeburr on December 02, 2021, 02:56:25 AM
@JJ
totally agree about ASSUME JJ .. also its not compatible with "similar" compilers
regards mike b