bClrGrad Not working for me

bClrGrad Not working for me

Postby reinaldocrespo » Fri May 27, 2011 6:02 pm

Hi again,

I'm trying to get grading on a dialog. Below is the code I'm using, but it does nothing:
Code: Select all  Expand view
  DEFINE DIALOG oDlg RESOURCE "presentacion" TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)

   oDlg:bClrGrad = { | lInvert | If( ! lInvert,;
                                     { { 0.25, nRGB( 129, 132, 135 ), nRGB( 54, 58, 62 ) },;
                                       { 0.75, nRGB(  20,  40,  60 ), nRGB(  5, 10, 15 ) } },;
                                     { { 0.25, nRGB( 160, 173, 174 ), nRGB( 67, 112, 133 ) },;
                                       { 0.75, nRGB(  11,  66,  94 ), nRGB( 74, 134, 187 ) } } ) }
   oDlg:nClrText = { | lInvert | If( ! lInvert, nRGB( 235, 160, 86 ), nRGB( 20, 20, 20 ) ) }                        

   ACTIVATE DIALOG oDlg NOWAIT VALID ( oSelf:hide(), .F.) ON init oDlg:move(-5,-5,-10-20)

   oDlg:hide()
 


Help and ideas are greatly appreciated.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: bClrGrad Not working for me

Postby ukoenig » Fri May 27, 2011 6:06 pm

Reinaldo,

a Gradient must be defined ON INIT !!!

Code: Select all  Expand view

...
...
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( GradBrush( oDlg, { { 0.50, 14853684, 16314573 }, ;
                           { 0.50, 16314573, 14853684 } }, .T. ) )

RETURN ( NIL )

// -------------------------------

FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:oBrush:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif  

RETURN NIL
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: bClrGrad Not working for me

Postby reinaldocrespo » Fri May 27, 2011 6:53 pm

Uwe;

Thank you for helping. Since the dialog is being resized before display, the grading does not re-adjust and therefore causes an unwanted re-grading. I have built a reduced sample:
Code: Select all  Expand view

#include "fivewin.ch"

STATIC oDlg, oWnd

FUNCTION MAIN
   LOCAL oMenu
   LOCAL x := 1024
   LOCAL y := 780
   LOCAL xi := INT( x * 0.10 / 2 )
   LOCAL yi := INT( y * 0.10 / 2 )

   x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi
   
   MENU oMenu
      MenuItem "Show" ACTION Show()
      MenuItem "Hide" ACTION odlg:hide()
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
   ACTIVATE WINDOW oWnd ON INIT BuildDlg( "Sample Text", oWnd )

RETURN NIL

//-------------------------------------------------------
FUNCTION BuildDlg( cText, oOwner )

   DEFINE DIALOG oDlg ;
              OF oOwner;
        RESOURCE "SampleDlg" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240)

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()
   
   oDlg:lHelpIcon := .F.
   
   ACTIVATE DIALOG oDlg NOWAIT ;
    VALID ( oDlg:hide(), .f. ) ;
      ON INIT ( oDlg:hide(), oDlg:Center( oOwner ),;
                GradBrush( oDlg, { { 0.50, 14853684, 16314573 }, ;
                                   { 0.50, 16314573, 14853684 } }, .T. )  )

   oDlg:hide()

RETURN NIL

//-------------------------------------------------------
STATIC FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:oBrush:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif

RETURN NIL

//-------------------------------
STATIC FUNCTION Show()
LOCAL aClient := GetClientRect ( oWnd:hWnd )

      oDlg:SetSize( aClient[4] - 1, aClient[3]- 2, .T. )
        oDlg:Center( oWnd )
      oDlg:Show()
     
Return Nil


 


This is the resouce code:
Code: Select all  Expand view

SAMPLEDLG DIALOG 6, 15, 232, 58
STYLE DS_SYSMODAL |DS_3DLOOK |DS_SETFONT |DS_MODALFRAME |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_DLGFRAME |0x40000000
CAPTION "FW Dialog"
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "",1001,"BUTTON",BS_GROUPBOX |WS_CHILD |WS_VISIBLE ,7,2,217,23
  CONTROL "Ok",2,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,174,33,50,14
  CONTROL "Redefined Text",1,"STATIC",SS_CENTER |WS_CHILD |WS_GROUP |WS_VISIBLE ,9,13,201,8
