I have a C++Builder application in which I need to make the mouse cursor invisible. How can I do this?
I think it can be done using the Win32 API, but I don't know exactly how.
Call ShowCursor(FALSE). If you need to restore the cursor later, call ShowCursor(TRUE).
Note that the cursor visibility is reference counted so you need to match every call passing FALSE to one passing TRUE.
This function sets an internal display counter that determines whether the cursor should be displayed. The cursor is displayed only if the display count is greater than or equal to 0. If a mouse is installed, the initial display count is 0. If no mouse is installed, the display count is –1.
Related
The component I use is a descendant of TStringGrid, called TDataGrid (which can be found on Torry). Unfortunately, it has a small bug which doesn't seem to be present in the original TStringGrid component. I have the options goEditing and goAlwaysShowEditor both enabled, so I'm expecting the text of a cell to be selected when the control receives input focus. But in the case of TDataGrid this doesn't happen if I press TAB to move from one control into the grid control. It receives input focus, but nothing is selected, and the caret isn't even visible. Obviously, this is very misleading for a user.
The original TStringGrid component has similar inconsistencies, where if you have goAlwaysShowEditor enabled, there is always one cell with its text "exposed" (focused, sort of, even if the grid control itself doesn't have focus), so if you left-click in that cell, it also won't select the text, just enable a caret. I have been able to get around this however, by simply disabling goAlwaysShowEditor when the grid control doesn't have focus and subsequently enabling it when the grid receives focus.
So does a TStringGrid have any way of selecting the text of a cell? I know how to set the focus to a cell, but I haven't figured out a way to actually select the text. Really would appreciate any ideas to get around this!
FWIW, I'm using Delphi 10.3
I've found one solution that actually seems to work, but it only handles the very specific scenario when you TAB into the grid control and there may be other cases that need to be handled..
So, controlling the selection of the text within a cell IS possible, but it will not work if you try to control it during the OnEnter event. So instead, I've had to resort to checking for TAB in the OnKeyUp event, where it will work.
You need to expose protected members of a TStringGrid to access the appropriate methods. It's not the prettiest solution, but it works at least...
type TStringGridHelper = class helper for TStringGrid
procedure HHideEditor;
procedure HShowEditor;
end;
procedure TDataGridHelper.HHideEditor;
begin
HideEditor;
end;
procedure TDataGridHelper.HShowEditor;
begin
ShowEditor;
end;
And in the OnKeyUp event handler...
if Key = VK_TAB then begin
StringGrid.HHideEditor;
StringGrid.HShowEditor;
end;
Is there any way to get the ChartCursor to stay on a selected point? Especially while using touch-devices it's very uncomfortable, that you have to constantly touch the right data point to see the actual values. Regarding huge datasets the cursor starts to select immediately if you move just a bit and hit the next datapoint. And while you make a selection the cursor disappears.
Is there some kind of workaround to get the cursor stay, where the graph ist clicked/tapped? (Or at least a way to use some kind of threshold for the select?)
I am using a while loop and within that I add ginput in MATLAB to capture the positions of mouse. I check every time if the returned position is within some area so I will plot some curve on the current figure. But the problem is, by using ginput, I have to press enter before the positions are returned. Is that any way to capture the mouse event such that when the current cursor hover over some points, a callback function will be triggered? Thanks.
Since you already have a figure you're using, you could set the listening property for the figure:
set(gcf,'WindowButtonMotionFcn', #mouseMoveListener);
But now you have to create a function called 'mouseMoveListener' (if you want to name it something else, change the words after the # sign to whatever name you want, and make sure the actual event function is named that too).
Within your function mouseMoveListener you can now get the mouse coordinates:
MousePos = get(mainAxis,'CurrentPoint');
Which tells the current point of the mouse with respect to the axes coordinates. From there, you can have whatever if statement check that the position is where you want it and perform whatever tasks you want based on that information.
How to find out blink cursor position in windows, from c++? In many cases I need send button click on the position of the blinking cursor, but I didn't find any important function which will take care of that.
OS win 7(64), c++
It is called "caret", cursor is the mouse pointer. You use GetCaretPos() to get its position. But the returned position is relative to the client area of the window that owns the caret. Which probably means that you need to find that window first, use GetForegroundWindow() for that. And don't send button click messages, they are posted so use PostMessage().
Avoid all of this by just using SendInput().
Note that UIPI (the user interface component of UAC) prevents you from poking stuff into a window owned by an elevated process.
GetGUIThreadInfo() is probably your best bet; pass it with idThread = 0 to get the info from the currently active thread, and then check the rcCaret member of the returned GUITHREADINFO structure. You'll then need to use ClientToScreen() with the hwndCaret value to convert client-relative coordinates to screen coordinates.
Note that this only works for apps that use the Win32 caret functions - specifically SetCaretPos(). If an app draws its own caret without using these, you may not get anything meaningful back. (Some apps, like Word, draw their own caret, but still call SetCaretPos so that accessibility aids that need to track the caret can use this technique.)
The rectangle you get back can sometimes be wider than the actual caret. When a bitmap is used for the caret, as is the case for Right-To-Left or Left-To-Right carets that have a little 'flag' attached to the top, you'll get back a rectangle that's a bit wider than the actual caret area, and may need to adjust or otherwise figure out where within this area the actual caret bar is - it may or may not be in the exact middle. Looks like for Notepad++ you should be fine, though.
I can retrieve the position of window using GetWindowRect winapi function.
It should be a function also that defines the order of windows in z-axis (which window is above and which is under), but cannot find the appropriate function.
Point me to any one?
Well, seems like EnumDesktopWindows returns windows in the Z order from the top to the bottom. So no need in any special function then (which doesn't exist perhaps).
You don't get the z order directly. You are expected to call GetWindow()passing GW_HWNDNEXT or GW_HWNDPREV to walk the z order hierarchy.
Start at one of your windows and walk until you find either the other window or your walk terminates. This then tells you the relationship between the two windows.