I read the question more carefully. Then so:
while (true) { IntPtr ptr = WinAPI.FindWindow(null, "VKMusic4"); if (ptr == IntPtr.Zero) { Console.WriteLine("окно не найдено"); Thread.Sleep(1000); } else { Console.WriteLine("окно найдено"); do Thread.Sleep(1000); while (WinAPI.FindWindow(null, "VKMusic4") == ptr); } }
or so:
IntPtr ptr, old = IntPtr.Zero while (true) { ptr = WinAPI.FindWindow(null, "VKMusic4"); if (ptr == IntPtr.Zero) { Console.WriteLine("окно не найдено"); } else if (ptr == old) { Console.WriteLine("окно уже обработано"); } else { Console.WriteLine("окно найдено"); old = ptr; } Thread.Sleep(1000); }
Rearrange the lines according to the numbers (X - delete). Line 3 is divided into 0 and 3 - in 0 declaration of the variable, in 3 - assignment.
3 IntPtr ptr = WinAPI.FindWindow(null, "VKMusic4"); 1 while (ptr == IntPtr.Zero) 2 { 4 if (ptr == IntPtr.Zero) // скорее всего это лишнее) X { 5 Console.WriteLine("окно не найдено"); X // Если окно не нашли то возвращаемся к поиску. X } X else X { 7 Если нашли то делаем что либо: 8 Console.WriteLine("окно найдено"); X } 5 Console.Read(); 6 }
It should turn out like this:
IntPtr ptr; while ((ptr = WinAPI.FindWindow(null, "VKMusic4")) == IntPtr.Zero) { Console.WriteLine("окно не найдено"); Console.Read(); } Console.WriteLine("окно найдено");
IsWindow(ptr)msdn.microsoft.com/ru-ru/library/windows/desktop/ ... As soon as the window is gone - it will return false - nick_n_aptrchange in your cycle? - VladD