SendMessage WM_MOUSEMOVE not working as expected - c

When sending the WM_MOUSEMOVE message to the client area of an application (in this case Open Office Writer) the image will flicker as if the mouse is over the specified coordinates, but does not stay in that state. The code is:
PostMessage(hWndClient, WM_MOUSEMOVE, 0, MAKEWORD(x, y))
where x and y are relative to the client area.
Sending this in a loop still does not work as the area highlighted by the mouse over event will just flicker.
Any help would be appreciated.

The app could be triggering on all sorts of other events. Maybe it wants to see WM_MOUSEHOVER etc... It's been long a while, but I remember there being something really klugy about how some of these events were implemented - like there was a separate thread that polled the mouse and generated WM_MOUSELEAVE events when the mouse was no longer over the window. You could be getting bitten by something like that too. It's also possible that the application itself is polling the mouse for its true position when it receives the event.
Depending on what you're trying to do, perhaps you could programmatically move the mouse instead of just trying to fake events. Unfortunately, I don't remember the API for this, but I'm sure it's possible.

I used sth like this in my main window and looks that helps... in WM_MOUSEMOVE:
POINT Point;
GetCursorPos(&Point);
ScreenToClient(hHwnd, &Point);
int X = Point.x;
int Y = Point.y;

Try this: PostMessage(hWndClient, WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(x, y)), since postion is a 32-bit integer, the lower 16 bit is x, and the higher 16 bit is y, maybe you should use MAKELONG instead of MAKEWORD.
Check WM_MOUSEMOVE.

Related

Xlib - Two issues with call to XMoveResizeWindow

I am new to Xlib (in C) and am having two issues when calling the XMoveResizeWindow function.
ex.
XMoveResizeWindow(display, window_id, move_x, move_y, resize_x, resize_y);
1) After the call, the window I move will reposition itself correctly, however, if I select the window with the pointer after the move, it will instantly revert back to the position it held prior to the move. I assume I have to somehow 'update' the X11 server after it's moved with the windows new position?
2) Secondly, in regards to the resize of the window. My window is essentially being truncated by the x and y values entered, instead of resized. In other words, instead of the entire window shrinking down, the right and bottom sides of the window are cut off from view. Is there a way to instead resize the entire window?
--I am sorry I am unable to submit my complete code, however, I believe my issues are due solely to my lack of understanding of Xlib and this particular function's operations. As such, I am not neccessarily looking for specific code as a solution, merely an explination or suggestion on how I should go about implementing a solution.
Thank you.
I believe there is something wrong with your code, since that code is not available i'll point to an example.
Examples are given at readme itself.

WM_MOUSEMOVE issues with position

