Drawing with FWPPC

Post Reply
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Drawing with FWPPC

Post 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
Raymond Fischbach
www.mouches.org
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

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

// 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
Raymond Fischbach
www.mouches.org
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

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

// 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
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Post by Raymond Fischbach »

Hello Bill,

Many thanks, i works very well.

Best Regards,
Raymond
Raymond Fischbach
www.mouches.org
User avatar
Antonio Linares
Site Admin
Posts: 42519
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 75 times
Contact:

Post by Antonio Linares »

A ReleaseDC() method call is missing:

Code: Select all | Expand

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Post by Raymond Fischbach »

Thanks for the hint.

Regards,
Raymond
Raymond Fischbach
www.mouches.org
Post Reply