PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Drawing lines/rectangles etc. using the WM_PAINT handler  (Read 2367 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9389
  • Windows 10
    • PlanetSquires Software
Drawing lines/rectangles etc. using the WM_PAINT handler
« on: October 31, 2009, 09:25:25 PM »

You draw lines, rectangles, etc... in the WM_PAINT handler for the Form. Here is some example code to get you started. You do all kinds of fancy things by using the WM_PAINT handler.

Code: [Select]
Function FORM1_WM_PAINT ( _
                        hWndForm      As Dword _  ' handle of Form
                        ) As Long
                       
                       
   Local hDC    As Dword
   Local hPen   As Dword
   Local hBrush As Dword
   
   ' Get the DC for this form
   hDC = GetDC( hWndForm )
   
   ' Save the DC's contents so we can restore them later
   SaveDC hDC
   
   ' Create a pen to use with our rectangle. The width is 1 and
   ' uses a red color.
   hPen   = CreatePen( %PS_SOLID, 1, %Red )

   ' If we want our rectangle to have a solid background color
   ' then we create a solid brush, otherwise I just use a hollow brush.
   'hBrush = CreateSolidBrush( %Blue )
   hBrush = GetStockObject(%HOLLOW_BRUSH)
   
   ' Select the objects into the DC
   SelectObject hDC, hPen
   SelectObject hDC, hBrush
   
   ' Draw the rectangle. The rectangle uses the currently defined
   ' pen to draw the border and brush to fill the inside. We could
   ' use RoundRect api if we want a rectangle with rounded corners.
   Rectangle hDC, 20, 20, 200, 200
     
   ' To draw a line, simple use the MoveTo and LineTo api.
   MoveTo hDC, 20, 225
   LineTo hDC, 500, 225
   
   ' Restore the contents of our saved DC
   RestoreDC hDC, -1
   
   ' Delete the objects that we created
   DeleteObject hPen
   DeleteObject hBrush
   
   ' Release the DC.
   ReleaseDC hWndForm, hDC                     

End Function
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Robert Eaton

  • Junior Member
  • **
  • Posts: 126
Re: Drawing lines/rectangles etc. using the WM_PAINT handler
« Reply #1 on: November 06, 2009, 12:30:33 PM »

Can you tell me how this could be used to draw inside a control such as a picture or fireImage control? My attempts so far have failed :(

Thanks,
Bob
Logged

Gerald Sutherland

  • Little Newbie
  • *
  • Posts: 1
Re: Drawing lines/rectangles etc. using the WM_PAINT handler
« Reply #2 on: November 14, 2009, 01:09:24 AM »

I'd be interested in learning how do draw graphics on a control as well.
Logged

Robert Eaton

  • Junior Member
  • **
  • Posts: 126
Re: Drawing lines/rectangles etc. using the WM_PAINT handler
« Reply #3 on: November 14, 2009, 12:19:28 PM »

I was able to get the above example to work by putting it in the "custom" message handler of the control. I also had to turn off the two redraw options in the ClassStyles options for the main form.

But you should probably look at this thread:

http://www.planetsquires.com/protect/forum/index.php?topic=2020.0

I'm in the process of working my way though that one ;D
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9389
  • Windows 10
    • PlanetSquires Software
Re: Drawing lines/rectangles etc. using the WM_PAINT handler
« Reply #4 on: November 14, 2009, 12:33:30 PM »

I'm in the process of working my way though that one ;D

..and we're all chomping at the bit to see how you are progressing! Any problems just ask. Post your code if you want a second set of eyes to look it over for any potential problem areas.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Robert Eaton

  • Junior Member
  • **
  • Posts: 126
Re: Drawing lines/rectangles etc. using the WM_PAINT handler
« Reply #5 on: November 14, 2009, 01:33:38 PM »

What I've done so far is to take the Filelines control, rename all of the commands, and then per your instructions add it to a project, position it, and send commands to it ;D (It had me scratching my head at first but finally got it all working!)

So next is to start writing my control. (Pesky stuff like broken clothes washers getting in the way :'()
Logged