Thread: dragging

  1. #1
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685

    dragging

    I'm trying to make it possible for the user to drag the mouse and create a box (like a paint program does) and I'm sure the api has something that handles this. I thought it was DragDetect() but i'm sure that isn't it. Can anyone help?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Um, probably, but I don't know. You could always use the MoveToEx()/LineTo() functions though.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No that isn't exactly what I'm asking. I'm a little confused on how to actually know when a drag event is occuring. I was using my own little hack that would base dragging off of a WM_LBUTTONDOWN and a WM_LBUTTONUP but it was not very accurate and it would easily break. What is the best option for determining dragging?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by master5001
    No that isn't exactly what I'm asking. I'm a little confused on how to actually know when a drag event is occuring. I was using my own little hack that would base dragging off of a WM_LBUTTONDOWN and a WM_LBUTTONUP but it was not very accurate and it would easily break. What is the best option for determining dragging?
    It's effective to just to track the mouse messages and redraw as a result....

    Create static RECT to hold the position of the rect at anytime....

    Track the WM_LBUTTONDOWN to target when the user clicks........if the PtInRect() returns TRUE, you are in draw mode!

    Track the WM_MOUSEMOVE messages as above and with each, call a repaint to move the pos of the rect....

    On a WM_LBUTTONUP, you will stop tracking and redrawing, maybe call an extra repaint to finish things off.....

    You can add extra complexities at your will - sizing the rect...clipping to the client area....etc

    <EDIT> dont need to convert point between Client & Screen....my mistake</EDIT>
    Last edited by Fordy; 07-27-2002 at 04:25 AM.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Thanks Fordy, I'm pretty much going to do that. Although I still remain a bit confused as to what DragDetect() is used for. The docs are not much help either. From my tests of the function I determined that it returns true if a drag takes place, however getting the SM_CXDRAG and SM_CYDRAG from the GetSystemMetrics() doesn't seem to be accurate as to what where I dragged to.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I wrote this using the LineTo() and MoveTo() functions. As you can see, they work fine.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    That looks good (much smoother than WM_LBUTTON* and WM_MOUSEMOVE). I'll have to do it your way instead. Thanks.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Actually, the whole process is controlled by the WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE messages.


    Here's the class I created to do all the work:
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah, I was playing around with it and found that there is no easy way around using all the mouse tracking messages. I like your encrypted source code Then again, since I got it working I don't really need someone elses source. Besides where is the fun in life if someone else gives you all the answers?

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Oh I know, but I have no idea where you're at with Windows and so I decided just to show you how it might be accomplished. Because when I first started programming Windows, that would have taken me weeks to code, considering how cryptic the API is. Had I been shown more practical ways to achieve certain results before my own eyes, I would've lost a lot less sleep, and been an overall happier person, that's all
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The way I look at it is if I want a specific example of how to do something you will see code in my post or an attachment that contains code. Otherwise I'm cool with people saying things like "use BitBlt()" or even more vague "use winsock." Your code seems to work about the same way as some of my first attempts. My original problem, as it turns out, was I was using rects and FrameRect() isn't smart enough to draw a rect that moves in a negative direction. LineTo() seems to work fine.

  12. #12
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well just because I post it doesn't mean you have to read it!
    Besides, the implementation was incomplete, don't you think? How did you solve the speed of update problem?

    It's funny you said that, though. I'm the same way. I generally want theoretical answers unless I'm really stuck. Then again, just re-read your the first post
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  13. #13
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Sebastiani, if you read my answer to one of your posts you should have got the updating flicker under control. In this situation it is best to update the entire client area. It doesn't make a big difference in draw speed. My problems are stemming from my proprietary image handling. I don't use HBITMAPs in my current project and SetPixel() is pretty slow. The rectangles don't hurt my update times as much as redrawing the image does.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  2. Dragging file onto program
    By Enahs in forum Windows Programming
    Replies: 2
    Last Post: 01-03-2006, 04:45 PM
  3. novel method of dragging
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-05-2005, 06:41 PM
  4. dragging files to client area
    By HybridM in forum Windows Programming
    Replies: 5
    Last Post: 10-31-2003, 12:11 AM
  5. Dragging
    By subdene in forum Windows Programming
    Replies: 0
    Last Post: 12-29-2002, 03:19 PM