Hi, im trying to get the caption text from the active window but i cant get it working in vb.net. Can somebody please help me. Im new to using API
Public Class Form
Inherits System.Windows.Forms.For
#Region " Windows Form Designer generated code
' Return Caption.ToString(
Public Declare Function GetActiveWindow Lib "user32" () As System.IntPt
Public Declare Auto Function GetWindowText Lib "user32"
(ByVal hWnd As System.IntPtr,
ByVal lpString As System.Text.StringBuilder,
ByVal cch As Integer) As Intege
' Create a buffer of 256 character
Dim Caption As New System.Text.StringBuilder(256
Dim hWnd As IntPtr = GetActiveWindow(
Dim t As Strin
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
Dim t As Strin
t = GetWindowText(hWnd, Caption, Caption.Capacity) 'put the caption text in strin
End Su
End Class 10 1295
"sneffe" <an*******@discussions.microsoft.com> schrieb Hi, im trying to get the caption text from the active window but i cant
get it working in vb.net. Can somebody please help me. Im new to using API. [...] Dim t As String
t = GetWindowText(hWnd, Caption, Caption.Capacity) 'put the caption text in string
What's the exact problem? Can't the code be compiled (congrats, then you
correctly enabled option strict) or do you get a runtime error? Do you need
a description of the API functions? The MSDN library contains them: Put the
cursor on the function and press <F1>.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"sneffe" <an*******@discussions.microsoft.com> schrieb Hi, im trying to get the caption text from the active window but i cant
get it working in vb.net. Can somebody please help me. Im new to using API. [...] Dim t As String
t = GetWindowText(hWnd, Caption, Caption.Capacity) 'put the caption text in string
What's the exact problem? Can't the code be compiled (congrats, then you
correctly enabled option strict) or do you get a runtime error? Do you need
a description of the API functions? The MSDN library contains them: Put the
cursor on the function and press <F1>.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
My problem is that the var t is not assigned any value.
My problem is that the var t is not assigned any value.
Your GetActiveWindow() isn't initialized to any value. And also,
GetWindowText doesn't return a string. It returns a Integer. Use your
stringbuilder variable to get the Caption of the window.
Put this your button click event
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = GetActiveWindow()
GetWindowText(hWnd, Caption, Caption.Capacity)
Debug.WriteLine(Caption)
End Sub
sneffe wrote: My problem is that the var t is not assigned any value.
Your GetActiveWindow() isn't initialized to any value. And also,
GetWindowText doesn't return a string. It returns a Integer. Use your
stringbuilder variable to get the Caption of the window.
Put this your button click event
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = GetActiveWindow()
GetWindowText(hWnd, Caption, Caption.Capacity)
Debug.WriteLine(Caption)
End Sub
sneffe wrote: My problem is that the var t is not assigned any value.
Please use the MSDN to correct your GetWindowText declaration and use
Namely what does it return and the meaning of each parameter
sneffe wrote: Hi, im trying to get the caption text from the active window but i cant get it working in vb.net. Can somebody please help me. Im new to using API.
Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
' Return Caption.ToString() Public Declare Function GetActiveWindow Lib "user32" () As System.IntPtr Public Declare Auto Function GetWindowText Lib "user32" _ (ByVal hWnd As System.IntPtr, _ ByVal lpString As System.Text.StringBuilder, _ ByVal cch As Integer) As Integer
' Create a buffer of 256 characters Dim Caption As New System.Text.StringBuilder(256) Dim hWnd As IntPtr = GetActiveWindow() Dim t As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As String
t = GetWindowText(hWnd, Caption, Caption.Capacity) 'put the caption text in string End Sub End Class
Please use the MSDN to correct your GetWindowText declaration and use
Namely what does it return and the meaning of each parameter
sneffe wrote: Hi, im trying to get the caption text from the active window but i cant get it working in vb.net. Can somebody please help me. Im new to using API.
Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
' Return Caption.ToString() Public Declare Function GetActiveWindow Lib "user32" () As System.IntPtr Public Declare Auto Function GetWindowText Lib "user32" _ (ByVal hWnd As System.IntPtr, _ ByVal lpString As System.Text.StringBuilder, _ ByVal cch As Integer) As Integer
' Create a buffer of 256 characters Dim Caption As New System.Text.StringBuilder(256) Dim hWnd As IntPtr = GetActiveWindow() Dim t As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As String
t = GetWindowText(hWnd, Caption, Caption.Capacity) 'put the caption text in string End Sub End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fabian Müller |
last post by:
Hi all,
my question is as follows:
If have a class X and a class Y derived from X.
Constructor of X is X(param1, param2) .
Constructor of Y is Y(param1, ..., param4) .
|
by: hasho |
last post by:
Why is "call by address" faster than "call by value"?
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: Amaryllis |
last post by:
I'm trying to call a CL which is located on our AS400 from a Windows
application. I've tried to code it in different ways, but I seem to
get the same error every time. Does anyone have any clue...
|
by: mitchellpal |
last post by:
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?
|
by: shsingh |
last post by:
I have a class A containing some map as data variables. I creat an
object of class A on heap by allocatiing memory by using "malloc". This
will return me the required memory but the object is not...
|
by: cberthu |
last post by:
Hi all,
Is it possible to have two connects in the same rexx script to
different DB's?
I have to get data form on DB (with specifics selects and filter out
some values with RExx) and save the...
|
by: CryptiqueGuy |
last post by:
Consider the variadic function with the following prototype:
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this...
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |