How to implement crosshairs (whole screen) in mdi-app?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

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

  1. #1
    Join Date
    Jul 2001
    Posts
    293

    Question 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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    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.

  3. #3
    Join Date
    Jul 2001
    Posts
    293

    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.

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,845

    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

  5. #5
    Join Date
    Jul 2001
    Posts
    293

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

  6. #6
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,598

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

    Quote Originally Posted by Ralf Schneider View Post
    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
    Nobody cares how it works as long as it works

  7. #7
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

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

    Quote Originally Posted by Ralf Schneider View Post
    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?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,845

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

    Quote Originally Posted by zerver View Post
    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.

  9. #9
    Join Date
    Jul 2001
    Posts
    293

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

    Hello,

    I do not mean full screen, but all over the client view.
    Sorry.

  10. #10
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,598

    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.
    Nobody cares how it works as long as it works

  11. #11
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

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

    Quote Originally Posted by Ralf Schneider View Post
    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 View Post
    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.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  12. #12
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,330

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center