How can i close a application window in visual c++?

Hi. Im new to visual c++ and have a problem. I have a working loop which reads information from new application windows, those windows pop up at random times, and i need to close that new window after im done reading the data. How can i do this?
RdmrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
::PostMessage(hWndAppToClose, WM_CLOSE, 0, 0);
0
RdmrAuthor Commented:
Could you post an example how to close all new windows or a specific window by name? As i said before im new to visual c++, im not familiar with most functions and how to use them. As far as i can understand you need to have the handle of the window you need to close, how can i get it?
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>I have a working loop which reads information from new application windows

Use the window handle that you have there (or how do you have functional code ?)

example of how to use it in C++
::PostMessage(hWndAppToClose, WM_CLOSE, 0, 0);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

RdmrAuthor Commented:
I dont detect the new window, i try to read information from the screen every few seconds and after im done i need to close a program window if i find one, its not the best solution, but i need it to work atleast partialy, but the problem is that if a new window apears it stays open for 30s, thats too long i would need it to close faster. The window always apears at the same spot and the first part of his name is the same in this case "Bluetooth Passkey......"
0
itsmeandnobodyelseCommented:
>>>> you need to have the handle of the window you need to close, how can i get it?
You can call FindWindow if you have the title of the window. If not, you may enumerate all top-level windows by calling EnumWindows. It will call a callback function you have to provide for each top-level window.
0
RdmrAuthor Commented:
Ok thnx for the help, Andy's solution worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.