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
507 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?

856 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