Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Handle of External Program Window 1

Status
Not open for further replies.

webpager

Programmer
Mar 27, 2001
166
GB
Hi People
Can anyone tell me how to get the file handle from an external window. I am interfacing WINAMP from VFP6 but I am unable to get the file handle of its main window as there does not appear to be a relevant function within VFP. I am able to control WINAMP from Visual Basic but I need to interface it with an existing program, written in VFP.
Thanks
Keith
 
Oops, link was incorrect. THis is the correct one.

thread184-59381 Weedz (Wietze Veld)
veld4663@exact.nl
The Netherlands

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
webpager

Change the "WinAmp" references in the following code to whatever is correct for you.

SET LIBRARY TO foxtools.fll

* Register the Windows API functions that will be called

mGetWinTxt = RegFn("GetWindowText", "I@CI", "I")
mGetWindow = RegFn("GetWindow", "II", "I")
mIsWinVis = RegFn("IsWindowVisible", "I", "I")

* Get the HWND (handle) to the main FoxPro window

foxhwnd = MAINHWND()

* Produce a list of all windows

hwndNext = CallFn(mGetWindow,foxhwnd,0)
lWinAmp = .F.
DO WHILE hwndNext <> 0
[tab]IF (hwndnext <> foxhwnd) AND ;
[tab][tab]CallFn(mGetWindow,hwndnext,4) = 0
[tab][tab]Stuffer = SPACE(64)
[tab][tab]x = CallFn(mGetWinTxt,hwndnext,@Stuffer,64)
[tab][tab]IF [WINAMP] $ UPPER(Stuffer)
[tab][tab][tab]lWinAmp = .T.
[tab][tab][tab]EXIT
[tab][tab]ENDIF
[tab]ENDIF
[tab]hwndNext = CallFn(mGetWindow,hwndnext,2)
ENDDO

IF lWinAmp
[tab] && WinAmp is running
ENDIF

Chris :)

 
Hello.

Chris, don't be ofended, please, but it is a shorter way to do this task:

declare integer FindWindow in win32API string @ cClass, string @ cTitle
hwnd=FindWindow(0,&quot;The Window's Caption&quot;)

Thus, I've stored the window's handle in the hwnd variable.

Hope this helps. Grigore Dolghin
Class Software
Bucharest, Romania
 
Thanks for the info guys, first part of my conversion completed but still a long way to go.
I`ve never had to touch the API before but now seems a good time to start.
Can you suggest any books or sites for further API info?
 
Grigore,

Yes, your method utilizing the FindWindow function is shorter, but Chris's method is far more robust because he doesnt need to know the exact window title, as you do.

And most applications today use a dynamic titlebar. For instance, I doubt the titlebar on your web browser just says &quot;Microsoft Internet Explorer&quot; or &quot;Netscape&quot; or whatever your browser name is.

Using Chris's method, he could still get a handle to the window, while you couldnt with just FindWindow.
Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Hello, John.

It's the second time I have the feeling that I've upset you in some way. It it this so, then I'm really sorry.

Let me explain my reason to jump in:

Webpager wants to interface Winamp. So, the window don't have a dynamic caption. On the other hand, his first post was: &quot;Does anyone know the equivalent for FindWindow in VB&quot; and he gave the VB API call. He doesn't need a procedure to enumerate all the windows and keep the one he want. He need only that: the handle of Winamp window. And in this case the answer work like a charm.

But, if you think that I shouldn't interfere next time, just let me know.

Thank you. Grigore Dolghin
Class Software
Bucharest, Romania
 
It's the second time I have the feeling that I've upset you in some way. It it this so, then I'm really sorry.

I doubt that's the case. Part of the problem is that there are a lot of different levels of English familarity for the posters on this forum, and therefore it is hard to tell exactly when a writer is confused, and when it is just his words which are confused <g>. Add to that that many people like to give alternatives or enhancements to a question and you have a second level of possible misunderstanding. Finally, I think there's a cultural difference between US bluntness and European circumspection which can at time lead to apparent impoliteness or overesensitivity.

For you part, I don't think you need to worry a bit about hurting others feelings. Even if a particular person were to disagree over a certain post, others, who mostly read and learn (such as myself) find even the most vigorous debate on alternatives useful.

Dave Dardinger

 
Grigore

In making the post, I had 3 options

[tab]1. Refer to an example in another thread or FAQ, such as FAQ184-145

[tab]2. Post a specific answer using similar code to your post.

[tab]3. Post a generic version.

I chose the latter because it would give anyone following the thread, a robust solution which could be modified for other situations.

I found Jon's comments concerning your alternative to be both impersonal and accurate, and also felt he had made the post I would have done in response.

Having read and followed Jon's posts since the early days of Tek-Tips - I can assure you he is the ultimate professional and has never brought personalities into his immense contribution to the forum.

Being British, but having spent a considerable amount of time working with, and being in, the States, I can see the situation from both points of view.

Dave has made a good point about those differences, and whilst you may feel this is something personal, I would like to assure you that, IMHO, this is not the case.

Chris :)


 
Hello, All.

Thank you, guys. It was me. :)

Grigore Dolghin
Class Software
Bucharest, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top