C#转VB.NET的一些问题 25
publicclassWindowsEnum{privatedelegateboolWNDENUMPROC(IntPtrhWnd,intlParam);[DllImpor...
public class WindowsEnum
{
private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);
[DllImport("user32.dll")]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);
[DllImport("user32.dll")]
private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
public struct WindowInfo
{
public IntPtr hWnd;
public string szWindowName;
public string szClassName;
}
public WindowInfo[] GetAllDesktopWindows()
{
List<WindowInfo> wndList = new List<WindowInfo>();
EnumWindows(delegate(IntPtr hWnd, int lParam)
{
WindowInfo wnd = new WindowInfo();
StringBuilder sb = new StringBuilder(256);
wnd.hWnd = hWnd;
GetWindowTextW(hWnd, sb, sb.Capacity);
wnd.szWindowName = sb.ToString();
GetClassNameW(hWnd, sb, sb.Capacity);
wnd.szClassName = sb.ToString();
wndList.Add(wnd);
return true;
}, 0);
return wndList.ToArray();
}
}
C#的这段代码如何转换到VB.net 并将其可用啊? 我现在用网站转换到VB.NET 无法使用 大神帮忙转换一下啊 谢谢! 展开
{
private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);
[DllImport("user32.dll")]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);
[DllImport("user32.dll")]
private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
public struct WindowInfo
{
public IntPtr hWnd;
public string szWindowName;
public string szClassName;
}
public WindowInfo[] GetAllDesktopWindows()
{
List<WindowInfo> wndList = new List<WindowInfo>();
EnumWindows(delegate(IntPtr hWnd, int lParam)
{
WindowInfo wnd = new WindowInfo();
StringBuilder sb = new StringBuilder(256);
wnd.hWnd = hWnd;
GetWindowTextW(hWnd, sb, sb.Capacity);
wnd.szWindowName = sb.ToString();
GetClassNameW(hWnd, sb, sb.Capacity);
wnd.szClassName = sb.ToString();
wndList.Add(wnd);
return true;
}, 0);
return wndList.ToArray();
}
}
C#的这段代码如何转换到VB.net 并将其可用啊? 我现在用网站转换到VB.NET 无法使用 大神帮忙转换一下啊 谢谢! 展开
2个回答
展开全部
public class WindowsEnum
private delegate function WNDENUMPROC(hwnd as IntPtr, lParam as int32) as boolean
[DllImport("user32.dll")] private shared function EnumWindows( lpEnumFunc as WNDENUMPROC , lParam as int32) as boolean
end function
[DllImport("user32.dll")] private shared function GetWindowTextW(hWnd as IntPtr , lpString as stringbuilder,nMaxCount as int32) as int32
end function
[DllImport("user32.dll")] private shared function GetClassNameW(hWnd as IntPtr , lpString as StringBuilder,nMaxCount as int32 ) as int32
end function
public structure WindowInfo
public hWnd as IntPtr
public szWindowName as string
public szClassNamestring
end structure
public function GetAllDesktopWindows() as WindowInfo()
Dim wndList as new List<of windowinfo>()
EnumWindows(Function(hWnd as IntPtr,lParam as int32)
Dim wnd as new WindowInfo()
Dim sb as new StringBuilder(256)
wnd.hWnd = hWnd
GetWindowTextW(hWnd, sb, sb.Capacity)
wnd.szWindowName = sb.ToString()
GetClassNameW(hWnd, sb, sb.Capacity)
wnd.szClassName = sb.ToString()
wndList.Add(wnd)
return true
End Function,0)
return wndList.ToArray()
end function
end class
private delegate function WNDENUMPROC(hwnd as IntPtr, lParam as int32) as boolean
[DllImport("user32.dll")] private shared function EnumWindows( lpEnumFunc as WNDENUMPROC , lParam as int32) as boolean
end function
[DllImport("user32.dll")] private shared function GetWindowTextW(hWnd as IntPtr , lpString as stringbuilder,nMaxCount as int32) as int32
end function
[DllImport("user32.dll")] private shared function GetClassNameW(hWnd as IntPtr , lpString as StringBuilder,nMaxCount as int32 ) as int32
end function
public structure WindowInfo
public hWnd as IntPtr
public szWindowName as string
public szClassNamestring
end structure
public function GetAllDesktopWindows() as WindowInfo()
Dim wndList as new List<of windowinfo>()
EnumWindows(Function(hWnd as IntPtr,lParam as int32)
Dim wnd as new WindowInfo()
Dim sb as new StringBuilder(256)
wnd.hWnd = hWnd
GetWindowTextW(hWnd, sb, sb.Capacity)
wnd.szWindowName = sb.ToString()
GetClassNameW(hWnd, sb, sb.Capacity)
wnd.szClassName = sb.ToString()
wndList.Add(wnd)
return true
End Function,0)
return wndList.ToArray()
end function
end class
更多追问追答
追问
你这个是不可用的!
追答
可能哪里打错了,截个图把
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询