Solved

I want to use a windows API to get all open window handles (hwnd's) into an array or listbox

Posted on 2010-11-25
6
510 Views
Last Modified: 2012-05-10
Looking to retrieve all open windows on a machine into a listbox, so I can access these using other functions.

Findwindow needs the text of the window, I have not yet found a good way to list all open windows.

Thanks again!

BC
0
Comment
Question by:busycoder
[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
6 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34215658
DO runningapps

You will get a cursor called runapps with a field taskname of all running applications.
0
 
LVL 27

Accepted Solution

by:
CaptainCyril earned 400 total points
ID: 34215665
PROCEDURE runningapps
LOCAL awin_apps, vfp_handle, ln_current_window,ln_window_count
DIMENSION awin_apps(1)
vfp_handle=0
DECLARE INTEGER FindWindow;
      IN win32api;
      INTEGER nullpointer,;
      STRING cwindow_name
DECLARE INTEGER GetWindow;
      IN win32api;
      INTEGER ncurr_window_handle,;
      INTEGER ndirection
DECLARE INTEGER GetWindowText;
      IN win32api;
      INTEGER n_win_handle,;
      STRING @ cwindow_title,;
      INTEGER ntitle_length
vfp_handle=findwindow(0,_SCREEN.CAPTION)
ln_current_window=vfp_handle
ln_window_count=0
DO WHILE ln_current_window>0
      lc_window_title=SPACE(255)
      ln_length=getwindowtext(ln_current_window, ;
      @lc_window_title,LEN(lc_window_title))
      IF ln_length>0
            lc_window_title=STRTRAN(TRIM(lc_window_title),CHR(0),"")
      ELSE
            lc_window_title=""
      ENDIF
      IF ln_current_window>0 .AND. !EMPTY(lc_window_title)
            ln_window_count=ln_window_count+1
            DIMENSION awin_apps(ln_window_count)
            awin_apps[ln_Window_Count]=lc_window_title
      ENDIF
      ln_current_window=getwindow(ln_current_window,2)
ENDDO
CREATE CURSOR runapps (taskname C(250))
IF ALEN(awin_apps,1)>0
      SELECT runapps
      FOR i=1 TO ALEN(awin_apps,1)
            APPEND BLANK
            REPLACE taskname WITH awin_apps(i)
      NEXT
ENDIF
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34215668
to EE Support,

It took me 5 trials to submit the code on this one. I attached it first as Code to the first comment then I clicked on Attach and then on Submit and the code did not go through without any warning. Then I tried to send it as a second comment, the error message came out that needed a closing .
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34215669
I had to change bracket to paranthesis in the code because it had problems with HTML tags. It thought that it was for Italics.
0
 
LVL 42

Assisted Solution

by:pcelba
pcelba earned 100 total points
ID: 34217429
If you really need all window handles then look at following code:

http://www.news2news.com/vfp/?example=27

I have 347 entries in the table... most of them are invisible windows.
0
 

Author Closing Comment

by:busycoder
ID: 34335353
Sorry for the delay on the points this did the job for me very well!!!

Thank you!!!!
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save Table Settings 6 267
Using UDFs in grids 3 260
FoxPro Visual Studio 2013 10 1,117
.SETALL() method not working on all columns 7 278
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

739 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