END
 


The idea here is for the grading to recalculate and paint from top to bottom as one grading. Help? Again, thank you.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: bClrGrad Not working for me

Postby ukoenig » Fri May 27, 2011 7:50 pm

Reinaldo,

the Gradient-dimension is taken from the Resource,
that is the Reason that the Gradient is shown tiled.
It is not the Size, shown on Screen ( different to Resource ).
I will have a look for the problem.

Displayed Resource ( Gradient calculated from this Dimension ) :
SAMPLEDLG DIALOG 6, 15, 232, 58

Image

Screen-display :

Image

Some changes :
NO Mdi and Show-function !!!
Moving Dialog to show Window-menu !!!

Image

Code: Select all  Expand view

#include "fivewin.ch"

STATIC oDlg, oWnd

FUNCTION MAIN
LOCAL oMenu
LOCAL x := 1024
LOCAL y := 780
LOCAL xi := INT( x * 0.10 / 2 )
LOCAL yi := INT( y * 0.10 / 2 )

x  := INT( x * 0.90 ) + xi
y  := INT( y * 0.90 ) + yi
   
DEFINE WINDOW oWnd FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU BuildMenu()


ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT BuildDlg( "Sample Text", oWnd )

RETURN NIL

//----------------------------------------------------------------------------//

FUNCTION BuildMenu()
local oMenu

MENU oMenu
      MenuItem "Show" ACTION oDlg:Show()                           
      MenuItem "Hide" ACTION oDlg:Hide()
ENDMENU

return oMenu

//-------------------------------------------------------

FUNCTION BuildDlg( cText, oOwner )
LOCAL aClient := GetClientRect ( oWnd:hWnd )
LOCAL aColors := { { 0.50, 14853684, 16314573 }, { 0.50, 16314573, 14853684 } }

DEFINE DIALOG oDlg OF oOwner PIXEL ;
RESOURCE "SampleDlg" ;
TRANSPARENT ;
COLOR CLR_WHITE , RGB(240,240,240)

REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)
REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()
   
oDlg:lHelpIcon := .F.
 
ACTIVATE DIALOG oDlg NOWAIT ;
VALID ( oDlg:hide(), .f. ) ;
ON INIT ( oDlg:Move( 50, 1, aClient[4] - 1, aClient[3] - 20, .f. ), ;
            GradBrush( oDlg, aColors, .T. ) )
  
oDlg:hide()

RETURN NIL

//-------------------------------------------------------

STATIC FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:oBrush:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif

RETURN NIL
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: bClrGrad Not working for me

Postby reinaldocrespo » Sat May 28, 2011 1:10 am

Uwe;

Perhaps I should explain a little more.

1. I need the window NOT maximized.
2. Upon resize of the main window, the dialog should also resize maintaining the grading.
3. Upon move of the main window, the dialog should also move with it.

You will find this behavior on any windows app. Here the sample code again. Upon move of the main window, the dialog moves with it. Upon resize of main window, the dialog resizes. So far so good, but grading is not adjusting with new window sizes:
Code: Select all  Expand view

#include "fivewin.ch"

STATIC oDlg, oWnd

FUNCTION MAIN
   LOCAL oMenu
   LOCAL x := 1024
   LOCAL y := 780
   LOCAL xi := INT( x * 0.10 / 2 )
   LOCAL yi := INT( y * 0.10 / 2 )

   x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi
   
   MENU oMenu
      MenuItem "Show" ACTION (Resize(), oDlg:Show() )
      MenuItem "Hide" ACTION odlg:hide()
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
   ACTIVATE WINDOW oWnd ON INIT BuildDlg( "Sample Text", oWnd )

RETURN NIL

