How can I translate this to vb.net?
I have tried a lot, and basicly I'm stuck at passing the txt variable to sendmessage, since this needs to be an intptr apparently.. -
Public Function WindowText(window_hwnd As Long) As String
-
Dim txtlen As Long
-
Dim txt As String
-
-
WindowText = ""
-
If window_hwnd = 0 Then Exit Function
-
-
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
-
If txtlen = 0 Then Exit Function
-
-
txtlen = txtlen + 1
-
txt = Space$(txtlen)
-
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
-
WindowText = Left$(txt, txtlen)
-
-
If WindowText = "MOHAA Console" Then
-
WindowText = ""
-
ElseIf WindowText = "copy" Then
-
WindowText = ""
-
ElseIf WindowText = "quit" Then
-
WindowText = ""
-
ElseIf WindowText = "clear" Then
-
WindowText = ""
-
End If
-
findstring$ = WindowText
-
FindText TargetPosition + 1
-
-
End Function
-
thanx
5 1505 Plater 7,872
Recognized Expert Expert
What exactly is that function doing? Maybe there is a completely different way of doing it?
It looks like it is just getting the title of a window from a window handle?
The function will get text in an other window's textbox using it's windowhandle and put it in a variable...
Public Function WindowText(window_hwnd As Long) As String
Dim txtlen As Long
Dim txt As String
WindowText = "" 'if the given window handle is zero, the function will exit.
If window_hwnd = 0 Then Exit Function 'the length of the text in the windowhandle will be gotten here
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0) 'If the textlength is zero, meaning there is no text, the function exits.
If txtlen = 0 Then Exit Function
txtlen = txtlen + 1 'This declares some kind of buffer for a string I believe...
'I'm not sure since I have never programmed in vb, only in .net
txt = Space$(txtlen) 'This line is what I'm unable to translate. It will get the text in the window
'(which is some kind of multiline textbox) and put it in the txtlen variable.
'Arguments passed to sendmessage: the handle, the command to get text,
'the textlength, and a reference (?) to the buffer. I do not know how to
'pass this last parameter to sendmessage in vb.net
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
'I'm not sure what this does...
WindowText = Left$(txt, txtlen) 'don't mind the rest of the function
If WindowText = "MOHAA Console" Then
WindowText = ""
ElseIf WindowText = "copy" Then
WindowText = ""
ElseIf WindowText = "quit" Then
WindowText = ""
ElseIf WindowText = "clear" Then
WindowText = ""
End If
findstring$ = WindowText
FindText TargetPosition + 1
End Function
Ok, I figured it out myself, Thanx anyway
Plater 7,872
Recognized Expert Expert
Did you use:
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByRef txt)
??
I would have passed the variable in by reference and then cast it as an IntPtr. (Note: I don't know if that works, but would be what I tried).
How did you solve it?
Did you use:
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByRef txt)
??
I would have passed the variable in by reference and then cast it as an IntPtr. (Note: I don't know if that works, but would be what I tried).
How did you solve it?
Dim txt As StringBuilder = New StringBuilder(length)
SendMessage(readbox, WM_GETTEXT, length, txt)
using a stringbuilder as buffer, it did the trick
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bengt Richter |
last post by:
Just thought None as the first argument would be both handy and mnemonic,
signifying no translation, but allowing easy expression of deleting characters,
e.g.,
s = s.translate(None,...
|
by: Zahid |
last post by:
Hi,
-- URGENT --
I have a short piece of C/C++ code that i need
translating into VB.Net. Any volunteers? Know of any
websites that do this? Greatly appreciated.
code:
typedef unsigned...
|
by: Dean Slindee |
last post by:
This chunk of code does not translate accurately using the available C# to
VB translator tools.
I am wondering what the "sub within a sub" structure should look like in VB:
starting with the...
|
by: Craig Buchanan |
last post by:
if i have a class that is declared
public abstract class Hashlist : IDictionary, IEnumerable
{
....}
how do i translate the following (method?) into vb?
IEnumerator...
|
by: Petar Popara |
last post by:
Please could someone translate this for me from C/C++ to VB.net?
#define MY_CONST 1
typedef struct _MYSTRUCT {
const char* p1;
int p2;
char p3;...
|
by: VBTricks.de.vu Webmaster |
last post by:
Hello,
in VB6 I used to translate my application by setting the tag-property of
all controls, menu-entries... to a number which has been linked to a
string (array). Then I went through all...
|
by: Carlos |
last post by:
Hi all,
ca anybody help me to translate to vb .net this c# instruction?
string fname = ((TextBox)GridView1.Rows.
Cells.Controls).Text;
Thanks,
Carlos
|
by: raz230 |
last post by:
I'm sorry for posting this here-
I have to integrate an parcel tracking with Canada Post into one of my
applications. The web service they use is made with SAP and is not
the usual WSDL type of...
|
by: kovariadam |
last post by:
Hi,
Does anybody know why i get this error:
SQL0176N The second, third or fourth argument of the TRANSLATE scalar
function is incorrect. SQLSTATE=42815
with this query:
SELECT...
|
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= |
last post by:
I've just been tasked to translate a C# project into VB (Dot Net 2.0). I am
somewhat familiar with C# but far from an expert.
I'd like a second opinion on this one.
The project uses CSLA...
|
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: 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...
|
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: 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...
|
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |