Get Current Screen Name?

Can Any one please tell how to get the Current Active Screen Name in C#.

Hope you can help

Thanks


Answer this question

Get Current Screen Name?

  • Kelly R. Martin

    Can Any one please tell how to get the Current Active Screen Name in C#

    Hope you can help

    Thanks

  • donbox5

    Can Any one please tell how to get the Current Active Screen Name in C#.

    Hope you can help

    Thanks

  • Johnny Ashcan

    I am still not sure I understand why you need that but anyway... There're a few simple API's that you can call: GetForegroundWindow should return you a window handle of the currently active window:

    [DllImport("coredll.dll")]
    static extern IntPtr GetForegroundWindow();

    and GetWindowText that will get you the window caption:

    [DllImport("coredll.dll", SetLastError=true)]
    static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

    [DllImport("coredll.dll", SetLastError=true)]
    static extern int GetWindowTextLength(IntPtr hWnd);

    public string GetText(IntPtr hWnd)
    {
    // Allocate correct string length first
    int length = GetWindowTextLength(hWnd);
    StringBuilder sb = new StringBuilder(length + 1);
    GetWindowText(hWnd, sb, sb.Capacity);
    return sb.ToString();
    }


  • Ice_

    Oh, so you just wanted an active window caption... I wonder how it would help you out
    Why don't you just put out a notification using Microsoft.WindowsCE.Forms.Notification class



  • WXS123

    Please do not cross post. Merging...

    You should be more specific. What exactly do you mean by the "current active screen"



  • Jagdeep Sihota

    Thank You very much Alex. I could work it out with this. Keep support me. Thank You n Bye

  • cmcharly

    in C:

    #include <winuser.h>
    char caption[1024];
    HWND win;
    int length;

    win = GetForegroundWindow(); // hwnd
    length = GetWindowTextLength(win); // strlen of the caption
    GetWindowText(win, caption, length+1);
    caption[length+1] = '\0'; // set end of the string






  • Pretpal

    Hi Ilya Tumanov,

    Say, I have opened another application like Internet explorer or Today screen. Then I want to get that that screen name.
    In my project I have to put a notification ballon when message arrives. It has to be happened when I am not in my application and operating other than my application. I am able to retrieve active Form name but only with in my application. Even though I am with another application like Today screen or with another, I am getting Form name which is belongs to my application.

    Can you please tell me is there any method to retrieve the current screen name.
    like GetUIApplication and GetActive Screen from UIObject class in Java.

  • Get Current Screen Name?