· Начало · Отвђтить · Статистика · Поиск · FAQ · Правила · Установки · Язык · Выход · WASM.RU · Noir.Ru ·

 WASM Phorum —› WASM.WIN32 —› Поиск слова в строке.

Посл.отвђт Сообщенiе


Дата: Июн 9, 2004 12:13:25

Получаю заголовок окна:
Buf.
invoke GetForegroundWindow
invoke SendMessage, eax, WM_GETTEXT, 1024, addr 

нужно найти слово в заголовке. Например "Mozilla", как это сделать?
Спасибо.


Дата: Июн 9, 2004 12:19:42

1) У masm32 есть:
Syntax: @InStr([position], string1, string2)
2) Напиши свою


Дата: Июн 9, 2004 13:02:19

2PavPS, можно по-подробнее? что такое string1 и string2?


Дата: Июн 9, 2004 13:10:09

ЭТО ХЭЛП MASM32 V 8.1

INSTR

Syntax: @InStr([position], string1, string2)

name INSTR [position,] textitem1, textitem2

Description
The @InStr macro function searches for the first occurrence of
<string2> inside <string1> and returns the position of the
first character of the match. The search begins at <position>,
if you give that parameter. The @InStr function will not expand
macros or expressions unless you use the expression operator (%).


The first character is indexed as 1. @InStr returns 0 if
<string1> is not found.

The INSTR directive performs the same function as @InStr but
assigns the result to <name>. These two lines are equivalent:

develop TEXTEQU @InStr (2, <MikeBobMichaelJim>, <Mi>)
develop INSTR 2, <MikeBobMichaelJim>, <Mi>
;develop is now 8

Parameter Description

name Name of the resulting constant.


position Starting character position of the search
(default 1). Must be a positive integer.

string1 String being searched; any text.

string2 String to search for; any text.

textitem1 String being searched; any text item.

textitem2 String to search for; any text item.
-o-

3) Могу дать свою процедуру

300959178__instr


Дата: Июн 9, 2004 13:51:20

Спасибо! =) попробую разобраться.


Дата: Июн 12, 2004 08:40:21

Вот что у меня получилось. Работает.


.386
.model flat,stdcall
option casemap:none



include include\windows.inc
include include\user32.inc
include include\MASM32.INC
include include\shlwapi.inc
includelib lib\user32.lib
include include\kernel32.inc
includelib lib\kernel32.lib
includelib lib\shlwapi.lib
includelib lib\MASM32.lib
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
.DATA
Buf db 1024 dup (?)
buffer db "mas",0
.code
InStringx proc startpos:DWORD,lpSource:DWORD,lpPattern:DWORD

LOCAL sLen:DWORD
LOCAL pLen:DWORD

push ebx
push esi
push edi

invoke StrLen,lpSource
mov sLen, eax ; source length
invoke StrLen,lpPattern
mov pLen, eax ; pattern length

cmp startpos, 1
jge @F
mov eax, -2
jmp isOut ; exit if startpos not 1 or greater
@@:

dec startpos ; correct from 1 to 0 based index

cmp eax, sLen
jl @F
mov eax, -1
jmp isOut ; exit if pattern longer than source
@@:

sub sLen, eax ; don't read past string end
inc sLen

mov ecx, sLen
cmp ecx, startpos
jg @F
mov eax, -2
jmp isOut ; exit if startpos is past end
@@:

; ----------------
; setup loop code
; ----------------
mov esi, lpSource
mov edi, lpPattern
mov al, [edi] ; get 1st char in pattern

add esi, ecx ; add source length
neg ecx ; invert sign
add ecx, startpos ; add starting offset

jmp Scan_Loop



; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Pre_Scan:
inc ecx ; start on next byte

Scan_Loop:
cmp al, [esi+ecx] ; scan for 1st byte of pattern
je Pre_Match ; test if it matches
inc ecx
js Scan_Loop ; exit on sign inversion

; cmp ecx, 0 ; works but 1 instruction longer
; jl Scan_Loop

jmp No_Match

Pre_Match:
lea ebx, [esi+ecx] ; put current scan address in EBX
mov edx, pLen ; put pattern length into EDX

Test_Match:
mov ah, [ebx+edx-1] ; load last byte of pattern length in main string
cmp ah, [edi+edx-1] ; compare it with last byte in pattern
jne Pre_Scan ; jump back on mismatch
dec edx
jnz Test_Match ; 0 = match, fall through on match

; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Match:
add ecx, sLen
mov eax, ecx
inc eax
jmp isOut

No_Match:
xor eax, eax

isOut:
pop edi
pop esi
pop ebx

ret

InStringx endp


start:
invoke GetForegroundWindow
invoke SendMessage, eax, WM_GETTEXT, 1024, addr Buf
invoke InStringx,1,ADDR Buf, ADDR buffer
.IF eax !=0
jmp @F
szDlgTitle db "MASM", 0

@@:

push MB_OK
push offset szDlgTitle
push offset szDlgTitle
push 0
call MessageBox

push 0
call ExitProcess
.ENDIF
END start


Powered by miniBB 1.6 © 2001-2002
Время загрузки страницы (сек.): 0.098