Solved

Getting hWnd from titlebar

Posted on 1997-07-24
6
451 Views
Last Modified: 2012-05-04
If I know the title of a program ie. "MS-WORD", is it possible to get the hWnd (window handle) of that application (form[s])?
0
Comment
Question by:PersonX070197
6 Comments
 
LVL 3

Expert Comment

by:ESI
ID: 1428826
Yes its possible to retrieve the hWnd just by the caption (or a part of the caption) displayed in the main form.
Is it what u need before I dig in my API docs ?
0
 
LVL 2

Expert Comment

by:vorlon
ID: 1428827
PersonX,
Yes. In order to get the hWnd of the application knowing only it's titlebar, you have to use the FindWindow API function.

Here is some information of that function:
Declare Function FindWindow& Lib "user32" alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName as string)

Description:
Finds the first top level window in the window list that meets the specified conditions.

Return Value:
Long - Handle of the window found. Zero if no window was found. Sets GetLastError

Use in VB:
No problem. One common use of FindWindow is to obtain the handle of the hidden window of class ThunderRTMain that is part of every running Visual Basic executable. You can then use the GetWindowText API to retrieve the window name of this window which is also the appliation title.

Parameters:
lpClassName - String: Pointer to null terminated (C Language) string containing the name of the class of the window, or zero to  accept any class.

lpWindowName - String: Pointer to null terminated (C Language) string containing the window text (or title), or zero to accept any window title.

Hope this helps.
0
 
LVL 3

Expert Comment

by:ESI
ID: 1428828
What is this ThunderRTMain hidden window ? What's the use to get a handle on it ? I've seen too there is a "CONJURE.MAK" hidden window when VB5 is running.
Any infos welcomed !
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Expert Comment

by:vorlon
ID: 1428829
I have no idea what the CONJURE.MAK hidden window or the ThunderRTMain class do. I simply copied the description of the function from my reference. I've used this function before manny times and it does what it's support to do.

Have you ever noticed that sometimes you can't run multiple VB applications simultaneously? Well maybe these windows/class names have something to do with that.

Just my $0.02.
vorlon
0
 

Author Comment

by:PersonX070197
ID: 1428830
I'm sure that the API you gave me works, but it doesn't seem to work for me... You see, let's say I want to terminate "Notepad" I  would first declare the API (Findwindow and Destroywindow), Find the titlebar of notepad, possibly "Untitled - Notepad" then my code:
x=FindWindow& (0,"Untitled - Notepad"")
x=DestroyWindow (x)
....It should work according to the code you pasted above,  (If I replace the values with all 0's it should work for sure right?
[FindWindow& (0,0) - should return ANY window, well it doesnt)
So am I messing something up here or is it mess'd or what?
0
 
LVL 3

Accepted Solution

by:
wolfcrag earned 100 total points
ID: 1428831
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Is this the declaration you used? If not, try it out. If it is,  try String instead of Any in both parameters, and then use the following code:

hwndWin = FindWindow(vbNullString, "Untitled - Notepad")
Throw = DestroyWindow(hwndWin)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now