Solved

FindWindow(NULL,"notepad");

Posted on 2007-11-27
7
897 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:Troudeloup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20359393
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;
}
0
 

Author Comment

by:Troudeloup
ID: 20359407
what does it do?


I need n handles returned for n number of windows of that name.
0
 
LVL 86

Expert Comment

by:jkr
ID: 20359414
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;
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Troudeloup
ID: 20359443

#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
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20359490
If you need an array, you can use

#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)"Notepad");

   for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
    cout << "HWND: " << *i << endl;

   return 0;
}
0
 

Author Comment

by:Troudeloup
ID: 20360358
how do I find out how many items the vector has?
0
 
LVL 86

Expert Comment

by:jkr
ID: 20360370
Just use

size_t sz = vw.size();
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question