Is there any way to use wild cards win invoke findwindow?

For example if a couple different versions of a window Im looking for are the same except they end with different letters.
(program V1a or program V1b or program V1c)

Posted on 2005-07-24 19:47:42 by UPucker
You can use a GetWindow loop in combination with a wildcard match (aka "globbing") function

Here is an excerpt from one of my programs:

stdcall ,eax,GW_CHILD
mov ebx,eax
.wnd: stdcall ,ebx,OFFSET szTitle,200h
stdcall match,OFFSET szTitlePattern,OFFSET szTitle
test eax,eax
jnz .IsMatch
stdcall ,ebx,GW_HWNDNEXT
test eax,eax
mov ebx,eax
jnz .wnd

szTitlePattern db "V1*",0

; #### GLOBBING FUNCTION - AMERICA F*CK YEAH! ####################
match: ; mask,string
push ebx esi edi
mov esi, ; mask
mov edi, ; string
xor ebx,ebx
jmp .chkz
.next: movzx eax,byte
cmp eax,"*"
jne .cmp1
inc ebx
inc esi
jmp .chkz
.cmp1: test ebx,ebx
jz .nowc
mov edx,esi
mov ecx,edi
.cmp2: movzx eax,byte
cmp eax,"*"
je .cmp3
test eax,eax
jz .cmp3
cmp eax,"?"
je .sc
lcase al
mov ah,
lcase ah
cmp al,ah
jne .cmp3
.sc: inc edx
inc ecx
jmp .cmp2
.cmp3: je .cmp4
inc edi
cmp byte ,0
jnz .next
xor eax,eax
jmp .quit
.cmp4: xor ebx,ebx
jmp .mtch
.nowc: cmp al,"?"
je .mtch
lcase al
mov ah,
lcase ah
cmp al,ah
je .mtch
xor eax,eax
jmp .quit
.mtch: xor ebx,ebx
inc esi
inc edi
.chkz: cmp byte ,0
jne .next
xor eax,eax
inc eax
cmp byte ,0
je .quit
mov eax,ebx
.quit: pop edi esi ebx
retn 08h

; #### LOWERCASE MACRO ###############3
macro lcase expr {
local .over
cmp expr,"Z"
ja .over
cmp expr,"A"
jb .over
add expr,32
Posted on 2005-07-24 19:52:54 by comrade
I'm not certain, but I don't think so. BUT instead you could loop trought all windows and check the strings if the start match.
Posted on 2005-07-24 19:53:12 by _Christopher
How would this be done in with masm?

Posted on 2005-07-25 01:56:27 by UPucker
Did you look at comrade's examplecode? Well I'm thinking of writing some code on my own for that use (it could get useful).
Some psuedocode:

  • Get byte

  • Just skip (then do a usual match) it if's not * or 0x00

  • If's a ?, skip that too

  • If the bytes doesn't match, exit

  • If it's a *, check next byte if the string will end

  • If it's the end, just exit, match successful

  • If it's not the end, check the same things but backwards

Well that will only work for a single *, but it's better than nothing. IF and then when I written some code, I shall post it, but I have to wake up now...
Posted on 2005-07-25 05:29:54 by _Christopher
doesnt enumwindows produces the loop ?? and enumerates all top level windows and gives you the handle to every top level window ??

00401000 >PUSH    0                                ; /lParam = 0
00401002  PUSH    msgbox.00401013                  ; |Callback = msgbox.00401013
00401007  CALL    <JMP.&user32.EnumWindows>        ; \EnumWindows
0040100C  PUSH    0                                ; /ExitCode = 0
0040100E  CALL    <JMP.&kernel32.ExitProcess>      ; \ExitProcess
00401013  PUSH    EBP
00401014  MOV    EBP, ESP
00401016  PUSH    500                              ; /Count = 500 (1280.)
0040101B  PUSH    msgbox.0040301C                  ; |Buffer = msgbox.0040301C
00401020  PUSH    DWORD PTR SS:            ; |hWnd = 00401000
00401023  CALL    <JMP.&user32.GetWindowTextA>    ; \GetWindowTextA
00401028  PUSH    msgbox.00403000                  ; /String2 = "Iczelion's tutorial no.2"
0040102D  PUSH    msgbox.0040301C                  ; |String1 = "Iczelion's tutorial no.2"
00401032  CALL    <JMP.&kernel32.lstrcmpA>        ; \lstrcmpA
00401037  OR      EAX, EAX
00401039  JNZ    SHORT msgbox.00401044
0040103B  MOV    EAX, 0
00401040  LEAVE
00401041  RETN    8
00401044  MOV    EAX, 1
00401049  LEAVE
0040104A  RETN    8

Posted on 2005-07-25 07:16:36 by bluffer