If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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).

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).

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.

Re: How to implement crosshairs (whole screen) in mdi-app?

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?

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.

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?

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.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.