Form Back Color

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Form Back Color

Post by esgici »

Hi

Code: Select all

  MsgBox( VALTYPE( GetProperty( "frmTest", "BACKCOLOR" ) ), "Frm BackColor" )  
This line return U !

Where I'm wrong :(

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Form Back Color

Post by esgici »

Why GetProperty() ?

Because

Code: Select all

aWinBackColor := frmGraps.BackColor

MsgBox( VALTYPE( frmGraps.BackColor ) )

etc
all are syntax error :?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Form Back Color

Post by esgici »

... And result of

Code: Select all

nFormNo := GetFormIndex( "frmTest" )
_HMG_SYSDATA [ 79 , nFormNo ] 
is : { -1, -1, -1 } :cry:

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Form Back Color

Post by Rathinagiri »

I think background color is normally determined by windows itself by default. Only when we change the background color it may be initialized.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Form Back Color

Post by esgici »

Hi Rathi

Thanks to your interest.
rathinagiri wrote:... when we change the background color it may be initialized.
Sadly no :(

Please look at my ErasLine.prg.

Back colour property of form explicitly initialized in the DEFINE WINDOW statement (line 35 ).

Please add

Code: Select all

      @ 100, 230 BUTTON btnTest CAPTION "&Test"  ACTION TestBColor()  
line into DEFINE WINDOW statement and

Code: Select all

PROCEDURE TestBColor()

* aFormBColor :=  frmEraseLine.BackColor  // Syntax Error
* aFormBColor :=  GetProperty( "frmEraseLine", "BACKCOLOR" ) 
* MsgBox( ValType( aFormBColor ) )             // U
* SetProperty( "frmEraseLine", "BACKCOLOR", { 0, 0, 0 } ) // NOP
* frmEraseLine.BackColor := { 0, 0, 0 }  // Syntax Error
  
nFormNo := GetFormIndex( "frmEraseLine" )
_HMG_SYSDATA [ 79 , nFormNo ] := { 0, 0, 0 }  
aFormBColor :=  _HMG_SYSDATA [ 79 , nFormNo ]

MsgBox ( LTRIM( STR( aFormBColor[ 1 ] ) ) + ", " + ;  
         LTRIM( STR( aFormBColor[ 2 ] ) ) + ", " + ;  
         LTRIM( STR( aFormBColor[ 3 ] ) ) )
         
RETURN // TestBColor()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
procedure into .prg.

I think this job may not be such difficult :cry:

Best regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Form Back Color

Post by mol »

Some times ago, I've tried to change form color, but without success.
You can define backcolor only while form definition...

Besides, you can use

Code: Select all

hb_valtoexp(aFormBColor)
to display whole array...

Regards, Marek
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Form Back Color

Post by Pablo César »

I got it in HMG !!! But of course with C codes of P.Chornyj:

Code: Select all

#include <hmg.ch>

/* Hatch Styles */
#define HS_HORIZONTAL       0       /* ----- */
#define HS_VERTICAL         1       /* ||||| */
#define HS_FDIAGONAL        2       /* \\\\\ */
#define HS_BDIAGONAL        3       /* ///// */
#define HS_CROSS            4       /* +++++ */
#define HS_DIAGCROSS        5       /* xxxxx */

Function Main
DEFINE WINDOW Form_1 AT 249 , 292 WIDTH 550 HEIGHT 350 TITLE "Test of Change BackColor of main form" ICON NIL MAIN 

    DEFINE BUTTON Button_1
        ROW    60
        COL    240
        WIDTH  100
        HEIGHT 28
        ACTION ChangeBackGround("Form_1",GetColor({236, 233, 216}))
        CAPTION "Change color"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .T.
    END BUTTON
	
	DEFINE BUTTON Button_2
        ROW    120
        COL    240
        WIDTH  100
        HEIGHT 28
        ACTION ChangeBackGround("Form_1","Wall.bmp")
        CAPTION "Bitmap: Wall"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .T.
    END BUTTON
	
	DEFINE BUTTON Button_3
        ROW    180
        COL    240
        WIDTH  100
        HEIGHT 28
        ACTION ChangeBackGround("Form_1",{0,200,0},2)
        CAPTION "Hashed"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .T.
    END BUTTON
	
	DEFINE LABEL Label_1
        ROW    290
        COL    80
        WIDTH  410
        HEIGHT 30
        VALUE "Our thanks to P.Chornyj, Grigory Filatov and Roberto Lopez"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .T.
        FONTITALIC .T.
        CENTERALIGN .T. 
    END LABEL

END WINDOW
Form_1.Center
Form_1.Activate
Return Nil

Function ChangeBackGround(cWindow,xToChange,hatch)
Local i := GetFormIndex ( cWindow )
Local hWnd, oldBrush, Brush

hWnd := GetFormHandle (cWindow)

IF IsWindowHandler( hWnd )
   If ValType(xToChange)="A"
      If hatch=Nil
	     Brush := CreateSolidBrush( xToChange[1], xToChange[2], xToChange[3] )
	  Else
		 Brush := CreateHatchBrush( hatch, RGB( xToChange[1], xToChange[2], xToChange[3] ) )
	  Endif
   Else		 
	  Brush := CreatePatternBrush( xToChange )
   Endif
   oldBrush := SetWindowBrush( hWnd, Brush )
   DeleteObject( oldBrush )
ENDIF
erasewindow(cWindow)
If ValType(xToChange)="A"
   SetProperty(cWindow,"Label_1","BackColor",xToChange)
Endif
Return Nil

/*
 * C-level
*/
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

HB_FUNC ( ISWINDOWHANDLER )
{
  hb_retl( IsWindow( (HWND) hb_parnl(1) ) );
}

HB_FUNC ( GETWINDOWBRUSH )
{
  hb_retnl( GetClassLong( (HWND) hb_parnl(1), GCL_HBRBACKGROUND ) );
}

HB_FUNC ( SETWINDOWBRUSH )
{
  hb_retnl( SetClassLong( (HWND) hb_parnl(1), GCL_HBRBACKGROUND, (LONG) hb_parnl(2) ) );
}

HB_FUNC ( CREATEHATCHBRUSH )
{
  hb_retnl( (LONG) CreateHatchBrush( hb_parnl(1), (COLORREF) hb_parnl(2) ) );
}

/*
    Windows 95: Creating brushes from bitmaps or DIBs larger than 8x8 pixels is not supported. 
    If a larger bitmap is specified, only a portion of the bitmap is used.
*/
HB_FUNC ( CREATEPATTERNBRUSH )
{
  HBITMAP himage;

  himage = (HBITMAP) LoadImage( GetModuleHandle(NULL), hb_parc(1), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );
  if (himage == NULL) 
  {
    himage = (HBITMAP) LoadImage( 0, hb_parc(1), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );
  }

  hb_retnl( (LONG) CreatePatternBrush( himage ) );
}

#pragma ENDDUMP
Codes referance was extracted from C:\MiniGUI\SAMPLES\BASIC\WindowBackground, thanks Grigory Filatov !

Files to compile this example are in attached compressed file.
Attachments
Teste63.rar
(775.28 KiB) Downloaded 353 times
Last edited by Pablo César on Sun Nov 18, 2012 2:06 am, edited 1 time in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
danielmaximiliano
Posts: 2763
Joined: Fri Apr 09, 2010 4:53 pm
DBs Used: DBF
Location: Argentina
Contact:

Re: Form Back Color

Post by danielmaximiliano »

I did not understand whether the need is to change the background of the window, but
It works. but gives a compilation error

Code: Select all

/*
 * MiniGUI Window BackColor Demo
 * (c) 2005 Grigory Filatov
*/

#include "minigui.ch"

Static nColor  := 1, ;
	   aColors := { { 255 , 255 , 0 } , { 255 , 128 , 192 } , { 255 ,   0 ,   0}, ;
		            { 255 , 0 , 255 } , { 255 , 128 , 64  } , {   0 , 255 ,   0}, ;
		            { 128 , 0 , 128 } , { 255 , 255 , 255 } , { 128 , 128 , 128}, ;
		            {   0 , 0 , 255 } , { 192 , 192 , 192 } }

Procedure Main

	SET MULTIPLE OFF
        DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 480 ;
		TITLE 'Set Window BackColor Demo (Contributed by Grigory Filatov)' ;
		MAIN ;
		BACKCOLOR WHITE

		DEFINE TIMER Timer_1 INTERVAL 2000 ACTION SetBackColor()
    END WINDOW

	CENTER WINDOW Form_1
       ACTIVATE WINDOW Form_1

Return

Procedure SetBackColor()
        nColor++
       if nColor > Len(aColors)
	  nColor := 1
      endif
 ThisWindow.BackColor := aColors[nColor]

Return
Administrador Cwindowssystem32cmd.exe - call  chmg.3.0.46build.bat demo.jpg
Administrador Cwindowssystem32cmd.exe - call chmg.3.0.46build.bat demo.jpg (127.69 KiB) Viewed 3940 times
Set Window BackColor Demo (Contributed by Grigory Filatov)_2012-11-17_21-00-37.jpg
Set Window BackColor Demo (Contributed by Grigory Filatov)_2012-11-17_21-00-37.jpg (14.99 KiB) Viewed 3940 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Form Back Color

Post by esgici »

Pablo César wrote:I got it in HMG !!!
Thanks Pablo :)

