Click here to Skip to main content
16,005,236 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
this my source to get title(name) of runing applications in my listbox:
C#
[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());

but when KMPlayer is runing my list show audio file name

thanks
Posted
Comments
Sergey Alexandrovich Kryukov 5-Sep-13 22:01pm    
What did you expect? Why is it wrong? What's the purpose of getting the title?
—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 call ToString() on GetForegroundWindow in your last line, as it returns IntPtr. This line should not even compile as GetForegroundWindow() 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 Microsoft MediaPlayer control (for WPF or System.Windows.Forms), open-source VLC, or something like that.

—SA
 
Share this answer
 
Comments
Ron Beyer 5-Sep-13 22:17pm    
+5'd, but the () are not required. This is why I hate VB, this:

Sub Main()
Dim x As Integer = 10

Console.WriteLine(x.ToString)

Console.ReadLine()

End Sub

Is perfectly legal code, runs, compiles, and makes my brain explode.

EDIT: My mistake, it actually is C#
Sergey Alexandrovich Kryukov 5-Sep-13 22:21pm    
Thank you, Ron.
—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 and System.Windows.Forms.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900