I am working on a program that is supposed to simulate basic mouse input for a program while it stays in the background (meaning, I want to do other things in other windows with the actual mouse and keyboard while the target receives input). One thing I need to be able to do is move the mouse to a specific (x,y) point.
It seems to work for the most part, but in a certain region of the screen the message only works correctly some of the time. Other times, it moves to a consistent but wrong other point within the region. I am reading that sometimes it is relative, but if I spam the message repeatedly, it does seem to work consistently. Also, reading in Spy++, the messages that are sent by me actually moving my mouse are using what seem to be absolute coordinates.
My function is here:
void mouseMove(short x, short y) {
PostMessage(wnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
}
Preferably, I'd like for any (x,y) to be absolute so I can have the region treated as any other. But it would also be fine to set the position to a coordinate relative to the top left corner of the region.
I have tried just about all of the messages I've seen sent to the window in Spy++ before the WM_MOUSEMOVE but nothing is helping.
How might I approach this?
Edit, since details might not prove enough info:
I am sending these messages in this order:
WM_ACTIVATE 2 0
WM_MOUSEMOVE 0 MAKELPARAM(x,y)
WM_LBUTTONDOWN MK_LBUTTON MAKELPARAM(x,y)
WM_LBUTTONUP 0 MAKELPARAM(x,y)
I think what I initially thought (bad WM_SETCURSOR area) is wrong because Spy++ consistently shows HTCLIENT being used.
I have found a lot of people trying to do this (background input) and most seem to be told it's impossible. It's not impossible, and I think if someone can answer how to do this correctly once and for all it would be doing quite a few people a big favor.
Synthesizes keystrokes, mouse motions, and button clicks.
UINT WINAPI SendInput(
_In_ UINT nInputs,
_In_ LPINPUT pInputs,
_In_ int cbSize
);
PostMessage function. Places (posts) a message in the message queue
associated with the thread that created the specified window and
returns without waiting for the thread to process the message.
For PostMessage to work you need to be in the process as the target that you can achieve with SetWindowHook but the these links will do the jobs:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/ms171542(v=vs.110).aspx

What happens when you call glClearColor with a negative argument?

I'm working on a simple OpenGL application that allows the user to adjust the background color of a simple window by clicking and dragging to either then left (make it less intense) or the right (more intense). When dragging to the right, for example, I have something like this:
intensity += 0.0001*x; //where x is the current mouse location
...and to the left, the other way:
intensity -= 0.0001*x;
intensity is global static GLfloat that gets passed to glClearColor in the display function, which is called multiple times. This strategy works just fine when the user intensifies the color while dragging right, but it messes up after a certain point when dragging left: the color becomes less intense as I drag along and returns to black as it should, but then intensifies back into the original color.
I think the problem is that the intensity, which should be between 0 and 1, is becoming negative when I drag too far and, thus, glClearColor is fixing the problem by just changing the sign back to positive (?). If that is the case, how can I enforce that the values passed to glClearColor stay in the proper range? I tried to fix the problem by making sure that the current intensity would not become negative/adjustment would not happen if it is already too low, but it didn't seem to work:
if(x <= xPrev && intensity >= (.0001*x)) //moving left to de-intensify color
intensity -= 0.0001*x;
...Am I doing this incorrectly, or is glClearColor handling negative values differently than I expect?
Another interesting issue that came up is that my "intensity" adjustments only seem to work on the r, g, and/or b values (i.e., I pass "intensity" as one of those in glClearColor. Using the a value didn't work...but isn't it supposed to change color intensity?
This sounds a bit like a hysteresis problem. It's not clear how events are received, or what coordinate system x is in. Perhaps drop an 'anchor' (xStart) when the button is pressed, and handle all subsequent values while dragging as an offset from this value. What toolkit / library are you using for windows and events? If you launch from a console, perhaps add a trace statements like:
fprintf(stderr, "%.8e\n", x);
to see if the values of x correspond to what you're expecting on each frame.
glClearColor clamps values to [0, 1], so it's probably not the issue. Perhaps a trace for intensity would be useful?

GTK: Get pointer position on scroll-event AFTER scrolled_window has scrolled

I've got a drawing area inside a scrolled window (with convenience viewport),
and this drawing area updates itself according to incoming motion-notify-events.
When I scroll the area though obviously no motion events are emitted,
but I wanted to work around this, and so tried to connect the drawing area's
"scroll-event" signal to the same motion-notify callback.
The problem I'm facing here is that this signal is emitted before the scrolled window
has update its viewport, so in the callback, I end up with pointer coordinates that were true just before scrolling, making it look like the drawing area is always "lagging a step behind" the actual pointer when scrolling while not moving the pointer itself.
I thought I could compensate for this by manually extracting the coordinates with gdk_window_get_pointer, but then I realized this cannot work as the pointer is technically still at its old position when the callback is commencing.
I also tried using g_signal_connect_after in hopes it would have the callback get called after the viewport was scrolled, but it didn't help.
My last hope would be to start a timer on scroll-events, and have the callback fire after a minimal amount of time, but this sounds realllly ugly, and I'd like to avoid that at any cost.
Any ideas as to how this could be realized?
Thanks in advance!
A solution would be to connect to the "value-changed" signal of the GtkScrolledWindow
adjustments.
Source: https://mail.gnome.org/archives/gtk-app-devel-list/2011-September/msg00014.html

Why does handling WM_NCCALCSIZE cause my window to jump?

I have a WPF app which snaps to screen edges (I just set the .Top or .Left of the window if you're within 20 pixels of the screen edge), but I recently added some code provided by the WPF SDK Team to "mess" with the window chrome, and although it's working great (screenshot), it's causing the "snapto" to move the window unexpectedly (e.g.: it jumps to the left when it should be snapping straight down to the bottom)
I've narrowed it down to their handling of the WM_NCCALCSIZE ... which is really odd because they basically don't do anything, they just say they handle it, and return 0.
According to the documentation of WM_NCCALCSIZE, this should just result in the whole window being treated as client (having no non-client edge), but somehow it also means that whenever my snap-to code moves the window down to the bottom of the screen, it also moves left about 134 pixels ... (moving to the other edges has similar side effects) and as long as I hold the mouse to drag it, it flickers back and forth from where it's supposed to be. If I comment the WM_NCCALCSIZE handling out, the snap-to works the way it should (but the form doesn't look right).
I've tried everything I can thing of in the WM_NCCALCSIZE handler, but I can't stop it from jumping left ... and of course, WM_NCCALCSIZE only gets called when the window size changes, so I don't understand how it causes this in the first place!
P.S. If you want to actually see the code, it's already on CodePlex, in two files, look for _HandleNCCalcSize and OnWindowLocationChanged
The reason this happens is that handling the WM_NCCALCSIZE changes the overall size of the window ... but if you're moving the window, changing your position during WM_MOVE or WM_WINDOWPOSCHANGED (which corresponds to the WPF WindowPositionChanged event) causes another WM_NCCALCSIZE message ...
Making changes during WM_NCCALCSIZE (even just asserting that you handled the message) causes another call to WM_MOVE ... which puts you into a loop where the "FROM" part of the positionchanged message stays the same (making the window "jump" from where it started to the position you adjust it to during WM_MOVE over and over as it changes back after WM_NCCALCSIZE).
The Correct Way
What you have to do is to obey Raymond Chen and handle WM_WINDOWPOSCHANGING instead. It happens before these other messages, and that way they do not interfere with each other!
The wParam always seems to be TRUE (1) and lParam is a NCCALCSIZE_PARAMS ...
The intent is to do exactly what you said: to force the whole window to be "client" and then use the Vista DWM apis to extend the frame into the client area. I just don't see why it's moving so far to the left...
If I trace or breakpoint the HandleNCCalcSize method, when I resize the window (while it's on the edge so the snap-to fires), the NCCalcSize gets called twice: once where it should be, and then off to the left, where it ends up.

Resources