News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FindWindow

Started by mickalia, January 02, 2006, 08:20:47 PM

Previous topic - Next topic

mickalia

I am new to assembler and have been looking at the MASM examples, I program in Visual Basic.

My question is how do you get the return from FindWindow()

I know it won't be hwnd = findwindow("Blah","Blah") like in VB!


Also maybe an example to Loop until the return is more than 0 would be great,


Thanks in advance  :thumbu

MusicalMike

should be in the eax register, the eax register is commonly used for return values

mickalia


hutch--

Something like this.


invoke FindWindow,ADDR classname,ADDR winname
mov hFind, eax


You need to have the two string addresses available as zero terminated strings. From memory you can find the handle by supplying either of the two strings. Look the API up in win32.hlp or similar.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

P1

Quote from: mickalia on January 02, 2006, 08:20:47 PMAlso maybe an example to Loop until the return is more than 0 would be great,
in MASM32\Example1\WINENUM is a sample you should check out for checking all the windows.

Regards,  P1  :8)

mickalia

Thanks for the replys guys, heres what i got so far:

; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \MASM32\INCLUDE\shell32.inc

      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \MASM32\LIB\shell32.lib

; #########################################################################


        .data

       
        Whwnd          dd 0
        Wclass          db     "YahooBuddyMain",0
        Wname          db     "Yahoo! Messenger with Voice",0

     

                    .code
   

                    start:



                                              StartLoop:

                                                                      invoke FindWindow,ADDR Wclass,ADDR Wname
                                                                         
                                                                            cmp eax, 0
                                                             
                                                                            je ExitLoop

                                                                      jmp StartLoop

                                               ExitLoop:




                                              call ExitProcess


                    end start



I know where the main problem is (cmp eax, 0) but I don't know what to put for anything other than 0! >0? not 0? HELP! :red


Also how can I pause in the loop I tried sleep but that didnt work or I did it wrong?


Thanks again

hutch--

The example you have posted apart from being very badly formatted is not making sense. If the FindWindow() function is successful, it will find the window handle with one call, there is no need to loop through anything. If it cannot recognise a window by either its class name or its window title, then looping it will not work any better.

It looks like you need to learn some very basic assembler first as VB is not close enough to assembler for you to understand what is going on. All function returnes in 32 bit Windows return their values in the EAX register unless they are floating point functions exclusively but you are going to need to know something about what registers are and how to use them to get any results.

Try something like this AFTER the FindWindow call to know if you succeeded or not.

.data
  yes db "yes it is a window handle",0
  no  db "no its not a window handle",0
  ttl db "FindWindow Result",0
.code
.if eax != 0
  invoke MessageBox,0,ADDR yes,ADDR ttl,0
.else
  invoke MessageBox,0,ADDR no,ADDR ttl,0
.endif
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

mickalia

Thanks for the reply.

Please tell me why it is very badly formatted (so I can improve it) ?

Also, it does make sense, maybe its me that didn't make sense explaining what I want to do.

The window I want to find with findwindow may or may not already be in use, if it is in use it will find it with one call like you said. But if it is not in use, it will find it as soon as it is in use (loop).

I understand what the code is doing, and what I am trying to do, I just don't know no where near enough to solve it alone, hence this post. I will take in all replys to learn from.

mickalia


    StartLoop:
    invoke FindWindow,ADDR classname,ADDR winname
     .if eax != 0
   je ExitLoop
.else
  jmp StartLoop
.endif
     


Works great though!  :clap:

mickalia

QuoteStartLoop:
    invoke FindWindow,ADDR classname,ADDR winname
 
     .if eax != 0
   je ExitLoop
.else
  invoke Sleep,100
  jmp StartLoop
.endif

Infact thats better, lol.

gabor

Hi!

In this case (in your last but one post of code) I personally would not use the if macro (this my personally opinion and taste). This is what I would do:

StartLoop:
  invoke FindWindow,ADDR classname,ADDR winname
  or eax,eax        ; this returns zero->ZF=1 when eax=0
  jnz StartLoop     ; jz (jump if zero)=je (jump if equal)

I think you should make a jump only when eax is NOT zero, this would be a jump backward. Else the loop simply ends...
Why is your code better with that Sleep call inserted? Maybe I got wrong what you want to do...

To learn you have choosen the perfect place. I have learnt a lot here, I really like this forum. It is full of creative helpful fellows who are thinking the same way (in 89%) like I do... Have fun here!

Greets,Gábor

mickalia

  :U

Just added the sleep so the loop doesnt take up all the cpu

P1

mickalia,

Welcome to MASMforum!       

Read around the different areas and get a feel for the place.         

Read the help files and tutorials of MASM32.   It's best, if you download the most recent MASM32 package and install it. 

'Search' & Google are your friends for programming.  Then ask your questions.

It's easier just to look for the program file to see if it is running.

Would be nice to tell us what you are trying to accomplish with the Find ?

Sometime the problem is not in code, but the method.

Regards,  P1  :8)

mickalia

Thanks for all the replys.


Well to be honest there is no real reason, I am just dipping my toes into the water with this language. Since reading the replys to this, the assembler code actually is making sense to me and I am understanding what is going on (to an extent), which is great!

What I was trying to do as sort of a personal task was execute the default browser with shellexecute, loop around until its on screen and then do something to it, click a menu item or something. Now I have the code to do this all working and I understand it, this is probley the best way I can learn. I love API!


mickalia

I will get reading them tutorials soon, I have MASM32 ( I will update it ) , but to be honest I have just been using notepad.