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
513 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

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…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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