Detect middle mouse click event [duplicate] - c++

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).

Related

Weird artefact when resizing window [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When I resize the window for my C++ application and make circling motions (just drag the top-left corner a bunch), it causes a strange artefact.
When I let go of my mouse:
Essentially what's happening is the application pauses whilst the window is being resized. Is there a way around this?
EDIT: Thanks for closing my question guys...
If anyone miraculously finds this question, I was able to find my own "solution". Do yourself a favour and use freeGLUT rather than SDL2, works like a charm, the set-up is much easier too.
Pretty much all window APIs(Win32, GLFW, etc) have some sort of PollEvents() function that takes all the events out of the event queue and processes them. For Win32, you have a callback function that gets called every event and you process them individually until the queue is empty. For GLFW you poll the events, then you read the state of a certain key from the updated input data (As I understand it). Regardless of the specific implementation for input, most PollEvents() functions become blocking when you either resize or move the window. What that means is that it will be constantly receiving events of type window resize or window move, even if there is no change. This causes the rendering to not update, which causes all sorts of weird stuff. The way around this is to put the PollEvents() function on a different thread than the update loop and call it repeatedly. Depending on what API you're using, there might be restrictions. For example, GLFW's PollEvents() function must be on the main thread, forcing the update loop to be on a separate thread. However, the idea is still the same across window APIs.

Check for window title [duplicate]

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.

Hide window in MFC C++ [duplicate]

This question already has answers here:
Hide an MFC dialog window
(6 answers)
Closed 9 years ago.
I have an MFC C++ app, I need my app to run in background, to do run some functions.
So I want to disable the dialog window .In other words I am trying to hide/make it invisible to the user.
How could I do this ? I don't have much experience with MFC, I would really appreciate the help.
Bye.
You need to hide the mainframe using ShowWindow(SW_HIDE).
Refer ShowWindow.

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).

Check whether key is pressed down in Windows console [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++ console keyboard events
I want a Windows console program to do something if a certain key is pressed down,
something like
while(1)
{
....
if(the key 'o' is pressed down)
....
}
but I don't know what to put in the if statement. How do I check if the key 'o' is pressed down?
I'm using Windows 7 64-bit and Visual Studio Professional 2008.
You can use the std::cin.get() or you can use the windows.h GetAsyncKeyState, depending on what exactly you want to do.
If you want lower level stuff, look into hooks and events from the WinAPI.
Rather than busy-polling for a keypress, you should register for key events in your application (assuming this is a Windows GUI app), and check for the keys you're interested in.
If you are actually making a console app, see here: C++ console keyboard events