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
480 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 41

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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