|
-
May 9th, 2001, 04:35 AM
#1
Thread Starter
Addicted Member
Drawing a Dash Line Problem
I need to show a red dashed line with a red arrow at each end
e.g. >- - - - - -<.
The line has to be dragged over multi controls so I was using a usercontrol by setting the MaskPicture to a >- - - - - -< bitmap. This works, but the length of the >- - - - - -< line needs to be dynamic.
I already know the maximum length the line can be, so what I was thinking of doing was storing an image of the maximum length line without the right hand arrow in an image list.
e.g. >- - - - - - - - - - - -
Then, when I need to show the line somehow trim the >- - - - - - - - - - - - line to the correct size
e.g. >- - - - -
Then somehow add the < to image to make >- - - - -< and then set the MaskPicture to the new image.
How do I do this, or is there a better way?
-
May 9th, 2001, 10:32 AM
#2
Frenzied Member
You'll be happy to know that there's a better way (and much easier too)
You can draw lines using the Windows GDI functions, and you can setup the way those lines are drawn by changing the pen that is selected into the DC you're drawing to. Assuming you've got a DC for whatever control you want to draw to, you first create a custom pen with whatever colour, style et cetera you want, using the CreatePen function to return a handle to a pen. Then you select that pen into your device context (or DC) using the SelectObject function. Now your DC is set up, you use the MoveToEx function to move the pen to where you want to start drawing your line, then use the LineTo function to draw your line to another point. You may want to swap back to the original pen, in which case you'll have to store the handle to the original pen (which is returned from the SelectObject function) in a variable somewhere. When you've finished with your pen, you must remember to select it out (using SelectObject) and delete it using the DeleteObject function, otherwise you will get a memory leak.
There are other kinds of lines, curves and polygons you can draw if you want, just check your help files.
Harry.
"From one thing, know ten thousand things."
-
May 10th, 2001, 06:24 AM
#3
Thread Starter
Addicted Member
It would be easy accept I need to draw on multiple controls, which means multiple DC's. With the usercontrol way I can move the line around like any other control over as many different controls as I like.
The problem is I don't know how to do the following:
- How do I make a 160 x 9 bitmap into a 100 x 9 bitmap without streching it.
- How do I add two bitmaps together.
e.g. <- - - - - + > to make <- - - - ->
-
May 10th, 2001, 10:30 AM
#4
Fanatic Member
Create a picture with 3 sections, left middle and right. Have a second picture with the correct width, then copy the left part, copy the middle part as much as needed (repeat it, so you can have a dynamical width), then copy the right part...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
May 11th, 2001, 02:37 AM
#5
Thread Starter
Addicted Member
How?
What API's or code do I need to use?
-
May 11th, 2001, 06:31 AM
#6
Fanatic Member
You could use BitBlt, there are a lot of tutorials on it if you don't know how it works... maybe even PaintPicture would work, although I prefer the API over VB functions, and BitBlt is most likely to be faster
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
May 11th, 2001, 07:37 AM
#7
transcendental analytic
You can use Harrys approach if you use the GetDC on the window on which the controls are placed, but when you recieve WM_PAINTs for respective controls be sure to update the line.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|