Solved

Getting hWnd from titlebar

Posted on 1997-07-24
6
473 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

726 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