public delegate bool WNDENUMPROC ( IntPtr hwnd, int lParam);
[ DllImport ( "user32.dll" )]
public static extern int EnumWindows( WNDENUMPROC lpEnumFunc, int lParam);
public static bool EnumFunc( IntPtr hwnd, int lParam)
{
Console . WriteLine( "Window handle is " + hwnd);
return true ;
}
private void button1_Click( object sender , EventArgs e)
{
EnumWindows(EnumFunc, 0 );
}
//--------------------------
using System . Runtime . InteropServices;
public delegate bool EnumWindowsProc ( IntPtr hWnd, IntPtr lParam);
[ DllImport ( "user32.dll" )]
public static extern int EnumWindows( EnumWindowsProc lpEnumFunc, IntPtr lParam);
[ DllImport ( "user32.dll" )]
public static extern int GetWindowText( IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public static bool WindowsProc( IntPtr hWnd, IntPtr lParam)
{
StringBuilder vBuffer = new StringBuilder ( 256 );
GetWindowText(hWnd, vBuffer, vBuffer . Capacity);
string S = vBuffer . ToString();
int I = S . IndexOf( "_QQMusic_SmallClient" );
if (I > 0 )
{
S = S . Remove(I);
Console . WriteLine(S);
return false ;
}
return true ;
}