I wish draw a line when the mouse is on get control
a Vert line from top of image to sx eye
a Horiz line from sx of image to sx eye
perhaps when I converte cm to pixel make error
the test
- Code: Select all Expand view
#include "Fivewin.ch"
#include "Constant.ch"
STATIC oTmr, lMove, nLastGet
Function test()
local oDlg, oFont, oBold, oCoupon
local nBottom := 34
local nRight := 111
local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
local nHeight := nBottom * DLG_CHARPIX_H
local cTicket := "c:\work\fwh\bitmaps\olga1.jpg"
local nDistanzaX := 4.2, nDistanzaY := 2.9
local aGet := array(22)
local nRow:=10,nCol:= 10
local nInterlinea:= 20
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
oTmr := NIL
lMove := .F.
nLastGet := 0
DEFINE DIALOG oDlg SIZE nWidth, nHeight ;
PIXEL TRUEPIXEL FONT oFont ;
TITLE "Draw a line"
@ 0, 0 XIMAGE oCoupon SIZE 250, 300 OF oDlg SOURCE cTicket NOBORDER
oCoupon:bRClicked := { || NIL }
oCoupon:nUserControl := 0
@ 10, 260 FOLDER oFld SIZE oDlg:nWidth-270, oDlg:nBottom-50 OF oDlg PIXEL ;
PROMPT "Distance"
@ nRow,ncol SAY "Distanza X" of oFld:adialogs[1] SIZE 55, 12 PIXEL FONT oFont
nRow-=2
@ nRow,ncol+75 GET aGet[1] VAR nDistanzaX of oFld:adialogs[1] PIXEL FONT oFont SIZE 40,12 RIGHT
nRow+=nInterlinea
@ nRow,ncol SAY "Distanza Y" of oFld:adialogs[1] SIZE 55, 12 PIXEL FONT oFont
nRow-=2
@ nRow,ncol+75 GET aGet[2] VAR nDistanzaY of oFld:adialogs[1] PIXEL FONT oFont SIZE 40,12 RIGHT
aGet[1]:bMMoved := { |nRow, nCol, nKeyFlags| MyOverGet(nDistanzaX,nDistanzaY, oDlg, oCoupon, 1) }
aGet[2]:bMMoved := { |nRow, nCol, nKeyFlags| MyOverGet(nDistanzaX,nDistanzaY, oDlg, oCoupon, 2) }
ACTIVATE DIALOG oDlg CENTER
RETURN NIL
STATIC FUNCTION MyOverDlg(lPass)
IF .NOT. lMove
lMove := .T.
IF oTmr <> NIL
oTmr:End()
oTmr := NIL
ENDIF
lMove := .F.
ENDIF
RETURN NIL
STATIC FUNCTION MyOverGet(nDistanzaX, nDistanzaY, oDlg, oImage, nGet)
IF .NOT. lMove
lMove := .T.
IF nLastGet <> nGet
nLastGet := nGet
IF oTmr <> NIL
oTmr:End()
ENDIF
BuildTimer_Get(oImage, oDlg, nDistanzaX, nDistanzaY, nGet)
ENDIF
lMove := .F.
ENDIF
RETURN NIL
//--------------------------------------------------------------//
// Disegna una linea lampeggiante per la distanza X e distanza Y
FUNCTION BuildTimer_Get(oImage, oDlg, nDistanzaX, nDistanzaY, nGet)
local nTime := 0
local nInterval := 10
DEFINE TIMER oTmr OF oDlg ;
ACTION ( nTime++, oImage:refresh(), If(nTime > 10, ShowLine(oDlg, oImage, nDistanzaX, nDistanzaY, nGet),) ) ;
INTERVAL nInterval
ACTIVATE TIMER oTmr
RETURN NIL
FUNCTION ShowLine(oDlg, oImage, nDistanzaX, nDistanzaY, nGet)
LOCAL hDC, hBrush, hPen
LOCAL nImgX, nImgY
LOCAL nStartX, nStartY, nEndX, nEndY
LOCAL nSquareSize := 10 // Impostiamo la dimensione del quadrato (in pixel)
LOCAL nDistanzaX_px, nDistanzaY_px // Variabili per la conversione in pixel
// Calcola la posizione effettiva dell'immagine nel dialogo
nImgY := oImage:nLeft // Posizione X dell'immagine nel dialogo
nImgX := oImage:nTop // Posizione Y dell'immagine nel dialogo
// Converti le misure da mm a pixel (96 DPI)
nDistanzaX_px := nDistanzaX * 96 / 25.4 // Conversione della distanza X in pixel
nDistanzaY_px := nDistanzaY * 96 / 25.4 // Conversione della distanza Y in pixel
IF nGet == 1 // Linea Orizzontale
nStartX := nImgX + nDistanzaX_px
nStartY := nImgY + nDistanzaY_px
nEndX := nStartX + 20 // Lunghezza della linea orizzontale (in pixel)
nEndY := nStartY
ELSE // Linea Verticale
nStartX := nImgX + nDistanzaX_px
nStartY := nImgY + nDistanzaY_px
nEndX := nStartX
nEndY := nStartY + 60
ENDIF
hDC := oImage:GetDC()
hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Bianco
SelectObject(hDC, hBrush)
hPen := CreatePen(PS_SOLID, 3, RGB(243, 101, 108)) // 3 è lo spessore della linea
SelectObject(hDC, hPen)
IF MOD(GetTickCount(), 1000) < 500
MoveToEx(hDC, nStartX, nStartY, ) // NULL
LineTo(hDC, nEndX, nEndY)
ENDIF
// Rilascia il contesto e pulisci
oImage:ReleaseDC(hDC)
DeleteObject(hBrush)
DeleteObject(hPen) //
RETURN NIL