Restore override cursor not for entire application - c++

I have a large application with many widgets and windows.
At some moment I restore the cursor for entire application.
I need to keep it "customised" (as it was) for one frame.
I set it for the frame to be "customised" again, but it still restores for 1 millisecond and it is noticeable.
So the states of my cursor are: "Customised" - "Normal" - "Customised".
How can I skip changing cursor for one(current) frame? But restore it for all other windows (so it is normal again)?

Restore override cursor for all application, but set cursor to your frame.
Use setCursor() method.
http://qt-project.org/doc/qt-4.8/qwidget.html#cursor-prop
As documentation said about setOverrideCursor():
This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.
http://qt-project.org/doc/qt-4.8/qapplication.html#setOverrideCursor
So you can't restore cursor for all widgets instead of one, you should use setCursor() method.

Related

How can I ignore the mouse cursor in the screenshot when I use a DXGI?

I am working on DXGI screenshot.
I know that AcquireNextFrame returns DXGI_ERROR_WAIT_TIMEOUT if the content doesn't change.
However, even if there is only a change by the mouse cursor, it is considered changes.
So I want to ignore the changes from the mouse cursor.
I tried ShowCursor(FALSE), but it is not worked for the thread(window) that I didn't make.
Can I disable the cursor for the attached process? or How can I ignore the changes from the mouse cursor in DXGI?
(My goal is reducing the screenshot overhead when it captured, and I am using https://github.com/pgurenko/DXGICaptureSample for the test.)

Getting and setting cursor position before the system set the cursor position?

I'm trying to get and set the cursor position before the system(Windows) update the cursor position or somehow set a limit to where the cursor can move.
Tried GetCursorPos(), It execute too late.
Tried WH_MOUSE_LL hook, It slowed down the cursor movement (basically introduced massive lags), and I couldn't change the mouse position..
Call ClipCursor inside your low-level mouse hook. This is rather evil because the mouse is a shared resource.
A nice application only calls ClipCursor when it is the foreground application.
WH_MOUSE is more effective (WH_MOUSE_LL may significantly slow down your computer) but hook programs must be placed in DLL.
This allows hook processes to be loaded and run in each process.
On the other hand, the WH_MOUSE_LL process must switch back to the original process each time to run outside the process. This is a very slow operation.

MFC GUI custom control: how to draw cursor updates in response to mouse moves?

I have a custom Windows control subclassed from CButton (no idea why that was selected--this is 17-year-old code; no semblance of button functionality is present).
Its DrawItem( LPDRAWITEMSTRUCT pdis ) method is called by CButton::OnChildNotify in response to WM_DRAWITEM. It renders its scene with the DC CDC::FromHandle( pdis->hDC ).
The mouse event method OnMouseMove() calculates the new cursor position and calls RedrawWindow( NULL, NULL, RDW_INVALIDATE ). A cursor that follows the mouse duly appears at the new mouse position. It works fine, but it's slow. In fact, only the previous and new cursor cells need be redrawn (if that) yet the graphic updates start to lag as the entire scene is rendered many times.
I thought in my OnMouseMove() method, instead of repainting the entire scene, could just paint the cells in question. It already has the exact X and Y coordinates of the cells and pointers to their data. I thought CPaintDC(this) would provide a DC that allowed this, but it doesn't paint. (Doesn't crash either, which is a rare joy.)
My hazy recollection is that the "optimal" way to do this would be to invalidate just the areas of the two cells, and the DrawItem() method would eventually be told these areas were invalidated, and rather than totally repainting it could just work out from the coordinates which cells they were (not an easy operation btw) and repaint them, and that would streamline not only this cursor problem but also ensure only a few cells be painted were the partially-obscured control partially revealed. But time pressure doesn't allow and the use cases don't seem to call for this to be optimized.
So the question is: is there some nice way for OnMouseMove() to re-render a single control immediately, and if so with what DC? (For instance can I cache the DC that I've received in DrawItem() via FromHandle()?
Right now the only idea I have is to have an object member pointing to a single cell to be redrawn, to call RedrawWindow() with this RDW_UPDATENOW flag, and have DrawItem(), if that flag be set, do just that one item. That would result in DrawItem() getting a DC that presumably would work in the way it always has. Seems like a real hack though, is there a better way?
In a Windows application, it is customary to perform all rendering in response to a WM_PAINT (or WM_NCPAINT) message. Code that needs to trigger a repaint marks part or all of window's client area as dirty, by calling InvalidateRect (and friends). The system is optimized for this approach, coalescing multiple requests into a single update region, and subsequently issuing a WM_PAINT message, when there is no more important work to do (like handling input).
This works reliably, and is usually easier to implement than spreading the rendering across several places. It is, however, perfectly legal to deviate from this, and perform rendering anywhere in your code. While WM_PAINT messages can still arrive at any time, it is desirable to have the out-of-band rendering produce identical visual results as the WM_PAINT handler would, to prevent visual artifacts.
All rendering goes through an abstraction called a device context (DC). When handling a WM_PAINT message in an MFC application, a suitable DC can be obtained by constructing a CPaintDC instance. When rendering anywhere else you cannot use a CPaintDC, but need to use a CClientDC instead (or a CWindowDC, to render the non-client area as well). In general, rendering code need not know, which type of DC it is rendering to, and can usually be reused without change.

Windows - SDL_PumpEvents resets to system cursor

I'm using engine which uses SDL 1.2.5. I can't change SDL version or not use this engine. I need custom mouse cursor. I loaded cur file properly and used the SetCursor method but every time I call SDL_PumpEvents my custom cursor is replaced by SDL's default black one. I could turn off system cursor and draw it manually but that way cursor is delayed and it's noticeable. I'm programming a game so any cursor delays are unwelcome. Is there any way to tell SDL to not changing cursor? Or to lock the SetCursor method?
You could place the SetCursor function in your gameloop so it sets the cursor after the events get handled

Clearing mouseclicks buffer in openGL

I need to clear any mouse clicks which has happened before the end of an animation.Only mouse clicks afterwards have to be considered.
I tried enabling my mouse function after the animation,but any clicks that happened during the animation was considered.
To my understanding there is a buffer where mouseclicks are stored and during any mouse callback , it takes the co-ordinates and any other info of the first click stored in that buffer.so i need to know how to clear this.
I used fflush(stdin) but it doesnt clear keyboard or the mouse buffer.
Am using windowsxp and programming in visualsudio2008 in c language.i also use glut.h
i also use glut.h
Then you can't. If you're doing an animation, it's up to you to process (or choose not to process) any messages.
You should not be animating something by looping within your display method. Instead, you should set up a timer callback or something that will call glutPostRedisplay that will constantly call your drawing method. During this time, you should ignore any messages if you don't want to process them.