How to implement crosshairs (whole screen) in mdi-app?
Hello,
I am working on a solution for the above problem. Without success by now.
To draw it within OnMouseMove with XOR-operation in not a good solution.
One problem: OnMouseMove is not called if the mouse moves to outside the CView-window.
But in this case the crosshairs should be deleted.
Second: working with XOR will not be good because we need a defined state (visible/not visible).
Any ideas for the implementation?
thx.
Ralf
Re: How to implement crosshairs (whole screen) in mdi-app?
Your question isn't clear to me. Are you talking about a mouse cursor? If so, handle WM_SETCURSOR. If not, please explain your question more clearly.
Re: How to implement crosshairs (whole screen) in mdi-app?
it is not a mouse cursor. This would be easy.
It is a cross over the whole screen behaving like a mouse cursor.
It makes working with CAD-software easier.
Anyway, one can also say:
it is a owner draw mouse cursor over the whole screen.
Re: How to implement crosshairs (whole screen) in mdi-app?
you can make your own mouse pointers and tell windows to use that mousepounter when the mouse is over a particular window. that's the normal way to do such things.
Like GCDEF said. See WM_SETCURSOR
Re: How to implement crosshairs (whole screen) in mdi-app?
yes, I konw.
But in his case the mouse pointer size is limited to 32x32 (not whole screen).
Re: How to implement crosshairs (whole screen) in mdi-app?
Quote:
Originally Posted by
Ralf Schneider
yes, I konw.
But in his case the mouse pointer size is limited to 32x32 (not whole screen).
You can do it, but it will be a bit tricky. What I would do is to draw directly onto the desktop, which is obtainable by GetDC(NULL).
You draw two lines corresponding to the crosshair using XOR mode. When the mouse has been moved, you erase whe previously drawn crosshair by a second cross drawn in XOR mode and then after that you draw a new crosshair at the new position.
It will not be a perfect solution because if any of the background windows repaint themselves the XOR erase will fail and traces of the crosshair will be leftover.
Also see: http://stackoverflow.com/questions/1...ng-the-gdi-api
Regards
Re: How to implement crosshairs (whole screen) in mdi-app?
Quote:
Originally Posted by
Ralf Schneider
Anyway, one can also say:
it is a owner draw mouse cursor over the whole screen.
Does it really have to be drawn outside of your main frame window?
Re: How to implement crosshairs (whole screen) in mdi-app?
Quote:
Originally Posted by
zerver
You can do it, but it will be a bit tricky. What I would do is to draw directly onto the desktop, which is obtainable by GetDC(NULL).
Drawing on top of the desktop won't reliably work if you're using windows desktop composition modes (pretty much enabled for everyone these days). ANd it'll behave strangely on multimonitor setups.
if it really needs to be full screen, then the recommended way is to create a layered transparent window over the current monitor area. You'll need to change the window over to whatever monitor the mouse is on. And do all your painting in the layered window.
See WS_EX_LAYERED style, in combination with UpdateLayeredWindow()
1) This is tricky stuff.
2) Expect this to slow down screen drawing significantly (although less so than trying to paint on the composed desktop). So any high fps apps (video playback, games, ...) will be significanly affected.
Re: How to implement crosshairs (whole screen) in mdi-app?
Hello,
I do not mean full screen, but all over the client view.
Sorry.
Re: How to implement crosshairs (whole screen) in mdi-app?
If you do it inside the document area only, the method I suggested should work reliably:
1. Each time the document repaints itself, draw a cross at the current mouse position.
2. Each time the mouse is moved (WM_MOUSEMOVE), erase the existing cross and draw a new one.
All drawing should be done in XOR mode.
Re: How to implement crosshairs (whole screen) in mdi-app?
Quote:
Originally Posted by
Ralf Schneider
One problem: OnMouseMove is not called if the mouse moves to outside the CView-window.
But in this case the crosshairs should be deleted.
I can suggest two ways to handle that.
1. Register for WM_MOUSELEAVE message.
2. Capture the mouse by using SetCapture(); release the capture when mouse leaves your window. Note: you would have to process WM_CAPTURECHANGED message to handle lost capture.
Quote:
Originally Posted by
Ralf Schneider
Second: working with XOR will not be good because we need a defined state (visible/not visible).
Unfortunately, the XOR method only works on a high-contrast colors (where some of the RGB values are close to 0 or to 255); it does nothing on medium-gray and similar colors.
The most attractive aspect of this method is the ease of restoring what was drawn before by one more XOR. But this method breaks if anybody is drawing to that window outside of your control.
I would prefer to draw black (or red?) hairline and erase it by invalidating and updating the window under it. This can be done in two steps: horizontal and vertical lines separately, to avoid repainting of the entire window.
Re: How to implement crosshairs (whole screen) in mdi-app?
Quote:
This can be done in two steps: horizontal and vertical lines separately, to avoid repainting of the entire window.
This, of course, assumes that the program handles the WM_PAINT message properly and only re-paints the requested rectangle! I've seem numerous examples of programs coded by 'lazy' programmers who just repaint the entire client area when a WM_PAINT message is received irrespective of the provided rectangle for which painting is requested.:eek: