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,102 4);
if(!strstr(buf,(char*)lPar am)) return true;
vw.push_back(hwnd);
return true;
}
int main()
{
EnumWindows(EnumWindowsPro c,(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?
#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,102
if(!strstr(buf,(char*)lPar
vw.push_back(hwnd);
return true;
}
int main()
{
EnumWindows(EnumWindowsPro
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,102 4);
if(!strstr(buf,(char*)lPar am)) return true;
vw.push_back(hwnd);
return true;
}
vector<HWND>& GetAllHWNDs(const char* pName)
{
EnumWindows(EnumWindowsPro c,(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;
}
#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,102
if(!strstr(buf,(char*)lPar
vw.push_back(hwnd);
return true;
}
vector<HWND>& GetAllHWNDs(const char* pName)
{
EnumWindows(EnumWindowsPro
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.
ASKER
yep, this is dealt with :D
ASKER
would you take look at my screenshot and keyboard problem?
Need to do a little wor also, but I will try to ;o)
ASKER
what is wor?
Sorry -> work
ASKER
function()
{
vector<HWND> array = GetAllHWNDs("Star Wars Galaxies");
Sleep ( 1000 );
for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
{
// *i = hwnd
}
}