FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour colored square blink
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
colored square blink
Posted: Wed Oct 02, 2024 07:25 AM
How to display a red colored square over an image at x,y coordinates ( measure on mm) and the square should blink
Can have a small sample please ?

I create this



Problems
1) the square is not flashing
2) if I change record it does not delete the previous one

Any help please

the test
Code (fw): Select all Collapse
oBrw:bChange  := { || ShowBox(oBrw,oCoupon) }


FUNCTION ShowBox(oBrw, oImage)
    LOCAL hDC, nX, nY, nSize, hBrush
    LOCAL nImgX, nImgY



    // Coordinate del quadrato in mm (distanze specificate)
    nX := VAL(oBrw:aArrayData[oBrw:nArrayAt][2])
    nY := VAL(oBrw:aArrayData[oBrw:nArrayAt][3])
    nSize := 2 // dimensione del quadrato

    // Dimensioni e posizione dell'immagine
    nImgX := 10  // Posizione X dell'immagine
    nImgY := 0   // Posizione Y dell'immagine

    // Converti le misure da mm a pixel (96 DPI)
    nX := nX * 96 / 25.4
    nY := nY * 96 / 25.4
    nSize := nSize * 96 / 25.4
    nImgX := nImgX * 96 / 25.4
    nImgY := nImgY * 96 / 25.4

    // Calcola le coordinate finali tenendo conto della posizione dell'immagine
    nX := nImgX + nX
    nY := nImgY + nY

    hDC := oImage:GetDC()

    // Cancella il quadrato precedente disegnando uno sfondo bianco
    hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Bianco
    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Disegna il nuovo quadrato lampeggiante
    IF MOD(GetTickCount(), 1000) < 500
        hBrush := CreateSolidBrush(RGB(255, 0, 0)) // Rosso
    ELSE
        hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Trasparente (o sfondo)
    ENDIF

    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Rilascia il contesto e pulisci
    oImage:ReleaseDC(hDC)
    DeleteObject(hBrush)

    RETURN nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: colored square blink
Posted: Wed Oct 02, 2024 10:06 AM
this realease the box blink right but not if I change record it does not delete the previous one




oBrw:bChange := { || BuildTimer( oBrw, oCoupon, oDlg) }
Code (fw): Select all Collapse
FUNCTION ShowBox(oBrw, oImage)
    LOCAL hDC, nX, nY, nSize, hBrush
    LOCAL nImgX, nImgY



    // Coordinate del quadrato in mm (distanze specificate)
    nX := VAL(oBrw:aArrayData[oBrw:nArrayAt][2])
    nY := VAL(oBrw:aArrayData[oBrw:nArrayAt][3])
    nSize := 2 // dimensione del quadrato

    // Dimensioni e posizione dell'immagine
    nImgX := 10  // Posizione X dell'immagine
    nImgY := 0   // Posizione Y dell'immagine

    // Converti le misure da mm a pixel (96 DPI)
    nX := nX * 96 / 25.4
    nY := nY * 96 / 25.4
    nSize := nSize * 96 / 25.4
    nImgX := nImgX * 96 / 25.4
    nImgY := nImgY * 96 / 25.4

    // Calcola le coordinate finali tenendo conto della posizione dell'immagine
    nX := nImgX + nX
    nY := nImgY + nY

    hDC := oImage:GetDC()

    // Cancella il quadrato precedente disegnando uno sfondo bianco
    hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Bianco
    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Disegna il nuovo quadrato lampeggiante
    IF MOD(GetTickCount(), 1000) < 500
        hBrush := CreateSolidBrush(RGB(255, 0, 0)) // Rosso
    ELSE
        hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Trasparente (o sfondo)
    ENDIF

    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Rilascia il contesto e pulisci
    oImage:ReleaseDC(hDC)
    DeleteObject(hBrush)

    RETURN nil


    function BuildTimer( oBrw, oImage, oDlg)
       local nTime := 0
       local oTmr

       DEFINE TIMER oTmr OF oDlg ;
          ACTION ( nTime++, If( nTime > 14, ShowBox(oBrw, oImage) ,)) INTERVAL 5

       ACTIVATE TIMER oTmr


    return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: colored square blink
Posted: Wed Oct 02, 2024 10:15 AM
Now Run ok

I discovered that the coordinates are reversed




it just flashes a little too much, how do I reduce the flashing speed?
Code (fw): Select all Collapse
   function BuildTimer( oBrw, oImage, oDlg)
       local nTime := 0
       local oTmr
       loca nInterval := 10

       DEFINE TIMER oTmr OF oDlg ;
          ACTION ( nTime++,oImage:refresh(), If( nTime > 14, ShowBox(oBrw, oImage) ,)) INTERVAL nInterval

       ACTIVATE TIMER oTmr


    return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion