Hello,

Let me introduce to you my problem first, and then you guys should decide on the best method to take upon it.

My sister has lately been HELLa annoying with her crush over Justin Bieber, and it's really starting to get to me not to be able to think because I can't stop hearing her little playbacks of him on YouTube.

Now, I've decided, that since she doesn't listen to reason willingly, she'll be forced to... I decided to run a little prank on her, however, I have been failing it a bit so far.

My idea was to create a console project that will scout all active windows and look for the words "Justin Bieber" in them, and once found, will close such windows automatically, make it an infinite loop, hide to console window, and voila, an invisible process that will bug my sister endlessly.

Now, I've just run into problems with that, I've tried 3 methods, and got stuck on all of them:
1. Using native C++; I could make a string searcher that will return true if a given string has the wanted words on it, but could not find a function to give me the titles of active windows, nor one that could kill them.

2. Using MFC, I could find the active windows and close them, but I'm extremly undertaught about MFC in general, and have no idea how to deal with LPTSTRs and the such, so I could discern the title names.

3. Using .NET managed C++, I could also close a process, as well as comparing the title to my wanted wording, but I could not find a way to attach an active window to a process class to operate on...


Now, after exploring for answers on all 3 of the above for the past few hours(Oh, yes, I'm that dedicated for the wrong reasons!), I could not have found any solid answers for any them, not to mention that I'm not even sure which direction would be the best to keep exploring on, and looking for all 3 together just gives me a headache trying to recall what I found for which ._.


So! Any useful ideas for a desperate headblown guy?
Thanks!

call win32 api function EnumWindows(). For each window M$ will call your callback function with the handle of a window. In that callback function call GetWindowText(). Then all you have to do is strcmp() the returned text with that name. If its the window you want then send it a WM_CLOSE message with PostThreadMessage(). The first parameter to PostThreadMessage() is a handle to the process. You can get that by calling GetWindowThreadProcessID()

Edited 5 Years Ago by Ancient Dragon: n/a

Any chance you could give me a written code example of that? Like I said, I'm completely undertaught on that =\

It's ok, I'm not gonna ask you to make time for helping me, just if you'd happen to have that spare moment, I'd really appreciate it.

All the best =)

I am not sure how to do it but I will try to make it myself as Ancient Dragon said and then post the code here. I got a lot of free time :p. And this is all for a good cause :)

This article has been dead for over six months. Start a new discussion instead.