Painting a triangle with GDI

Just starting out? Need help? Post your questions and find answers here.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Painting a triangle with GDI

Post by PHP »

Hi,

i found this code on the board but it doesn't work anymore (no error, no result on the screen):

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  ProcedureReturn Polygon_(hdc, @x1, 3)
EndProcedure

OpenWindow(0, 0, 0, 320, 240, "Triangle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Repeat
  hdc = StartDrawing( WindowOutput(0) )
  If hdc
    FrontColor(RGB(255, 0, 0))
    Triangle(hdc,10, 10, 10, 100, 100, 10)
    ;     Polygon_(hdc, @x1, 3)
   
    StopDrawing()
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
Has the GDI changed in the meantime or something?

Thanks!
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Painting a triangle with GDI

Post by infratec »

Works here: win10 x64, PB 5.72 x86
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Painting a triangle with GDI

Post by infratec »

Maybe this is 'safer'

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  
  Protected Dim Poly.l(5)
  
  Poly(0) = x1
  Poly(1) = y1
  Poly(2) = x2
  Poly(3) = y2
  Poly(4) = x3
  Poly(5) = y3
  
  ProcedureReturn Polygon_(hdc, @Poly(0), 3)
EndProcedure
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Painting a triangle with GDI

Post by Fred »

PHP wrote:Hi,

i found this code on the board but it doesn't work anymore (no error, no result on the screen):

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  ProcedureReturn Polygon_(hdc, @x1, 3)
EndProcedure

OpenWindow(0, 0, 0, 320, 240, "Triangle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Repeat
  hdc = StartDrawing( WindowOutput(0) )
  If hdc
    FrontColor(RGB(255, 0, 0))
    Triangle(hdc,10, 10, 10, 100, 100, 10)
    ;     Polygon_(hdc, @x1, 3)
   
    StopDrawing()
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
Has the GDI changed in the meantime or something?

Thanks!
You shouldn't use WindowOutput(), it's an old command and still here for compatibility, but it can be erased by OS repainting etc. Better try with a CanvasOutput() instead.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Painting a triangle with GDI

Post by ozzie »

Fred wrote:You shouldn't use WindowOutput(), it's an old command and still here for compatibility, but it can be erased by OS repainting etc. Better try with a CanvasOutput() instead.
Seems like I've got some extra work to do! I've just run a search on my program and have found 12 instances of StartDrawing(WindowOutput(...)).
Post Reply