473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

GetActiveWindow handle

I'm having problems getting the caption on the active window handle. The
active window handle seems to always come back as zero and the caption
blank.

Private Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder,
ByVal nMaxCount As Integer) As Integer

Private Function ObtainWindowHandle(ByVal lpstrCaption As String) As Integer
' To store the handle to a window.
Dim hWnd As System.IntPtr

' To store the text of the title bar of the window.
Dim lpString As New System.Text.StringBuilder(255)

'Get The Active Window Handle
hWnd = GetActiveWindow()

'Get THe Caption on the Active Window Handle
GetWindowText(hWnd, lpString, lpString.Capacity)

'Test to see what we got
MsgBox(lpString.ToString)

End Function
Nov 21 '05 #1
2 12606
Okay I figured out the problem. I need to use GetForegroundWindow instead
of GetActiveWindow. Could someone explain what the exact difference between
these are?
"David A. Osborn" <do********@hotmail.com> wrote in message
news:Q_6Re.294048$_o.177978@attbi_s71...
I'm having problems getting the caption on the active window handle. The
active window handle seems to always come back as zero and the caption
blank.

Private Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder,
ByVal nMaxCount As Integer) As Integer

Private Function ObtainWindowHandle(ByVal lpstrCaption As String) As
Integer
' To store the handle to a window.
Dim hWnd As System.IntPtr

' To store the text of the title bar of the window.
Dim lpString As New System.Text.StringBuilder(255)

'Get The Active Window Handle
hWnd = GetActiveWindow()

'Get THe Caption on the Active Window Handle
GetWindowText(hWnd, lpString, lpString.Capacity)

'Test to see what we got
MsgBox(lpString.ToString)

End Function

Nov 21 '05 #2
From the Docs :
The GetActiveWindow function retrieves the window handle to the active
window attached to the calling thread's message queue.
------
GetActiveWindow works only for windows from the calling thread while
GetForegroundWindow works for any window.
-Atul, Sky Software http://www.ssware.com
Shell MegaPack For ActiveX & .Net - Windows Explorer Like Shell UI Controls


"David A. Osborn" <do********@hotmail.com> wrote in message
news:to7Re.294097$_o.288981@attbi_s71...
Okay I figured out the problem. I need to use GetForegroundWindow instead
of GetActiveWindow. Could someone explain what the exact difference
between these are?
"David A. Osborn" <do********@hotmail.com> wrote in message
news:Q_6Re.294048$_o.177978@attbi_s71...
I'm having problems getting the caption on the active window handle. The
active window handle seems to always come back as zero and the caption
blank.

Private Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
Private Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hWnd As System.IntPtr, ByVal lpString As
System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer

Private Function ObtainWindowHandle(ByVal lpstrCaption As String) As
Integer
' To store the handle to a window.
Dim hWnd As System.IntPtr

' To store the text of the title bar of the window.
Dim lpString As New System.Text.StringBuilder(255)

'Get The Active Window Handle
hWnd = GetActiveWindow()

'Get THe Caption on the Active Window Handle
GetWindowText(hWnd, lpString, lpString.Capacity)

'Test to see what we got
MsgBox(lpString.ToString)

End Function


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BadOmen | last post by:
I am using the GetActiveWindow() API but it returns 0 I have a remote that I activate this code with: Code: WinAmpHandler = GetActiveWindow WinAMPhWnd = FindWindow("Winamp v1.x",...
7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
2
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and just plain thinking about it. I am truly unable to...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
2
by: Larry Dodd | last post by:
I am trying to write an application that sits in the system tray and just monitors for a certain Window to be opened. Once this window is opened all keystrokes will be captured. I have the key...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.