Getting the handle of a window?

Just starting out? Need help? Post your questions and find answers here.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

seems that it cant find "Winamp 2.91" thats why repeats all time.. lets check what it debugged and find if theres something about winamp at there
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

ya.. theres no winamp 2.91 but theres

Winamp Playlist Editor
Winamp Minibrowser
Winamp Video
Winamp Equalizer
17. Clubbers Bible Winter 2003 - Track 6 - Winamp [Stopped]

:roll:
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

I'll tell you that the "winamp 2.91" only appears when NOT playing music.. when you're playing music, the title goes "MUSIC TITLE + Winamp" :) so.. gotta make something I have in mind.. I think it will work.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

GOT IT!


Code: Select all



Repeat 
  hwin=FindWindow_(0,0) 
  
  While hwin<>0 ;And oldwin <>win 
    
    MemID= AllocateMemory (255) 
    GetWindowText_ (hwin, MemID, 255) 
    Wintitle$ = PeekS (MemID) 
    
    Debug Wintitle$ 
    GetWindowThreadProcessId_(hwin,@ProcessId.l) 
   
    Finding = FindString(Wintitle$,"- Winamp",0)
    If Finding 
      Debug "Winamp 2.91' processID : " +StrU(ProcessId,#Long) 
      Break 
    EndIf 
    hwin=GetWindow_(hwin,#GW_HWNDNEXT) 
  Wend 
Until hwin 



Debug "WindHandler =: "+Str(hwin) 
Debug " " 
Debug " Wait 4 sec." 
Debug " And I do a CloseWindow_(hwin) on Winamp" 

Delay (4000) 
CloseWindow_(hwin)


:)
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

:)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

You know whats funny?... I was updating that code so it works when you have no current mp3 at winamp, else your pc could crash.. well! I was adding the second if (something like if Wintitle$ = "Winamp 2.91")

but.. I forgot to move the WEND.. so, guess what happend when I compiled it and my winamp had no current mp3.. memory started to get eaten by the program, SMC crashed and many others.. no icons, no nothing.. messengers went off, nothing was working of course (no smc.. no internet). firewall crashed, well.. even the services, everything!.. so.. just pressed reset, and as I had some time I even upgraded my firewall to a newer version, as my SMC was using so many cpu usage that I coudlnt connect to my adsl server.. well gotta finish programming this, at least I learnt something today... to CHECK WENDs! :P
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Here.. and no more crashes :wink:

Code: Select all


Repeat 
  hwin=FindWindow_(0,0) 
  
  While hwin<>0 ;And oldwin <>win 
    
    MemID= AllocateMemory (255) 
    GetWindowText_ (hwin, MemID, 255) 
    Wintitle$ = PeekS (MemID) 
    
    Debug Wintitle$ 
    GetWindowThreadProcessId_(hwin,@ProcessId.l) 
   
    Finding = FindString(Wintitle$,"- Winamp",0)
    If Finding
      Debug "Winamp 2.91' processID : " +StrU(ProcessId,#Long) 
      Break 
    EndIf 
    hwin=GetWindow_(hwin,#GW_HWNDNEXT) 

  If Wintitle$ = "Winamp 2.91"
    Debug "Winamp 2.91' processID : " +StrU(ProcessId,#Long) 
    Break 
  EndIf 
  
Wend 

Until hwin 



Debug "WindHandler =: "+Str(hwin) 
Debug " " 
Debug " Wait 4 sec." 
Debug " And I do a CloseWindow_(hwin) on Winamp" 

Delay (4000) 
CloseWindow_(hwin)

lol... thx again Henrik.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Lol :)
It's kind off funny, early on when stuff like that happend to me, i used to get mad but with PB i take things more as they come. 8)

Anyway 2 things about the code.
First off when you do this make sure that you are looking for something unique about the window, this might be different in other ver. off winamp.
There is a extensive code on the german forumm, which can help when you wanna find something unique like the [Class] name for the window. i try to find it and post it here as it ain't on the CodeArchiv either. :?:

Well about the code it self:
You don't need "ProcessId", this is a left over from when we checked for the exe file "Winamp.exe" and got the ProcessID and then compared it to the one we got from Findwindow ~(Sorry it's hard for me to be short in english)~ 8O

And the "hwin=GetWindow_(hwin,#GW_HWNDNEXT)" should be the last before "Wend"
Now your are goging for the next window before you check "If Wintitle$ = "Winamp 2.91"
So first when nothing was found then we whant the next window in line.

so the shortest ver. would be something like this:

Code: Select all

Repeat
    hwin=FindWindow_(0,0)
    
    While hwin<>0 ;And oldwin <>win
        
        MemID= AllocateMemory (255)
        GetWindowText_ (hwin, MemID, 255)
        Wintitle$ = PeekS (MemID)
        
        Debug Wintitle$
        
        
        Finding = FindString(Wintitle$,"- Winamp",0)
        If Finding
            Debug "Winamp 2.91' Found: "
            Break
        ElseIf Wintitle$ = "Winamp 2.91"
            Debug "Winamp 2.91' Found: " 
            Break
        EndIf
        ; nothing found, next window then.        
        hwin=GetWindow_(hwin,#GW_HWNDNEXT) 
    Wend
    
Until hwin



Debug "WindHandler =: "+Str(hwin)
Debug " "
Debug " Wait 4 sec."
Debug " And I do a CloseWindow_(hwin) on Winamp"

Delay (4000)
Best Regards
Henrik
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

I know about the versions... and I've seen that from the 2.91 at the 5.03 the caption is the title of the song + "- Winamp" and when its not playing, it's "Winamp "+VERSION$.. so I just look for Winamp 2,3,5 doesnt matter if its 2.1 .. I just look for "Winamp 3". Thats my fix for that.

And I know about what you said about the getwindow line.. i've seen it after I posted it, but I thought that posting more will be a good reason for banning me or something :oops: .

I already checked my new source with Winamp 2.91 and 5.03.. worked with out problems. so i'll be working on the utility which is more for getting info about winamp and also streaming your own winamp to the net.. (this worked at the first version I made of this proggy, but well... nedded more features) i'll post some info l8r.

cya and thx again.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply