Check for window title [duplicate] - c++

This question already has answers here:
Window Title Changed Event
(2 answers)
Closed 4 years ago.
Hello im creating program that check for opened window name but at the moment it check it like 100 times per second and i want to check it every time the window change.I know its propably becasue of infinity loop.But im new in C++ and i have no idea how to do it, can someone help me ?
char wnd_title[256];
while(1) {
HWND hwnd=GetForegroundWindow();
GetWindowText(hwnd,wnd_title,sizeof(wnd_title));
cout << wnd_title;
}
Best regards.

There are several things you can do to achieve that:
Best (thanks to Remy in the comments): "Another option is to use SetWinEventHook() to listen for EVENT_OBJECT_NAMECHANGE events. That is "more promising" than intercepting WM_SETTEXT messages, and less intrusive than "infiltrating"."
simple and boring (and it seems not really what you wanted): set a timer for the request so it is called in longer periods
propably the most promising one: Set up a Window hook with WH_GETMESSAGE to listen for the WM_SETTEXT which is messaged from the SetWindowTextA function
or go full crazy and CreateRemoteThread and infiltrate your enemy with a trusty spy.

Related

The equivalent of wxYield in Cocoa [duplicate]

This question already has answers here:
How do I update a progress bar in Cocoa during a long running loop?
(4 answers)
Closed 1 year ago.
I'm new to MacOS programming. I'm using Objective-C with XIB interfaces to develop Mac Apps.
I'm making an app that zips and unzips files/folders. I've also implemented a progress bar to show the progress of the task.
But, when the user drops a big file to compress the app freezes, the progress window never gets displayed but the logs are working fine though.
I remember when I was using wxWidgets, in a case like that I'd have to use wxYield() to process the events and update the ui and everything would be fine.
So, what's the way to do this thing on Cocoa?
I worked it using #Willeke's suggestions.
I'm executing the zip_close function on a different thread letting the main one handle the UI updates & events.
Also when the progress callback gets emitted, I'm updating the UI by accessing the main thread (making changes to the UI from another thread will give warnings).
Thank you both #Igor and #Willeke for helping out!

How to detect that a window is currently running a modal dialog? [duplicate]

This question already has answers here:
Detecting modal dialogs in MFC
(4 answers)
Closed 4 years ago.
I have a wizard interface (so a property sheet with property pages).
On one of the pages, I am running a background timer to keep detecting whether a given external thing is true or not (well, I compile a list of attached visible USB security dongles).
But when this page shows a modal dialog box - e.g. a MessageBox, I want to suspend/ignore the timer notifications.
I can do that by simply killing the timer - running the message box - then starting the timer anew. That works perfectly but requires that all calls to MessageBox remember to do this. Not a huge deal, but inelegant.
Now, I could also wrapper MessageBox so that I use a helper wrapper function which does the suspend / resume timer for the caller. That's a valid thought - but it still requires maintenance coders to always remember to call my wrapper function, and this doesn't work well for other modal dialog boxes that might need to be run which also would need to have the suspend/resume timer dance performed.
What I believe is ideal is to leave the timer running, but have the timer handler itself check if we're currently running a modal dialog, and if so, simply ignore the timer notification (the timer will continue to spew notifications in a few moments - and eventually we'll be done with the modal dialog [message box] and we can go ahead and handle the timer notification then).
But what I do not see is a mechanism by which to ask "Am I running a modal dialog right now?"
From the POV of the page's timer handler - it doesn't know if a modal dialog box is in progress or not. IsWindowEnabled() returns true - so at least the standard windows MessageBox() does NOT disable the parent window... which leaves me mildly confused as to how it is locking out button clicks on its parent window (my mind is a sieve these days - maybe the answer is obvious and I'm just getting old ;) )
Anyway - what am I missing? What is a simple test for "Is a modal dialog box running right now in this thread / as a child of this window?"
Thanks for any gentle clues you might have to offer
So, I was asking IsWindowEnabled() from the context of the property page - which is a child window within the wizard dialog.
Changing that to GetParent()->IsWindowEnabled() does return false while running a modal dialog.

Detect middle mouse click event [duplicate]

This question already has an answer here:
How to get middlemouse click event in C++
(1 answer)
Closed 9 years ago.
I need to detect a middle mouse click event in C++. Does anyone know how I can do so? If there is a way, can someone tell me how I can do it? I'm not so familiar with mouse events in C++. Seems a bit more complicated to do it in C++ as oppose to Java.
Since you are working on windows the following may work for you:
If your application contains a window, then simply look for WM_MBUTTONDOWN in your message loop.
If you dont have a window, then you can use a mouse hook.
Where you check the wParam for WM_MBUTTONDOWN(or WM_BUTTONUP).

is it possible to redirect cout stream to a particular window(control) having the hwnd handle for it? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Redirecting cout to a console in windows
I've created a child richedit window with CreateWindow and I wonder is it possible to redirect all cout calls so text would appear in RichEdit controll instead of console ?
As far as I know, you can't do that. You need to send window messages to set the text in the control.
That's not to say you can't use stream syntax. You could define your own ostream and use that instead of cout, then pass bytes into your window. It wouldn't help with any output that you don't generate, nor would it help if you mix printf calls (which you shouldn't really do).

Sending text/keystrokes to unselected window?

Is there a way to send keystrokes to a window that is not currently selected in C++? For example, if I have a notepad window minimized and want some text to be typed in it without bringing the window to the front.
I'm using Windows 7 64-bit.
Faking input is rather hard to achieve, in full generality, without using SendInput().
Yes you can try PostMessage(), but the answer from eznme is misleading at best when it talks about SendMessage. As I, and others, seem to say many times a day here, input is posted to the message queue rather than sent to a window handle.
All that said, if you don't want to give the Notepad window input focus then it's going to be hard to get the text in there by faking. The very simple alternative that works better and is easier to use, is to find the window handle of the Notepad EDIT window and use WM_GETTEXT and WM_SETTEXT, for example, to modify its contents directly.
In fact there is an enormous multitude of functionality available once your have this window handle at your mercy!
Absolutely: Check out PostMessage() and SendMessage(), they are part of the Windows API:
http://msdn.microsoft.com/en-us/library/ms644944%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx
Specifically you probably want to send WM_KEYUP
http://msdn.microsoft.com/en-us/library/ms646281%28VS.85%29.aspx