帮忙把和这个VB的转化成C# 的 谢谢啦
我自己对VB一窍不通。可老实偏偏给了个VB写的函数..完全看不懂 请各位帮帮忙 改一下 谢啦Public Function EditInfo(window_hwnd As Long) As String
Dim txt As String
Dim buf As String
Dim buflen As Long
Dim child_hwnd As Long
Dim children() As Long
Dim num_children As Integer
Dim i As Integer
' Get the class name.
buflen = 256
buf = Space$(buflen - 1)
buflen = GetClassName(window_hwnd, buf, buflen)
buf = left$(buf, buflen)
' See if we found an Edit object.
If right(buf, 4) = "Edit" Then
EditInfo = WindowText(window_hwnd)
Exit Function
End If
' It's not an Edit object. Search the children.
' Make a list of the child windows.
num_children = 0
child_hwnd = GetWindow(window_hwnd, GW_CHILD)
Do While child_hwnd <> 0
num_children = num_children + 1
ReDim Preserve children(1 To num_children)
children(num_children) = child_hwnd
child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
Loop
' Get information on the child windows.
For i = 1 To num_children
txt = EditInfo(children(i))
If txt <> "" Then Exit For
Next i
EditInfo = txt
End Function
把string改成char数组长度256 C#中有可变数组吧 做一个类型为句柄的可变数组 --------------------编程问答-------------------- http://www.vbconversions.com/
你找个工具转换下就行了,看到vb头痛 --------------------编程问答-------------------- 还是不行呢。。那工具不给力啊! --------------------编程问答-------------------- 使用了一些 API 函数。需要先声明。 --------------------编程问答--------------------
- - 我知道 GETCLASSNAME 等...我只是说翻译一下 ~~API 之类的声明我自己慢慢查去..
问题是都没人帮忙翻译..说api的话 有点早了.. --------------------编程问答-------------------- 你直接查 GetClassName, GetWindow C#代码不就得了?
http://www.pinvoke.net
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);
StringBuilder className = new StringBuilder(100);
//Get the window class name
int ret = GetClassName(hWnd, className, className.Capacity);
--------------------编程问答-------------------- 你的VB代码作用是给一个窗体句柄,返回第一个不为空 Edit 输入框的内容。 --------------------编程问答--------------------
里面有些东西找不到 比如WINDOWTEXT 啊 TO SAPCE估计是老师自己定义的吧...哎
--------------------编程问答--------------------
老师说是 传入一个窗口句柄,然后一个路径~~可是我不会翻译成C#的 --------------------编程问答-------------------- WindowText 应该是 GetWindowText Api 。。。Space 用 StringBuilder 代替掉了。
GetWindow -- 获得所有子句柄
GetClassName -- 获得ClassName,用string.EndWith("Edit") (代替Left)
GetWindowText -- 获得里面的内容,如果为空,递归继续找,不会空则返回
你现在不用看那段vb代码,也应该知道怎么写这个方法了吧。 --------------------编程问答--------------------
我自己水平也不高...也是毕业设计闹的`` 最后我弄成这样 可是还是有很多错 有些地方不太会改..
兄弟帮个忙吧! 比如space.
const int GW_HWNDNEXT = 2;
const int WM_GETTEXTLENGTH = 14;
const int WM_GETTEXT = 13;
const int GW_CHILD = 5 ;
const int GW_HWNDFIRST = 0;
public string WindowText(long window_hwnd)
{
long txtlen;
StringBuilder txt;
string astr;
return "";
if ((window_hwnd == 0))
{
}
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0);
if ((txtlen == 0))
{
// TODO: Exit Function: Warning!!! Need to return the value
}
// return;
txtlen = (txtlen + 1);
txt = Space(txtlen);
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, txt);
return txt.Substring(0, txtlen);
}
public string EditInfo(long window_hwnd)
{
StringBuilder txt;
StringBuilder buf;
long buflen;
long child_hwnd;
long[] children;
int num_children;
int i;
// Get the class name.
buflen = 256;
buf = Space((buflen - 1));
buflen = GetClassName(window_hwnd, buf, buflen);
buf = buf.Substring(0, buflen);
// See if we found an Edit object.
if ((buf.Substring((buf.Length - 4)) == "Edit"))
{
return WindowText(window_hwnd);
}
// It's not an Edit object. Search the children.
// Make a list of the child windows.
num_children = 0;
child_hwnd = GetWindow(window_hwnd, GW_CHILD);
while ((child_hwnd != 0))
{
num_children = (num_children + 1);
object Preserve;
children[1, To, num_children];
children[num_children] = child_hwnd;
child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT);
}
// Get information on the child windows.
for (i = 1; (i <= num_children); i++)
{
txt = EditInfo(children[i]);
if ((txt[0] != ""))
{
break;
}
}
return txt;
}
--------------------编程问答--------------------
这网站好,red-gate旗下的?学习。 --------------------编程问答-------------------- 嗯。求帮助啊...
补充:.NET技术 , C#