Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Okie, I'm new to programming with API's and don't have a lot of experience in VB and almost none in VB.NET that being said. . . help. Okie, so I'm basically crawling through other peoples code thats similar to what I'm trying to do and then trying it out myself. But everyone elses code is in VB 6.0 and I'm trying to work in .NET, which might be causing my problems, or it might be other stuff I don't really know about. Okay so I'm starting off pretty basic, and I THINK I'm working with an API, cuz like I said I'm 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 I've 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 I'm not sure if this is supposed to or not, but evertime I FindWindow with the same parameters I get a different value.

 

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

 

This is probably a really dumb question so I'd really appreciate like some quick answer, thanks.

  • *Experts*
Posted

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.

Posted (edited)

okie.

This is the code that gets me a handle.

 

Sitting in my module:

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

 

Sitting in some on_click function:

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:

 

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

 

with:

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 shouldn't need a reference just to get a window handle, but I'm new so what do I know. Thanks again.

Edited by Meowsers
Posted

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.

Posted

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)

Posted (edited)

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 I'm using integers, and it looks all pretty cuz I keep getting the same handle. So thats nice. And well. . . that's the end of the good news. Eh, where did u find out that the new WinAmp window name is STUDIO? I don't think I saw that anywhere. Are the messages sent using different id's too? Cuz well. . .I still can't get WinAmp to respond to my Call SendMessage functions. I'll 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 can't 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 can't get it to do any commands but I got the window title!! Very exciting times. Hmm this is really what I want but. . . I'm kinda curious so I'd like to know how to get the rest of the stuff worked out. So I dunno if I'm just still using out of date info or wat? Appreciate the help greatly! Shpank u.

Edited by Meowsers
Posted

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")

 

Don't know if it works for winamp since the string you type here, is the exact caption of the running program.

Posted (edited)

Cool thanks for that info. Is there any funky way to find out the id's and correspoding commands for the API?

 

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

 

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

 

   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 didn't 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. I've 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 I'll put a message box in and it'll work 75% of the time. I'm not used to such randomness arghhhh. :mad:

Edited by Meowsers
  • *Experts*
Posted
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.
Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...