Page 1 of 1

Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 7:58 am
by Silvio.Falconi
Is it possible to transform a Tsay or Tget control when it is disabled and create a rectangle with the dimensions of the control and fill it with a custom color or brush?

sample

Image

I tried with

Code: Select all  Expand view

#include "fivewin.ch"

Function sample()
   local oDlg,oFont
   local nHt      := Int( ScreenHeight() * 0.2 )
   local nWd      := Int( ScreenWidth() * 0.2 )
   local oChk
   local oGet,cGet:= space(100)
   local oSay
   local ncolor1 := RGB(245,245,235)
   local ncolor2 := RGB(250,250,245)
   local lNormal

DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -14
 DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL;
       RESIZABLE   TiTle "test" COLOR CLR_BLACK, RGB( 245,245,235)  ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX, WS_THICKFRAME )


@ 10,10 CheckBox oChk Var lNormal  Prompt "check" SIZE 100,20 of oDlg ;
       on change ( If(lNormal,(MakeBox(oGet,oDlg),  oGet:enable()),;
                              (MakeBox(oGet,oDlg) , oGet:disable())),;
                               oGet:refresh() )

   @ 62, 10 SAY oSay PROMPT  "Test Get" SIZE 100,25  PIXEL OF oDlg  TRANSPARENT  FONT oFont
   @ 80, 10 GET oGet VAR cGet SIZE 100,24 PIXEL OF oDlg

ACTIVATE DIALOG oDlg CENTERED  
return nil

Function MakeBox(oControl,oDlgEdit)
   local oBox
   local aRect       := GetClientRect(oControl:hWnd )
   local hDC := oControl:GetDC()

    local  nOldMode := SetBkMode( hDC, 1 )
    local hBru := TBrush():New( "BDIAGONAL",RGB(195,195,185) )
    local  hOldBrush := SelectObject( hDC, hBru )

      FillRect( hDC,{aRect[1] , aRect[2] ,aRect[4] , aRect[3]  }, hBru )

     SelectObject( hDC, hOldBrush )
     SetBkMode( hDC, nOldMode )
     DeleteObject( hBru )
     oControl:ReleaseDC()
   RETURN NIL


 

but not work

Re: Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 8:37 am
by Antonio Linares
Dear Silvio,

Must the rectangle be painted above the control as per your sample ?

Where are you calling your code from ?

Re: Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 8:41 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

Must the rectangle be painted above the control as per your sample ?

Where are you calling your code from ?


yes the rectangle must be painted over the control
in the image example I use a btnbmp and it run on only on btnbmp

for the test I added the code above

Re: Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 10:04 am
by Antonio Linares
If you want to paint on the dialog then you must use the hDC of the dialog, don't use the hDC of the control

Re: Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 10:53 am
by Silvio.Falconi
Antonio Linares wrote:If you want to paint on the dialog then you must use the hDC of the dialog, don't use the hDC of the control


Code: Select all  Expand view
Function MakeBox(oControl,oDlgEdit)
   local oBox
   local aRect := GetClientRect(oControl:hWnd )
   local hDC :=oDlgEdit:GetDC()

    local  nOldMode := SetBkMode( hDC, 1 )
    local hBru := TBrush():New( "BDIAGONAL",RGB(195,195,185) )
    local  hOldBrush := SelectObject( hDC, hBru )

    FillRect( hDC,{aRect[1] , aRect[2] ,aRect[4] , aRect[3]  }, hBru )

     SelectObject( hDC, hOldBrush )
     SetBkMode( hDC, nOldMode )
     DeleteObject( hBru )
     oDlgEdit:ReleaseDC()
   RETURN NIL


but not work

Re: Tget /tsay disable/enable

PostPosted: Thu Nov 09, 2023 11:54 am
by karinha
Dera Silvio, mira \samples\KARINHA.PRG si ayuda.

Regards, saludos.