IonicWind Software

IWBasic => General Questions => Topic started by: Andy on January 25, 2014, 04:18:47 AM

Title: List of open windows
Post by: Andy on January 25, 2014, 04:18:47 AM
Hi,

Is there a way to list all the currently open windows.

Explanation:
When I open Firefox twice, it only shows one Process ID for firefox, is there any way anyone knows of detecting something like Firefox being opened twice or more?

Can you list / count the number of open windows in the taskbar for example?

I can stop a process, but this would kill off both instances of Firefox, and I only want to stop the second
instance of Firefox.

???

Thanks,
Andy.



Title: Re: List of open windows
Post by: Andy on January 25, 2014, 04:34:56 AM
Have noticed in Task Manager:

Under the "Applications" tab it does show firefox twice or more.

Title: Re: List of open windows
Post by: Andy on January 26, 2014, 05:24:18 AM
So has anyone any ideas how to list the open applications and not the processes?


Thanks,
Andy.
Title: Re: List of open windows
Post by: LarryMc on January 26, 2014, 10:41:19 AM
This will give you the exact same list that you get in the Task window of Task Manager
Hope this will help get you started in the right direction.
I did notice that if you have multiple IE windows open it will only list the one that is currently selected(visible).

openconsole
$include "windowssdk.inc"

DEF hdesk,hnext,style:INT
DEF text:STRING
hdesk = GetDesktopWindow()

hnext = GetWindow(hdesk,GW_CHILD)
if hnext
GetWindowTextA(hnext,text,255)
style = GetWindowLongA(hnext,GWL_STYLE)
if IsWindowVisible(hnext) & ((style  & @CAPTION) > 0) & (len(text) > 0)
?text
endif
DO
hnext = GetWindow(hnext,GW_HWNDNEXT )
if hnext
GetWindowTextA(hnext,text,255)
style = GetWindowLongA(hnext,GWL_STYLE)
if IsWindowVisible(hnext) & ((style & @CAPTION) > 0) & (len(text) > 0)
?text
endif
endif
UNTIL hnext = 0
endif

waitcon
closeconsole


changing to this in both places
if IsWindowVisible(hnext) & ((style & @CAPTION) > 0) & (len(text) > 0)
?text
elseif instr(lcase$(text),"internet explorer")
?text
endif

will pick up the other open explorer windows but I'm getting dupicates.
Title: Re: List of open windows
Post by: Andy on January 27, 2014, 12:26:05 AM
Hi Larry,

Thats a great starting point.

With this list of applications, how can I use the "Destroywindow" function to kill off one of the applications in the list?

Thanks,
Andy.

Title: Re: List of open windows
Post by: Andy on January 27, 2014, 01:31:50 AM
Hi,

Got it!

I used SendMessage & WM_CLOSE to kill off all instances of Firefox.

See attached code.

once again, thanks Larry.
:)
Title: Re: List of open windows
Post by: LarryMc on January 27, 2014, 07:49:48 AM
QuoteI can stop a process, but this would kill off both instances of Firefox, and I only want to stop the second
instance of Firefox.

Your modified code looks to me like you will delete all instances of firefox unless the first child is firefox

What am I missing?
Title: Re: List of open windows
Post by: Andy on January 27, 2014, 09:09:07 AM
Hi Larry,

Yes that was my initial task to kill off all instances as posted, but now with your code i'm able to check each instance of firefox and only kill off the firefox window(s) I don't want such as ads and pop ups when I visit certain sites.

Thus I can now detect multiple firefox windows and select which ones I want the program to close for me.

I added a timer in there with a 1 second deley, which then loops back and re-detects instances of firefox, if it's one I don't want, it kills it off keeping my browser clear of junk.

Hope that's a bit clearer,
once again, many thanks.

When I get time I think i'll write an alternative task manager and post the code here for all.

Andy.
:)