Page 1 of 1

Drawing with FWPPC

Posted: Tue Jun 06, 2006 6:58 pm
by Raymond Fischbach
Hi All,

Is it possible to draw on a window with FWPPC?
Can I use the LineTo() function for example?

Anybody has a sample?

Many thanks,

Raymond

Posted: Wed Jun 07, 2006 4:43 pm
by Raymond Fischbach
Hello,

I have made a small program to test the drawing.
I am facing a problem.
When I start the program, I see the drawing flashing on the screen.
Then the screen becomes completely white with the "Exit" button shown.
Here follows the small code :

Code: Select all

// Draw on a window
#include "Fwce.ch"
#include "Winapi.ch"

FUNCTION Main()
LOCAL oWnd
LOCAL hDC
LOCAL hPen

DEFINE WINDOW oWnd TITLE "DESSIN "

hDC := oWnd:GetDC()
hPen := CreatePen(PS_SOLID,1,RGB(0,0,0))

@ 14.4, 1.0 BUTTON "&Exit"     SIZE 60, 35 ;
               ACTION (oWnd:End())

oWnd:aControls[1]:SetFocus()

MoveTo(hDC,100,100)
LineTo(hDC,150,150,hPen)
LineTo(hDC,050,050,hPen)
LineTo(hDC,200,200,hPen)

ACTIVATE WINDOW oWnd

RETURN nil
Anybody has an idea of what I am missing ?

Thanks in advance,
Raymond

Posted: Wed Jun 07, 2006 6:45 pm
by Bill Simmeth
Raymond,
When the window is painted, the drawing is lost. So, you need to load a function with your drawing instructions and place this in the PAINT callback. I have modified your example below.

Code: Select all

// Draw on a window
#include "Fwce.ch"
#include "Winapi.ch"

FUNCTION Main()
LOCAL oWnd

DEFINE WINDOW oWnd TITLE "DESSIN "

@ 14.4, 1.0 BUTTON "&Exit"     SIZE 60, 35 ;
               ACTION (oWnd:End())

oWnd:aControls[1]:SetFocus()

ACTIVATE WINDOW oWnd ON PAINT MyPainting( oWnd )

RETURN nil

*******************************************************************************
FUNCTION MyPainting( oWnd )
*******************************************************************************
LOCAL hDC
LOCAL hPen
   hDC := oWnd:GetDC()
   hPen := CreatePen(PS_SOLID,1,RGB(0,0,0))

   MoveTo(hDC,100,100)
   LineTo(hDC,150,150,hPen)
   LineTo(hDC,150,050,hPen)
   LineTo(hDC,200,050,hPen)

RETURN Nil

Posted: Wed Jun 07, 2006 7:19 pm
by Raymond Fischbach
Hello Bill,

Many thanks, i works very well.

Best Regards,
Raymond

Posted: Wed Jun 07, 2006 9:36 pm
by Antonio Linares
A ReleaseDC() method call is missing:

Code: Select all

LOCAL hDC 
LOCAL hPen 
   hDC := oWnd:GetDC() 
   hPen := CreatePen(PS_SOLID,1,RGB(0,0,0)) 

   MoveTo(hDC,100,100) 
   LineTo(hDC,150,150,hPen) 
   LineTo(hDC,150,050,hPen) 
   LineTo(hDC,200,050,hPen) 
   
   oWnd:ReleaseDC()
return nil

Posted: Thu Jun 08, 2006 8:10 am
by Raymond Fischbach
Thanks for the hint.

Regards,
Raymond