winforms - C# compare window title -


how can compare if active application/window title equal something? example, want winforms application execute functions when application in focus.

i tried using getforegroundwindow() it's not working.

[dllimport("user32.dll")] private static extern intptr getforegroundwindow();  public form1()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         timer1.start();     }      private void timer1_tick(object sender, eventargs e)     {         if (getforegroundwindow().tostring() == "test123")         {             messagebox.show("right");         }         else             messagebox.show("wrong");     } 

so timer going check if current window title called "test123" (note: not process name, window title text), , tell me if it's right or wrong.

getforegroundwindow() returns intptr. window handle (hwnd) other calls information.

in case, window text need use getwindowtext. implement , pass in newly acquired intptr (hwnd).


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -