Link to home
Start Free TrialLog in
Avatar of Troudeloup
Troudeloup

asked on

FindWindow(NULL,"notepad");

i know i said that i solved the problem, because I used a 3rd party software to look them up,


however

how do I find the handles of windows with the same title?


i other words, i have multiple notepads open
Avatar of jkr
jkr
Flag of Germany image

You could use 'EnumWindows()', e.g.

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

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

      cout << buf << endl;

      return true;
}

int main()
{
   EnumWindows(EnumWindowsProc,NULL);

   return 0;
}
Avatar of Troudeloup
Troudeloup

ASKER

what does it do?


I need n handles returned for n number of windows of that name.
Or

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

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

      cout << buf << " HWND: " << hwnd << endl;

      return true;
}

int main()
{
   EnumWindows(EnumWindowsProc,NULL);

   return 0;
}

Alternatively, to filter for Notepad:

Or

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

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

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

      cout << buf << " HWND: " << hwnd << endl;

      return true;
}

int main()
{
   EnumWindows(EnumWindowsProc,(LPARAM)"Notepad");

   return 0;
}

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

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

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

      cout << buf << " HWND: " << hwnd << endl;

      return true;
}

int main()
{
   EnumWindows(EnumWindowsProc,(LPARAM)"Notepad");

   return 0;
}






I don't understand the code,  i was expecting an array to be returnd and then i can send the hwnd to setforground()

yet this returns a bool
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany 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
how do I find out how many items the vector has?
Just use

size_t sz = vw.size();