Solved

FindWindow(NULL,"notepad");

Posted on 2007-11-27
7
852 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now