Get relative position of mouse in a window in x11 - c++

I need to get the relative position of mouse pointer in the window in which it is clicked, i've coded to capture the click event, but when i use this code
result = XQueryPointer(disp, XRootWindow(disp,0),&win, &win, &root_x, &root_y, &win_x, &win_y, &mask_return);
it shows the global position of mouse when printing win_x and win_y
only window i have is "win" the display is "disp"

Found out evt.xbutton.x and evt.xbutton.y returns window relative mouse co ordinates

Related

How to change the position of a window scrollbar?

How to change the position of the Vertical Scrollbar of a window?
I'm referring to the position in xy, for example set it in the middle of the window instead of the edges.
You cannot reposition a scrollbar that is built-in to a window. You will have to disable the native scrollbar (remove the window's WS_HSCROLL/WS_VSCROLL style) and then create a separate ScrollBar control as a child of the window. Then you can position that child wherever you want, using the x/y parameters of CreateWindow/Ex() or SetWindowPos().

Allow clicks to pass through window(hit-test transparency) on a non-transparent window

I have a layered window that I want all clicks to pass through no matter where the mouse is located. Some parts of it are color keyed, and others are not. Clicks pass through the window whenever the mouse is on a transparent part but whenever the mouse is on a non-transparent part, the window captures the click. An easy solution would be just to add the WS_EX_TRANSPARENT flag to the window but I DO NOT want to do that. I tried returning -1 on WM_NCHITTEST in WndProc since WM_NCHITTEST is called every time the mouse enters a non-transparent zone but that didn't work and clicks still didn't pass through non-color keyed areas of the window.
Thanks in advance

how to set cursor position out off the application window? (c++)

I'm creating an application using C++ to set the cursor position even when the mouse is out off the application window... the Win32 library has the SetCursorPos function which according to the documentation
A window should move the cursor only when the cursor is in the window's client area
however I want to move the cursor outside the window : EVEN when the window IS HIDDEN...
I want it to be more like a mouse driver : windows reads the cursor position from it...
it seems that although the documentation says :
A window should move the cursor only when the cursor is in the window's client area
it can control the mouse even when the window is HIDDEN

How to check mouse click position is on required application?

I know the mouse click position using API GetCursorPos and the handle of application (HWND).
How can I check mouse click position is on this application?
My view:
Get the bounding box of application from its handle. (GetWindowRect(hWnd, &rect);)
Check cursor position lies in this bounding box. (PtInRect(&rect, p))
This is not working if windows are overlapping.
As we know the handle of targeted screen handle and click cursor position:
// hWnd : Already known windows handle
GetCursorPos(&p);
HWND hWndFromPoint = WindowFromPoint(p);
// If the handle got from click point is child of the desire window means it is clicked on the desire window itself.
if (IsChild(hWnd, hWndFromPoint))
{
// Do something on Mouse click
}

MFC Unclickable Button (Running away from cursor on MouseMove)

How would i make a button that will change it's position on MouseMove Event if the cursor is close enough to the center of the button in MFC ?
WM_MOUSEMOVE is not delivered to the button if the cursor is not over it (and is not captured, but you don't want that). So you have to process WM_MOUSEMOVE in the parent dialog. If you want your button to be a self-contained control, you have to subclass the parent window upon button creation.
Subclassing, in this context, means:
- you retrieve and store the parent's window proc address with GetParent()->GetWindowLong(GWL_WNDPROC)
- you set it to your procedure with SetWindowLong()
- in the procedure, you call the parent's previous window proc, after handling WM_MOUSEMOVE the way you want.
The WM_MOUSEMOVE coordinates will be relative to the screen, but you'll probably want to track the button position relative to the window that contains it. Use the ScreenToClient method on the parent window to convert, then you can compare the coordinates to see if it's close. Then use MoveWindow to move the button.
If you track the mouse cursor position you can determine when the cursor gets close to or enters the button window rect. You can then use the SetWindowPos() function to reposition the button window in the parent window client area.