Getting the handle of a window?
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)

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!
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!

Here.. and no more crashes
lol... thx again Henrik.

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
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.
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:
Best Regards
Henrik

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.

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)
Henrik
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
.
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.
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

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.