Referances or WinAmp?

Meowsers

New member
Joined
Aug 31, 2003
Messages
4
Okie, Im new to programming with APIs and dont have a lot of experience in VB and almost none in VB.NET that being said. . . help. Okie, so Im basically crawling through other peoples code thats similar to what Im trying to do and then trying it out myself. But everyone elses code is in VB 6.0 and Im trying to work in .NET, which might be causing my problems, or it might be other stuff I dont really know about. Okay so Im starting off pretty basic, and I THINK Im working with an API, cuz like I said Im new at this whole thang and could be posting in the complete wrong forum. So, hope your still with me :P.

Okay so all the code Ive looked at is using the FindWindow function to get a reference to the window I want to refrance, ok fine. But their all returning Integers and when I try to get it as an int I get 0. However when I change it to return a Long I get a value. Another strange thing happens though Im not sure if this is supposed to or not, but evertime I FindWindow with the same parameters I get a different value.

Ive tried working with the FindWindow on different programs and they work fine. Im having issues with WinAmp. I guess I should probably also tell you that Im not sure what references to add so Im not using any. This may be the problem?

This is probably a really dumb question so Id really appreciate like some quick answer, thanks.
 
Im not really sure about what you are saying about your FindWindow problem returning 0 everytime, can you show the code you are using? Integer should work good.
FindWindow returns you the handle to the window, and a new handle is assigned everytime a window is created so that why you get different values.
 
okie.
This is the code that gets me a handle.

Sitting in my module:
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String _
, ByVal lpWindowName As String) As Long

Sitting in some on_click function:
Code:
Dim WinAMPhWnd As Long
WinAMPhWnd = FindWindow("Winamp v1.x", vbNullString)

And then if I msgbox WinAMPhWnd I get a number, but if I use this:

Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String _ 
, ByVal lpWindowName As String) As Integer

with:
Code:
Dim WinAMPhWnd As Integer
WinAMPhWnd = FindWindow("Winamp v1.x", vbNullString)

and try to msgbox the handle it gives me 0. Which I believe means that there is no window with that name. But my winamp is running. Could this be a problem with the references? Or. . .? Thanks for your help.

And the thing about different values, I had one WinAmp player going. And I had a button to get the handle each time I clicked it, but every time I clicked it (without doing anything to winamp) it gave me a different value. It seems to me like I shouldnt need a reference just to get a window handle, but Im new so what do I know. Thanks again.
 
Last edited by a moderator:
First off you need to know that a long in vb.net is now and integer, and integer is now a short, and a byte is still a byte :).

You have to make the calls via integers not longs. You may notice that is you change your text to a window that doesnt exist, the longs will still return a value, different every time.

Im investigating the rest still.
 
Ok, I have a different result now.

I assume that "Winamp v1.x" is not the name of the class. Ive searched and found the page you got all your info from :) and if you read it again, it mentions how to change the class name, if your desperate but ....

Version 1 and 2 use the string "Winamp v1.x" but V 3 uses "STUDIO" so try the following, it works on mine. (using integers)


WinAMPhWnd = FindWindow("STUDIO", vbNullString)
 
Okie!! Thanks a lot man! Progress is going. . . slowly. But all thanks to YOU! :D :D . . . however here comes the enevitable. . but :confused:.

Okay so I have the handle and Im using integers, and it looks all pretty cuz I keep getting the same handle. So thats nice. And well. . . thats the end of the good news. Eh, where did u find out that the new WinAmp window name is STUDIO? I dont think I saw that anywhere. Are the messages sent using different ids too? Cuz well. . .I still cant get WinAmp to respond to my Call SendMessage functions. Ill keep trying a bit and update this if I have any sucess. Thanks again! :D . Hope to hear some more :p.

Hmmm, further testing leads me to believe I have the right handle. But cant seem to do anything with it. All command messages I send do nuttin, and all queries give me goose egg.

OMG! IT DID SOMETHING! I still cant get it to do any commands but I got the window title!! Very exciting times. Hmm this is really what I want but. . . Im kinda curious so Id like to know how to get the rest of the stuff worked out. So I dunno if Im just still using out of date info or wat? Appreciate the help greatly! Shpank u.
 
Last edited by a moderator:
where did u find out that the new WinAmp window name is STUDIO

You can find out by starting your task-manager (ctrl+shift+esc), then start your winamp and you can see that winamp is studio.exe, therefore studio.

Another trick you can do is
WinAMPhWnd = FindWindow(vbNullString, "Winamp")

Dont know if it works for winamp since the string you type here, is the exact caption of the running program.
 
Cool thanks for that info. Is there any funky way to find out the ids and correspoding commands for the API?

Ive hit another snag, the WinAmp thing is working fine now. But Im having some issues with the MSN Messenger API (can u guess what Im trying to do?). Anyhow, theres a snippit of code that looks something like this:

Code:
hMsgrWnd = FindWindow("MSNHiddenWindowClass", vbNullString)
            hThread = GetWindowThreadProcessId(hMsgrWnd, 0)
            Call MSN.OptionsPages(0, MessengerAPI.__MIDL___MIDL_itf_msgrua_0000_0007.MOPT_GENERAL_PAGE)

            Do
                Call EnumThreadWindows(hThread, AddressOf EnumWindowsProc, 0)
            Loop While hOptionsWnd = 0

            Do
                hTabWnd = FindWindowEx(hOptionsWnd, 0, "#32770", vbNullString)
            Loop While hTabWnd = 0

            hEditWnd = FindWindowEx(hTabWnd, 0, "edit", vbNullString)
            hButtonWnd = FindWindowEx(hOptionsWnd, 0, "button", vbNullString)
            Call SendMessageByString(hEditWnd, WM_SETTEXT, 0, Value)
            Call SendMessageInteger(hButtonWnd, WM_KEYDOWN, VK_SPACE, 0)
            Call SendMessageInteger(hButtonWnd, WM_KEYUP, VK_SPACE, 0)

with

Code:
    Public Function EnumWindowsProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
        Dim sWndClass As String
        Dim lRet As Integer

        sWndClass = Space(255)
        lRet = GetClassName(hwnd, sWndClass, 255)
        sWndClass = Left(sWndClass, lRet)

        If sWndClass = "#32770" Then
            hOptionsWnd = hwnd
        Else
            EnumWindowsProc = True
        End If

    End Function

and the other stuff that I think is like standard win32 commands. (I didnt write any of this) but what ends up happening is it works the first 2 or 3 times I run it, but after that it gets caught in that second Do... While loop forever. Oh the code is basically supposed to open a properties page, change a value, and close it. Sorry for the longness of the code. Also if its not too much trouble could I get a brief explanation of the code? I have a vague idea of whats happening but if someone could really explain it I would really appreciate it. Thanks Again. :)

Oh, also. This is really strange. Ive put in like a counter thing so the loop terminates after like 20 times if its not ending (into the loop that is sometimes infinite) anyhow, this is really strange. When I put a MsgBox inside that loop that shows the value it works even after the first few runs. . .sometimes. I have no explination, I can run it like 15 times and nothing will happen than Ill put a message box in and itll work 75% of the time. Im not used to such randomness arghhhh. :mad:
 
Last edited by a moderator:
The EXE name is not necessarily the window class - you can find out by using Spy++ which is included with VS.NET and using the Find Window tool with the Winamp window.
 
I actually just searched on the net for winamp software development information and came up with a post about STUDIO. The calls your trying to do wont work, as I believe they have changed the way you access them, theres a kinda script thing available now.

PS: I know nothing about this, just what Ive learned while answering your question :).
 
Back
Top