Results 1 to 7 of 7

Thread: Drawing a Dash Line Problem

  1. #1

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Question 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?

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  3. #3

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Question

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


  4. #4
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    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)

  5. #5

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    How?
    What API's or code do I need to use?

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    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)

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width