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?
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?
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; }
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....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?
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.
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.
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; }
That looks good (much smoother than WM_LBUTTON* and WM_MOUSEMOVE). I'll have to do it your way instead. Thanks.
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; }
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?
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; }
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.
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; }
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.