Who knows FindWindow function please HELP ME

I have a problem with FindWindow , my program works but I have multiple windows with the same name .

How can I transform my program to work with multiple windows (same name) , to hide them all ???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define _WIN32_WINNT 0x0500

#include <iostream>
#include <windows.h>

using namespace std;

void show();
void hide();


int main()
{
    int optiune;
    
    SetConsoleTitle("Ascunde redirecte");

    do
    {
     cin>>optiune;
     switch(optiune)
     {
      case 1:
           show();
           break;
      case 2:
           hide();
           hide();
           break;
     }
    }while(optiune!=0);
    
    show();
    
    return 0;
}

void show()
{
    HWND hWnd = FindWindow(0,"Console");
    
    if(hWnd!=0)
    {
               ShowWindow(hWnd,SW_SHOW);      
    }
}

void hide()
{
    HWND hWnd = FindWindow(NULL,"Console"); 
    
    if(hWnd!=0)
    {  
              ShowWindow(hWnd,SW_HIDE);           
    }
} 

Its time for Plan B Bubi. It can't be done. You are either going to have to change the Window Class Name or the Window Title.

On the other hand, perhaps it could be accomplished through one of the EnumWindow Functions. Every Window has a different HWND. That would have to be the basis of any attempted solution.
It is about the HALF LIFE DEDICATED SERVER.

HLDS (counter strike server) is called Console.

I have found a executable that I can use to hide all the servers that are open. I am sure that it can be done ... maybe not with FindWindow , but I`m sure 100% that somehow it can be done ... anyone know how ?
anyone ?
1.locate windows by process ID not by title name
2. easiest - start your servers by your application with create process. Then you have control over all servers )showing, hiding, closing, sending messages, etc)
Same think ... when I do this it returns only the first Console program ID

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{    
    HWND WindowHandel = FindWindow(0, "Console");
    
    DWORD proccesID = 0;
    GetWindowThreadProcessId(WindowHandel, &proccesID);

    cout <<proccesID<<endl;
    system("pause");
}



// 5156

and If I close one Console window

// 5960 (that is the second opened Console window)

How can I find all the ID`s for all the servers opened ? :) . I hate win32 programming ... :)
when I do this it returns only the first Console program ID


that's what it does - "Retrieves a handle to the top-level window whose class name and window name match the specified strings."

----
Start all your servers with CreateProcess (there are examples how to run application using this function) and store handles in array. Then manipulate them.
this is not the solution , trust me .. I have an executable made by someone and it works without changing the Start of the servers ... It works without that guy to know nothing about no CreateProcess.

I know that there is a solution to retreive all the ID , HWND , what ever of all the Console aplications with the same name and then HIDE them ...

Anyone knows how ???
I think you can use FindWindowEx function and loop through the first handle you get as childafter.

http://msdn.microsoft.com/en-gb/library/windows/desktop/ms633500(v=vs.85).aspx
I have made it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <windows.h>

using namespace std;

BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM lParam)
{
     DWORD dwThreadId, dwProcessId;
     HINSTANCE hInstance;
     char window_name[255];
     HANDLE hProcess;
     
     if(!hWnd)
     {
      return true; // nu e window
     }
     //if(!::IsWindowVisible(hWnd))
     //{
      //return true; // nu e vizibila fereastra
     //}
     if(!SendMessage(hWnd,WM_GETTEXT,sizeof(window_name),(LPARAM)window_name))
     {
      return true; // nu are titlu fereastra
     }
     
     hInstance = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
     dwThreadId = GetWindowThreadProcessId(hWnd,&dwProcessId);
     hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessId);
     
     if(strcmp(window_name,"Console")==0)
     {
      cout<<hWnd<<" "<<dwProcessId<<"\t"<<window_name<<"\t"<<endl;
      ShowWindow(hWnd,SW_HIDE); 
     }
      
     CloseHandle(hProcess);
     return true;
}

int main()
{
    EnumWindows(EnumWindowsProc,NULL);
    system("pause");
    return 0;
}


You can close this topic , 10x
Topic archived. No new replies allowed.