Solved

FindWindow(NULL,"notepad");

Posted on 2007-11-27
7
838 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
Comment Utility
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
Comment Utility
what does it do?


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

Expert Comment

by:jkr
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Troudeloup
Comment Utility

#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
Comment Utility
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
Comment Utility
how do I find out how many items the vector has?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Just use

size_t sz = vw.size();
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
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.

762 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

12 Experts available now in Live!

Get 1:1 Help Now