CODE:function Find_Window(win #w, string name, string class, int full_name, int full_class)
{
external(INT, "FindWindowEx", "FindWindowExA", "user32.dll");
external(VOID, "GetClassName", "GetClassNameA", "user32.dll");
external(VOID, "GetWindowText", "GetWindowTextA", "user32.dll");
char array[255];
int n=0, handle;
if(name == "" && class == "") // если не указаны имя и класс
{
return 0;
}
if(name != "" && class != "") // поиск по имени и классу
{
// имя окна и класс указаны полностью
if(full_name==1 && full_class==1)
{
handle=FindWindowEx(0, 0, class, name);
while (handle!=0)
{
w[n]=formatiw(handle); n++;
handle=FindWindowEx(0, handle, class, name);
}
return n;
}
// имя указано полностью, класс частично
if(full_name==1 && full_class==0)
{
handle = FindWindowEx(0, 0, 0, name);
GetClassName (handle, address (#array[0]), 255);
while (handle!=0)
{
if(find_str(format(#array[0]), class, full_class) == 1)
{
w[n]=formatiw(handle); n++;
}
handle=FindWindowEx(0, handle, 0, name);
GetClassName (handle, address (#array[0]), 255);
}
return n;
}
// имя указано частично, класс полностью
if(full_name==0 && full_class==1)
{
handle = FindWindowEx(0, 0, class, 0);
GetWindowText (handle, address (#array[0]), 255);
while (handle!=0)
{
if(find_str(format(#array[0]), name, full_name) == 1)
{
w[n]=formatiw(handle); n++;
}
handle=FindWindowEx(0, handle, class, 0);
GetWindowText (handle, address (#array[0]), 255);
}
return n;
}
// имя указано частично, класс частично
if(full_name==0 && full_class==0)
{
handle = FindWindowEx(0, 0, 0, 0);
GetClassName (handle, address (#array[0]), 255);
while (handle!=0)
{
if(find_str(format(#array[0]), class, full_class) == 1)
{
GetWindowText (handle, address (#array[0]), 255);
if(find_str(format(#array[0]), name, full_name) == 1)
{
w[n]=formatiw(handle); n++;
}
}
handle=FindWindowEx(0, handle, 0, 0);
GetClassName (handle, address (#array[0]), 255);
}
return n;
}
}
if(name=="") // поиск по классу, имя не указано
{
if(full_class==1)
{
handle = FindWindowEx(0, 0, class, 0);
while (handle!=0)
{
w[n]=formatiw(handle); n++;
handle=FindWindowEx(0, handle, class, 0);
}
}
else
{
handle = FindWindowEx(0, 0, 0, 0);
GetClassName (handle, address (#array[0]), 255);
while (handle!=0)
{
if(find_str(format(#array[0]), class, full_class) == 1)
{
w[n]=formatiw(handle); n++;
}
handle = FindWindowEx(0, handle, 0, 0);
GetClassName (handle, address (#array[0]), 255);
}
}
}
else // поиск по имени, класс не указан
{
if(full_name==1)
{
handle = FindWindowEx(0, 0, 0, name);
while (handle!=0)
{
w[n]=formatiw(handle); n++;
handle=FindWindowEx(0, handle, 0, name);
}
}
else
{
handle = FindWindowEx(0, 0, 0, 0);
GetWindowText (handle, address (#array[0]), 255);
while (handle!=0)
{
if(find_str(format(#array[0]), name, full_name) == 1)
{
w[n]=formatiw(handle); n++;
}
handle = FindWindowEx(0, handle, 0, 0);
GetWindowText (handle, address (#array[0]), 255);
}
}
}
return n;
function find_str(string s1, string s2, int full)
{
int i=0, j=0, len1=size(s1),len2=size(s2);
char tmp1[255], tmp2[255];
string temp="";
strcpy(#tmp1[0], s1); strcpy(#tmp2[0], s2);
while(i <= len1 - len2 && temp != s2)
{
temp="";
if(full==0){while(tmp1[i]!=tmp2[0] && i < len1 - len2)i++;}j=0;
while(tmp1[i]==tmp2[j] && i < len1){temp=temp+tmp1[i]; i++; j++;}i++;
}
if(temp == s2)return 1;
else return 0;
}
}