//-------------------------------------------------------
FUNCTION BuildDlg( cText, oOwner )

   DEFINE DIALOG oDlg ;
        RESOURCE "SampleDlg" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240)

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()

   oDlg:bPainted := { || GradBrush( oDlg, ;
    { { 1.0, nRGB( 75, 144, 223 ), nRGB( 41, 85, 145 ) } }, .T. ) }/**/
   /*oDlg:bPainted := { || DlgGradient( oDlg, ;
      { { 1.0, nRGB( 75, 144, 223 ), nRGB( 41, 85, 145 ) } } ) } /**/

       
    oDlg:bResized := Eval( oDlg:bPainted )

   oDlg:lHelpIcon := .F.

   ACTIVATE DIALOG oDlg NOWAIT VALID ( oDlg:hide(), .F. ) ;
      ON INIT ( oDlg:Center( oWnd ), oDlg:Hide(), oDlg:Paint() );
      ON MOVE ( oDlg:Paint() )
     
   oDlg:hide()
   
   oWnd:bResized := {|| Resize() }
   oWnd:bMoved := { || Resize() }
   
RETURN NIL

//-------------------------------------------------------
STATIC FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:oBrush:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif

RETURN NIL

//-------------------------------------------------------
STATIC FUNCTION Resize()
LOCAL aClient := GetClientRect ( oWnd:hWnd )

      oDlg:SetSize( aClient[4] - 1, aClient[3]- 2, .T. )
        oDlg:Center( oWnd )
        Eval( oDlg:bPainted )

RETURN NIL

//-------------------------------------------------------
 


The resource is the same:

Code: Select all  Expand view

SAMPLEDLG DIALOG 6, 15, 232, 58
STYLE DS_SYSMODAL |DS_3DLOOK |DS_SETFONT |DS_MODALFRAME |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_DLGFRAME |0x40000000
CAPTION "FW Dialog"
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "",1001,"BUTTON",BS_GROUPBOX |WS_CHILD |WS_VISIBLE ,7,2,217,23
  CONTROL "Ok",2,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,174,33,50,14
  CONTROL "Redefined Text",1,"STATIC",SS_CENTER |WS_CHILD |WS_GROUP |WS_VISIBLE ,9,13,201,8
END
 


You see what I mean?

I hope you can find an idea. Thank you.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: bClrGrad Not working for me

Postby Daniel Garcia-Gil » Sat May 28, 2011 4:45 am

Hello

test this way
Code: Select all  Expand view


#include "fivewin.ch"

STATIC oDlg, oWnd

FUNCTION MAIN
   LOCAL oMenu
   LOCAL x := 1024
   LOCAL y := 780
   LOCAL xi := INT( x * 0.10 / 2 )
   LOCAL yi := INT( y * 0.10 / 2 )

   x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi
   
   MENU oMenu
      MenuItem "Show" ACTION (Resize(), oDlg:Show() )
      MenuItem "Hide" ACTION odlg:hide()
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
   ACTIVATE WINDOW oWnd ON INIT BuildDlg( "Sample Text", oWnd )

RETURN NIL

//-------------------------------------------------------
FUNCTION BuildDlg( cText, oOwner )

   DEFINE DIALOG oDlg ;
        RESOURCE "SampleDlg" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240) OF oWnd

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()

    oDlg:bResized := {|| GradBrush( oDlg, ;
    { { 1.0, nRGB( 75, 144, 223 ), nRGB( 41, 85, 145 ) } }, .T. ) }

   oDlg:lHelpIcon := .F.

   ACTIVATE DIALOG oDlg NOWAIT VALID ( oDlg:hide(), .F. ) ;
      ON INIT ( Resize( oWnd:nWidth, oWnd:nHeight ), oDlg:Hide() );
     
   oDlg:hide()
   
   oWnd:bResized := {|| Resize() }
   oWnd:bMoved := { || Resize() }
   
RETURN NIL

//-------------------------------------------------------
STATIC FUNCTION GradBrush( oDlg, aColors, lPos )
   local hDC, hBmp, hBmpOld, oBrush

   oDlg:oBrush:End()

   hDC = CreateCompatibleDC( oDlg:GetDC() )
   hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
   hBmpOld = SelectObject( hDC, hBmp )
   GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
   oBrush = TBrush():New( , , , , hBmp )
   oDlg:SetBrush( oBrush )
   SelectObject( hDC, hBmpOld )
   DeleteObject( hBmp )
   oDlg:ReleaseDC()
   DeleteDC( hDC )

RETURN NIL

//-------------------------------------------------------
STATIC FUNCTION Resize()

   local aCoors := GetCoors( oWnd:hWnd )
   local nAux := 50

   oDlg:Move( aCoors[ 1 ] + nAux, aCoors[ 2 ] + 5, aCoors[ 4 ] - aCoors[ 2 ] - 10, aCoors[ 3 ] - aCoors[ 1 ] - nAux - 10)


RETURN NIL

//-------------------------------------------------------
 
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: bClrGrad Not working for me

Postby nageswaragunupudi » Sat May 28, 2011 2:36 pm

Code: Select all  Expand view
#include "fivewin.ch"

STATIC oWnd, oDlg
STATIC aGrad := { { 0.50, 14853684, 16314573 }, { 0.50, 16314573, 14853684 } }

FUNCTION MAIN

   LOCAL oMenu
   LOCAL x := 1024
   LOCAL y := 700 //780
   LOCAL xi := INT( x * 0.10 / 2 )
   LOCAL yi := INT( y * 0.10 / 2 )

   x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi

   MENU oMenu
      MenuItem "Show" ACTION (Resize(), oDlg:Show() )
      MenuItem "Hide" ACTION odlg:hide()
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
   ACTIVATE WINDOW oWnd ON INIT BuildDlg( "Sample Text ", oWnd )

RETURN NIL

//-------------------------------------------------------
FUNCTION BuildDlg( cText, oOwner )

   DEFINE DIALOG oDlg RESOURCE "SampleDlg" TRANSPARENT

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR RGB(240,240,255),RGB(240,240,255)
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "c:\\fwh\\bitmaps\\exit3.bmp" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()

   oDlg:lHelpIcon := .F.

   ACTIVATE DIALOG oDlg NOWAIT VALID ( oDlg:hide(), .F. ) ;
      ON INIT oDlg:Hide() ON PAINT DlgPaint( hDC,oDlg )

   oWnd:bResized := { || Resize() }
   oWnd:bMoved   := { || Resize() }

RETURN NIL

//-------------------------------------------------------

STATIC FUNCTION DlgPaint( hDC, oDlg )

   LOCAL hBrush, aRect := GetClientRect( oDlg:hWnd )

   hBrush   := GradientBrush( hDC, 0, 0, aRect[ 4 ] - aRect[ 2 ] + 1, aRect[ 3 ] - aRect[ 1 ] + 1, aGrad, .t. )
   FillRect( hDC, aRect, hBrush )
   DeleteObject( hBrush )

RETURN NIL

//-------------------------------------------------------

STATIC FUNCTION Resize()

   LOCAL oRect    := oWnd:GetCliRect()
   LOCAL aPoint   := ClientToScreen( oWnd:hWnd, { oRect:nTop, oRect:nLeft } )

   oDlg:Move( aPoint[ 1 ], aPoint[ 2 ], oRect:nWidth, oRect:nHeight )
   oDlg:Refresh()

RETURN NIL

//-------------------------------------------------------
 


rc file: Style changed as WS_POPUP
Code: Select all  Expand view
SAMPLEDLG DIALOG 6, 15, 232, 58 STYLE WS_POPUP
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "",1001,"BUTTON",BS_GROUPBOX |WS_CHILD |WS_VISIBLE ,7,2,217,23
  CONTROL "Ok",2,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,174,33,50,14
  CONTROL "Redefined Text",1,"STATIC",SS_CENTER |WS_CHILD |WS_GROUP |WS_VISIBLE ,9,13,201,8
END
 


Image

Dialog fits into the window. Moves and resizes along with window.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: bClrGrad Not working for me

Postby reinaldocrespo » Sun May 29, 2011 6:29 pm

Rao, Daniel;

Thank you. Your sample code help me solve it. It is now working really nice. Again, thank you very much, both of you.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 111 guests