Link to home
Start Free TrialLog in
Avatar of Troudeloup
Troudeloup

asked on

rewriting into a function; specific code

#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

int main()
{
      EnumWindows(EnumWindowsProc,(LPARAM)"Star Wars Galaxies");

      Sleep ( 1000 );
      
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
            
            

      }

   return 0;
}





I want to rewrite this into one function so that it returns  hwnd array



can I do this to receive it?


hwnd array[5];

array = return_handle();

when I know that the array handle it returns has less than 5 elements?
SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Troudeloup
Troudeloup

ASKER

can i do this?


function()
{
      vector<HWND> array = GetAllHWNDs("Star Wars Galaxies");

      Sleep ( 1000 );
     
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
           
           

      }
}
actually there is a way to solve it,
Yes, that's well possible, e.g.

#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

vector<HWND>& GetAllHWNDs(const char* pName)
{
    EnumWindows(EnumWindowsProc,(LPARAM)pName);

    return vw;
}

void UseHWNDs(vector<HWND>& array)
{
      for (vector<HWND>::iterator i = array.begin(); i != array.end(); ++i)
      {
      // *i   = hwnd
           
           

      }
}

int main()
{
      vector<HWND> array = GetAllHWNDs("Star Wars Galaxies");

      UseHWNDs(array);

   return 0;
}
... it is just that 'EnumWindowsProc()' has to be kept as a separate function, since this one is called by the operating system, not your code.
yep, this is dealt with :D
would you take look at my screenshot and keyboard problem?
Need to do a little wor also, but I will try to ;o)
what is wor?
Sorry -> work