Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting hWnd from titlebar

Posted on 1997-07-24
6
Medium Priority
?
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 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