0

Hey,
I was trying to use the code from:
http://www.java2s.com/Tutorial/CSharp/0520__Windows/GetcurrentActiveWindow.htm
to get the topmost window handle; however, I need to click a notify icon, which will bring up a form.
I tried to use

private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
{
    if (this.Visible == false
        && e.Button == System.Windows.Forms.MouseButtons.None)
    {
        IntPtr x = GetForegroundWindow();
        if (x != this.Handle)
            handle = x;
        int chars = 256;
        StringBuilder buff = new StringBuilder(chars);
        if (GetWindowText(handle, buff, chars) > 0)
        {
            notifyIcon1.Text = buff.ToString();
        }
    }
}

This correctly displays the text etc. but when I click the notify icon, it changes.

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by bbman
0

Solved. I used the get title thing to check it actually had a title.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.