flat assembler
Message board for the users of flat assembler.

Index > Main > Sending command to window ?

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 09 Mar 2011, 22:39
Hi everyone. I'm having trouble with windows.. Problem is that, I'm trying to get title if window, then child windows of that window and send command to click that or get text from there.. Problem is that, I need to get child window's class and then send or get message right ? I'm trying to work on Windows 7's calc.exe
Also, I'm using tool called ShoWin which shows window class and some info.. First, I'm getting window's class with tool, then calling FindWindow API and return are successful. After that, I'm trying to get button class but every button has same class called "Button" and can't get for example number 8 to click it. And also, tool shows result window's class is "Static" but FindWindowEx fails on that. Can someone explain me how to do this ? Thank you.
Post 09 Mar 2011, 22:39
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 10 Mar 2011, 12:12
Are you trying to us calc.exe for your in-program calculations? Smile
Post 10 Mar 2011, 12:12
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 10 Mar 2011, 12:22
mindcooler
No no mate, it's just example cause I need to work with another programs and having same trouble there. I even can't get title of button cause it doesn't have it. Only info I have is class name "Button", nothing else.. Any solutions for this ?
Post 10 Mar 2011, 12:22
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Mar 2011, 18:22
I think you can use SendMessage and WM_GETTEXT Question
Post 10 Mar 2011, 18:22
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 10 Mar 2011, 19:30
but how ? I don't know handle of the child window there..
Post 10 Mar 2011, 19:30
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Mar 2011, 19:39
The return value of FindWindow is the hWnd or you can use EnumChildWindows.
Post 10 Mar 2011, 19:39
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 10 Mar 2011, 20:12
Wow, didn't knew that. Can you write small example of all of this for me ? Cause I'm doing those things first time and I can't understand much.. Thanks for your support!
Post 10 Mar 2011, 20:12
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 10 Mar 2011, 21:46
Another problem is that I don't know which class, ID or caption it has. How can I find then with EnumChildWindow ?
Post 10 Mar 2011, 21:46
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 11 Mar 2011, 18:27
Most of the functions you need are defined in user32 and have references on MSDN. If you read up on EnumChildWindows it'll tell you how the handle is given to you in the EnumChildWindowsProc you give it.

To get the class ID use GetWindowClass and SendMessage with WM_GETTEXT or GetWindowText to get its caption.
Post 11 Mar 2011, 18:27
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 11 Mar 2011, 19:45
cod3b453
I got it but I will get all buttons and I don't know which one is button 4 from there. I'm just asking for little example if you can.. I don't understand other way sorry Sad
Post 11 Mar 2011, 19:45
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 11 Mar 2011, 23:02
This will print the hWnd for button 6
Code:
        include '%fasminc%/macro/import32.inc'
        include '%fasminc%/macro/proc32.inc'

format PE
entry Main

        BUFFER_SIZE     equ 32
        FALSE           equ 0
        TRUE            equ (not FALSE)
        WM_GETTEXT      equ 0x000D
        NULL            equ 0


section '.code' code readable executable

        proc Main

                ; Top level window
                invoke FindWindowEx,NULL,NULL,pszCalcFrame,NULL
                or eax,eax
                jz @f

                ; Sub level window
                invoke FindWindowEx,eax,NULL,pszCalcFrame,NULL
                or eax,eax
                jz @f

                ; Scan
                invoke EnumChildWindows,eax,EnumChildWindowsProc,NULL

            @@:

                xor eax,eax

                ret
        endp

        proc EnumChildWindowsProc,hWnd,lParam
                push ebx

                invoke FindWindowEx,[hWnd],NULL,pszButton,NULL
                or eax,eax
                jz @f

            .next:

                mov ebx,eax

                invoke SendMessage,ebx,WM_GETTEXT,BUFFER_SIZE,buffer
                or eax,eax
                jz @f

                invoke lstrcmp,psz6,buffer
                or eax,eax
                jnz .fail

                push ecx esi edi

                mov ecx,8
                mov esi,pszHex
                mov edi,pszHexEnd

            .loop:

                dec ecx
                dec edi

                mov eax,ebx
                and eax,0x0F
                mov al,byte [esi+eax]
                mov byte [edi],al

                shr ebx,4

                or ecx,ecx
                jnz .loop

                pop edi esi ecx

                invoke MessageBox,NULL,pszHexOut,psz6,NULL

                jmp @f

            .fail:

                invoke FindWindowEx,[hWnd],ebx,pszButton,NULL

                jmp .next

            @@:

                xor eax,eax
                not eax

                pop ebx
                ret
        endp



section '.data' data readable writable

        pszCalculator   db 'Calculator',0
        pszCalcFrame    db 'CalcFrame',0
        pszButton       db 'Button',0
        psz6            db '6',0
        pszFmt          db '%08x',0
        pszHexOut       db '        '
        pszHexEnd       db 0
        pszHex          db '0123456789ABCDEF',0

        buffer  rb BUFFER_SIZE


section '.idata' import data readable writable

        library kernel32,'KERNEL32.DLL',\
                user32,'USER32.DLL'

        import kernel32,\
                lstrcmp,'lstrcmpA',\
                Sleep,'Sleep'

        import user32,\
                EnumChildWindows,'EnumChildWindows',\
                FindWindowEx,'FindWindowExA',\
                MessageBox,'MessageBoxA',\
                SendMessage,'SendMessageA'
    
Post 11 Mar 2011, 23:02
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 11 Mar 2011, 23:36
cod3b453
EnumChildWindows function returns 0xFFFFFFFF and no messagebox or print are shown..
Post 11 Mar 2011, 23:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.