获得应用程序标题时出错 [英] eror in get application title
本文介绍了获得应用程序标题时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
这是获取我的列表框中运行应用程序的标题(名称)的来源:
hi
this my source to get title(name) of runing applications in my listbox:
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private string GetActiveWindowTitle()
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
// listBoxControl1.Items.Add(Buff.ToString());
// Buff.Capacity.ToString();
Buff.MaxCapacity.ToString();
return Buff.ToString();
}
return null;
listBoxControl1.Items.Add(GetForegroundWindow.ToString());
但当KMPlayer运行我的列表时显示音频文件名
谢谢
but when KMPlayer is runing my list show audio file name
thanks
推荐答案
很抱歉没有回答你的问题:我认为你没有解释你的问题是什么。请看我对这个问题的评论。
首先,让我指出一个错误:调用ToString()<是没有意义的/ code>在最后一行的
GetForegroundWindow
,因为它返回IntPtr
。这行甚至不应该编译为GetForegroundWindow()
是一个函数(并且()
缺少括号)。我不认为这条线是你真实代码的一部分。
我想告诉你:你所有的问题实际上源于你是试图集成不是为此设计的应用程序(播放器),所以你必须选择脏Windows技巧。这是一个肮脏的生意,你总是松散。不幸的是,你没有分享你的目标,但我很确定它可以用一些合法的方式达成。例如,您可以获得一些可用的播放器组件(不是应用程序!),并在您的应用程序中使用其中一个。它可能是MicrosoftMediaPlayer
控件(对于WPF或System.Windows.Forms
),开源VLC,或者类似的东西。
-SA
Sorry for not answering your question: I think you did not explain what's your problem. Please see my comment to the question.
First of all, let me point out just one mistake: it's pointless to callToString()
onGetForegroundWindow
in your last line, as it returnsIntPtr
. This line should not even compile asGetForegroundWindow()
is a function (and "()
" brackets are missing). I don't think this line is a part of your real code.
I wanted to tell you this: all your problems are actually stem from the fact that you are trying to integrate the application (the player) which is not designed for this, so you have to opt for dirty Windows tricks. This is a dirty business where you always loose. Unfortunately, you did not share your goal, but I'm pretty sure that it could be reached with some legitimate ways. For example, you could get some available player components (not applications!) and use one of them in your application. It could be the MicrosoftMediaPlayer
control (for WPF orSystem.Windows.Forms
), open-source VLC, or something like that.
—SA
除了解决方案1:信息如果使用.NET中的VLC:
这是关于.NET的VLC组件绑定的更新有用信息:
http://sourceforge.net/projects/libvlcnet/ [ ^ ],
https:// wiki .videolan.org / C_Sharp / [ ^ ],
https://wiki.videolan.org/.Net_Interface_to_VLC/ [ ^ ]。
值得注意的是,您可以找到使用WPF和System.Windows.Forms
组件的材料。
-SA
In addition to Solution 1: information if the use of VLC in .NET:
This is the updated useful information on the VLC component binding for.NET:
http://sourceforge.net/projects/libvlcnet/[^],
https://wiki.videolan.org/C_Sharp/[^],
https://wiki.videolan.org/.Net_Interface_to_VLC/[^].
Notably, you can find material for using the component for both WPF andSystem.Windows.Forms
.
—SA
这篇关于获得应用程序标题时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文