C# 从C中的activex插件中获取信息#
我正在我的一个C#应用程序中使用Sopcast activex插件(sopocx.ocx)。 我想检索播放器状态(“缓冲频道”、“播放频道”、“频道脱机…”)和缓冲百分比。这两个信息都显示在播放器上(我试图发布一张图片,但我还没有足够的声誉) 问题是Sopcast activex插件没有提供任何方法来检索这些信息 有人知道怎么做吗 GetWindowText将导致一个空字符串C# 从C中的activex插件中获取信息#,c#,.net,streaming,activex,media-player,C#,.net,Streaming,Activex,Media Player,我正在我的一个C#应用程序中使用Sopcast activex插件(sopocx.ocx)。 我想检索播放器状态(“缓冲频道”、“播放频道”、“频道脱机…”)和缓冲百分比。这两个信息都显示在播放器上(我试图发布一张图片,但我还没有足够的声誉) 问题是Sopcast activex插件没有提供任何方法来检索这些信息 有人知道怎么做吗 GetWindowText将导致一个空字符串 using System; using System.Collections.Generic; using System
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
IntPtr hwnd = sopcast.Handle;
StringBuilder lpString = new StringBuilder(256);
GetWindowText(hwnd, lpString, 256);
MessageBox.Show(lpString.ToString());
}
private void playToolStripMenuItem_Click(object sender, EventArgs e)
{
sopcast.SetSopAddress("sop://broker.sopcast.com:3912/123456789");
sopcast.SetChannelName("Channel");
sopcast.Play();
}
}
}
您可以使用api窗口识别Id控件并获取文本这里有一个代码示例(用应用程序名替换记事本)。对于您来说,最重要的是从应用程序中获取ocx窗口的Id控件
using System;
使用System.Runtime.InteropServices
使用系统文本
使用系统安全
命名空间应用程序
{
}我下载了sopcast并尝试使用spy++获取状态: 如您所见,标题是状态而不是频道。。。 所以你不能让它变得更容易
您捕获的句柄用于整个控件Sopcast使用DrawText绘制状态文本(我是使用API监视器发现的)。因此,无法使用传统的GetWindowText函数或类似函数获取文本。我能够通过挂钩DrawText函数获得文本。NET EasyHook将使您能够做到这一点。 我的设想: 我有一个承载activex控件的winforms应用程序,我想获取状态文本
public class hooklocal : EasyHook.IEntryPoint
{
[DllImport("user32.dll")]
static extern int DrawText(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat);
[UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet = CharSet.Auto,SetLastError = true)]
delegate int DDrawText(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat);
int DrawTextH(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat)
{
//lpString contains the status text
return DrawText(hDC, lpString, nCount, lpRect, uFormat);
}
public hooklocal()
{
try
{
var CreateHook = LocalHook.Create(
LocalHook.GetProcAddress("user32.dll", "DrawTextW"),
new DDrawText(DrawTextH),
this);
CreateHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
Debugger.Break();
}
}
}
若要使用,请在程序启动时在新线程中实例化hooklocal类
易书下载
[DllImport(“user32.dll”,CharSet=CharSet.Auto,SetLastError=true)]静态外部int GetWindowText(IntPtr hWnd,StringBuilder lpString,int nMaxCount);谢谢你的回答。是的,我试过了。不幸的是,我得到了一个空字符串回来。还有什么想法吗?我也尝试过这个代码示例,但仍然得到一个空字符串[它与“Notepad”配合使用效果很好,但=p]我在原始问题中添加了一个代码示例。如果我做错了什么(特别是在获取activex控件句柄(“sopcast”)方面),你会看得更清楚。使用spy++(visual studio工具)的搜索工具,在桌面编辑上设置你要查找的区域(控件)的目标-刚刚看到你的评论:)再次感谢你花时间帮助一个C#新手!我不知道为什么,但对我来说,状态的标题总是空的(在Spy++)。Button类的标题是存在的,我可以通过编码很好地检索它们,但与您不同的是,状态的标题总是空的(请参见此处:)关于为什么会发生这种情况的任何想法??您做得对,我只有标题上的状态,所以它不是真正的值(频道处于脱机状态…)。问题是,它可能是一个自定义控件,没有可与API绑定的标题属性。它在windows 7下,64位,我有vs2010…哦。。。那么,到底有没有办法得到真正的价值呢?
public class hooklocal : EasyHook.IEntryPoint
{
[DllImport("user32.dll")]
static extern int DrawText(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat);
[UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet = CharSet.Auto,SetLastError = true)]
delegate int DDrawText(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat);
int DrawTextH(IntPtr hDC, string lpString, int nCount, IntPtr lpRect, uint uFormat)
{
//lpString contains the status text
return DrawText(hDC, lpString, nCount, lpRect, uFormat);
}
public hooklocal()
{
try
{
var CreateHook = LocalHook.Create(
LocalHook.GetProcAddress("user32.dll", "DrawTextW"),
new DDrawText(DrawTextH),
this);
CreateHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
Debugger.Break();
}
}
}