- Getting a list of all open windows in c++ and storing them
- 2 Answers 2
- Hey, Scripting Guy! How Can I Use Windows PowerShell to Get a List of All the Open Windows on a Computer?
- Get all open WPF windows
- 3 Answers 3
- Not the answer you’re looking for? Browse other questions tagged c# wpf windows or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- How to close all open windows at once?
- 12 Answers 12
- Перевод песни Keep passing the open windows (Queen)
- Keep passing the open windows
- Отходи от раскрытых окон
Getting a list of all open windows in c++ and storing them
I’m currently trying to get a list of all opened windows and storing them inside a vector. I’ve been looking at the code so much that the solution could be very easy but I don’t seem to get it done without a global variable (which I want to avoid).
Here is the code:
I want to store all titles in the vector but I don’t know how as I can’t pass the vector into the function.
2 Answers 2
The second parameter (lParam) to EnumWindows is documented as:
An application-defined value to be passed to the callback function.
Just pass your container to the API call:
And use it in your callback:
- The code presented uses a std::wstring in place of std::string . This is necessary so that the entire character set can be represented.
- As written, the code isn’t correct. There are (invisible) code paths, that have no well-defined meaning. The Windows API is strictly exposed as a C interface. As such, it doesn’t understand C++ exceptions. Particularly with callbacks it is vital to never let C++ exceptions travel across unknown stack frames. To fix the code apply the following changes:
- [C++11 only] Mark the callback noexcept.
- Wrap the entire callback inside a try-catch block, and handle any exceptions appropriately.
- [C++11 only] With C++11 you can pass C++ exceptions across unknown stack frames, by passing a std::exception_ptr, and calling std::rethrow_exception at the call site.
Hey, Scripting Guy! How Can I Use Windows PowerShell to Get a List of All the Open Windows on a Computer?
February 3rd, 2007
Hey, Scripting Guy! Someone told me that there’s a way to use Windows PowerShell to get a list of all the open windows on a computer. Any chance you could show me how to do that?
Hey, JD. You bet we can. Before we do that, however, we’d like to take a moment and salute Peter Costantini, the oldest living Scripting Guy. Peter, best-known for being the author of Dr. Scripto’s Script Shop and for being the crazy guy who sings on webcasts, recently accepted a Program Manager position in the Management Practices group at Microsoft. Peter will still be a Scripting Guy; he just won’t be able to devote much time to scripting and to writing Script Center articles.
Which, all things considered, puts him on the same footing as the other Scripting Guys. But at least he has an excuse for not doing anything.
Speaking of the other Scripting Guys, we wish Peter the best of luck, and, as a special tribute, thought we’d recap some of his greatest moments as a Scripting Guy:
For example, just a few weeks ago he – well, actually, Dean did that.
But about a year ago Peter – never mind; Jean wrote that, didn’t she?
Still there was – oh, right. But if it hadn’t set the building on fire that would have been a pretty good little script.
And of course, there are many other great moments, far too, uh, numerous to name.
Note. As you might expect, Peter’s true contributions to scripting and to the Script Center can’t be measured by the amount of work he did. Or at least that’s what he keeps telling the rest of us.
On the bright side, though, the years Peter spent sitting around doing nothing useful or important made him the obvious choice for a management position at Microsoft.
To be honest, our first reaction when Peter announced he was leaving was to simply sit around and mope. (Of course, that’s usually our first reaction to anything.) But Peter wouldn’t have wanted us to act that way; instead, he would have wanted us to get on with our lives. So here you go, Peter; this one’s for you:
As you can see, this is a pretty simple little command. We start out by calling the Get-Process Cmdlet, which – as the names implies – retrieves a collection of all the processes running on the computer. Of course, we don’t really want a collection of all the processes running on the computer; after all, that collection includes services and other processes that aren’t running in a visible window. Therefore, we “pipe” that collection to the Where-Object Cmdlet, and ask Where-Object to filter out all processes except for those where the MainWindowTitle property is not equal to an empty string.
Note. Yes, we know: in Windows PowerShell you use the –ne operator instead of <>. And no, it doesn’t matter whether we like using –ne; we just have to use –ne.
What’s that going to do for us? That’s going to weed out services and other processes that don’t run in a visible window (if there’s no window then MainWindowTitle will be equal to an empty string). We then pass this filtered collection to the Select-Object Cmdlet and ask Select-Object to display only the MainWindowTitle property:
Nice observation: you won’t find the MainWindowTitle property anywhere in WMI’s Win32_Process class. That’s because the Get-Process Cmdlet doesn’t use WMI to retrieve process information; instead, it uses the .NET Frameowork class System.Diagnostics.Process.
Unfortunately, there’s one minor drawback to this command: it doesn’t return any Windows Explorer windows (for example, a window open to C:\Scripts). But that’s OK; here’s another one-liner that does return Windows Explorer windows:
What we do here is use the New-Object Cmdlet to create an instance of the Shell.Application object. We call the Windows() method to retrieve a collection of Shell windows, then use the Select-Object Cmdlet to echo back the value of the LocationName property. That’s going to result in a report similar to this:
Alternatively, you can echo back the LocationURL property to get the complete path. Of course, in that case, you might want to do some cleanup work as well, seeing as how LocationURL returns paths similar to this:
But here’s a command that might be helpful in trying to clean up that string.
We hope that answers your question, JD. And in case you’re wondering, we gave absolutely no thought to stripping Peter of his Scripting Guy status after he accepted his new job. Was that in recognition of his valuable contributions to the scripting world, contributions that we expect will continue throughout the coming years? You bet it was.
Well, that and the fact that if we got rid of Peter then Greg would become the oldest living Scripting Guy, and there’s no way Greg is going to accept that. So see, Peter? We like to kid you and give you a bad time, but you’ll always fill a very important role on the team. Always.
Get all open WPF windows
I’m trying to get all open windows. I tried to use System.Windows.Application.Current.Windows but I get Null Pointer Exception in line where foreach loop is. Do anyone has idea what is wrong?
3 Answers 3
This is how you cycle through all opened windows in an running application in WPF:
If you want know in windowforms use application instead of app. bye.
Either Current or Windows is null
The Windows property can only be access from the thread that created the Application object and this will only work in a WPF application AFTER the application object has been created.
Bare in mind that System.Windows is a namespace, and Application is the actual class that references the current application context. What this means is that ´Application.Current.Windows´ only references all windows spawned by the application itself. Try to loop through all windows and print their title.
What happens in your program, is that the if statement will always be false, unless Title is equal to a window spawned by the Application, thus windowObject will remain to be null, and null will be returned by the method.
Not the answer you’re looking for? Browse other questions tagged c# wpf windows or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
How to close all open windows at once?
How do I close all opened windows at once?
12 Answers 12
All answers I could quickly find on this topic involve either the tip Molly gave or using an application (or coding it yourself). For example (I haven’t tried this), Close All Windows.
Also, by pressing Ctrl + Shift + Esc you get the Windows Task Manager, where you can see all running applications at once (among other things), select them, and End Task them.
I like to see my open windows ungrouped, but realized that this i.e. closing multiple windows at once was a problem with such a setting. A less time-taking method would be to use the command line like this :
And then restart explorer using :
Caution : This will cause processes like file copying on the default Windows interface to abort.
Simultaneously close all open windows:
- While pressing the Ctrl key, successively click each of the task icons on the taskbar.
- Right-click the last task icon, and choose Close Group.
If you only want to minimize the windows, use the ‘Show Desktop’ shorcut.
I usually (yes, this happens a lot to me..) just press Alt key and then go crazy on the F4 key until everything is shut down. Not one click, but it’s pretty fast. Or, depending on your system, reboot.. Don’t forget to save anything.
Or maybe you could simply switch users to continue your work without all these tabs. Then when you’re down, shutting down the computer will kill all the processes for the first user.
Not the best solutions, I just thought Id give this one a try.
It’s not a one-click solution but it is the fastest I know with my Windows 7 Pro
- Open taskbar properties (right click > properties) or (Control Panel > Appearance and Personalization > Taskbar and Start Menu)
- Select «Group similar taskbar buttons» = «Group similar taskbar buttons», and click OK
- Your windows are group, right-click and select «Close all windows»
- Go back to taskbar properties to restore you old settings
After doing Ctrl-Shift-Esc, go to applications. Then, press shift down and end task, all of them will end (You might get a confirmation message or something depending on the program).
Sometimes, even when you close a program, the processes of the program (The biggest example is an unclosed connection to a local file) may still be on your computer. Most of the time, these processes are mainly overlooked by the owner software because they use almost no space. However, if you still want to end them, just to be meticulous, go to processes and you’ll have to end them one by one.
Перевод песни Keep passing the open windows (Queen)
Keep passing the open windows
Отходи от раскрытых окон
This is the only life for me
Surround myself around my own fantasy
You just gotta be strong and believe in yourself
Forget all the sadness ’cause love is all you need
Love is all you need
Do you know what it’s like to be alone in this world
When you’re down and out on your luck
and you’re a failure?
Wake up screaming in the middle of the night
You think it’s all been a waste of time
It’s been a bad year
You start believing ev’rything’s gonna be alright
Next minute you’re down and you’re flat on your back
A brand new day is beginning
Get that sunny feeling and you’re on your way
Just believe — just keep passing the open windows
Just believe — just keep passing the open windows
Do you know how it feels when you don’t have a friend
Without a job and no money to spend?
You’re a stranger
All you think about is suicide
One of these days you’re gonna lose the fight
You’d better keep out of danger — yeah!
That same old feeling just keeps burning deep inside
Keep telling yourself it’s gonna be the end
Oh get yourself together
Things are looking better everyday
Just believe — just keep passing the open windows
Just believe — just keep passing the open windows
This is the only life for me
Surround myself around my own fantasy
You just gotta be strong and believe in yourself
Forget all the sadness ’cause love is all you need
Just believe — just keep passing the open windows
Just believe — just keep passing the open windows
You just gotta be strong and believe in yourself
Forget all the sadness ’cause love is all you need
Love is all you need
Baby — love is all you need
Just believe — just keep passing the open windows
Just believe — just keep passing the open windows
Just keep passing the open windows
Моя единственная жизнь,
Я окружу себя фантазиями.
Надо просто быть сильным и верить в себя,
Забыть все печали и помнить о любви.
Только о любви.
Знаешь чувство, когда ты в целом мире один,
Всё не так, и бедам твоим
давно потерян счёт?
По ночам кошмары мучают тебя,
И мнится, время проходит зря.
Тяжёлый был год.
Едва поверишь, что всё сложится хорошо,
Как в этот же миг упадёшь, сбитый с ног.
Новый день начнётся,
Улыбайся солнцу и иди вперёд.
Просто верь, отходи от раскрытых окон
Просто верь, отходи от раскрытых окон
Знаешь чувство, когда нет друзей, только ты,
Работы нет и карманы пусты?
Все чужие.
Замышляешь жизнь свою прервать,
Ты можешь эту схватку проиграть,
Опасны мысли шальные.
Такое чувство, что внутри всё сожжено,
Что это конец и перспективы нет.
О, не спеши сдаваться,
Новый день приносит новый свет.
Просто верь, отходи от раскрытых окон
Просто верь, отходи от раскрытых окон
Моя единственная жизнь,
Я окружу себя фантазиями.
Надо просто быть сильным и верить в себя,
Забыть все печали и помнить о любви.
Просто верь, отходи от раскрытых окон
Просто верь, отходи от раскрытых окон
Надо просто быть сильным и верить в себя,
Забыть все печали и помнить о любви,
Только о любви,
Детка, только о любви.
Просто верь, отходи от раскрытых окон
Просто верь, отходи от раскрытых окон
Отходи от раскрытых окон