saudação
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Form Back Color

Post by Pablo César »

Hola Daniel, ese otro ejemplo no funciona com BackColor ni con Form ni This en HMG, de esa forma. Adaptei desta forma el mismo ejemplo:

Code: Select all

/*
 * MiniGUI Window BackColor Demo
 * (c) 2005 Grigory Filatov
*/

#include <hmg.ch>

Static nColor  := 1, ;
      aColors := { { 255 , 255 , 0 } , { 255 , 128 , 192 } , { 255 ,   0 ,   0 }, ;
                   { 255 , 0 , 255 } , { 255 , 128 , 64  } , {   0 , 255 ,   0 }, ;
                   { 128 , 0 , 128 } , { 255 , 255 , 255 } , { 128 , 128 , 128 }, ;
                   {   0 , 0 , 255 } , { 192 , 192 , 192 } }
Function Main()
SET MULTIPLE OFF
DEFINE WINDOW Form_1 ;
	AT 0,0 ;
    WIDTH 640 ;
    HEIGHT 480 ;
    TITLE 'Set Window BackColor Demo (Contributed by Grigory Filatov)' ;
    MAIN ;
    BACKCOLOR WHITE

    DEFINE TIMER Timer_1 INTERVAL 2000 ACTION ChangeBackGround("Form_1",SetBackColor())
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function SetBackColor()
nColor++
if nColor > Len(aColors)
   nColor := 1
