Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
522 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 1600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 43

Assisted Solution

by:pcelba
pcelba earned 400 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 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