endif
// ThisWindow.BackColor := aColors[nColor]
Return aColors[nColor]

Function ChangeBackGround(cWindow,aColor)
Local i := GetFormIndex ( cWindow )
Local hWnd, oldBrush, Brush

hWnd := GetFormHandle (cWindow)

IF IsWindowHandler( hWnd )
   Brush := CreateSolidBrush( aColor[1], aColor[2], aColor[3] )
   oldBrush := SetWindowBrush( hWnd, Brush )
   DeleteObject( oldBrush )
ENDIF
erasewindow(cWindow)
Return Nil

/*
 * C-level
*/
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

HB_FUNC ( ISWINDOWHANDLER )
{
  hb_retl( IsWindow( (HWND) hb_parnl(1) ) );
}

HB_FUNC ( SETWINDOWBRUSH )
{
  hb_retnl( SetClassLong( (HWND) hb_parnl(1), GCL_HBRBACKGROUND, (LONG) hb_parnl(2) ) );
}

#pragma ENDDUMP
De todas formas precisa el código C para lograr el resultado en HMG.

-- In English

Hi Daniel, this other example does not work in HMG trying to change "BackColor" thru "Form" or even with "This". So a fixed up the same example for HMG:

Anyway will be necessary to use C code to work in HMG.
esgici wrote:
Pablo César wrote:I got it in HMG !!!
Thanks Pablo :)

saudação
You are welcome, my friend !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply