CHANGE BACKCOLOR OF WINDOWS PANEL ???

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by andyglezl »

Hola
No puedo cambiar el BACKCOLOR de una Ventana tipo PANEL
¿Es un ERROR, o que estoy haciendo mal?
Alguien sabe ?
Gracias.
*--------------------------------------------------------------------------

Hello
I cannot change the BACKCOLOR of a PANEL Window
Is it a MISTAKE, or what am I doing wrong?
Someone knows ?
Thank you.

Code: Select all


#include "hmg.ch"

STATIC aColFdo1 := { 000, 023, 052 }, aColFdo2 := { 112 , 128 , 144 }, aColFdo3 := { 140 , 160 , 180 }, aColFte := WHITE

FUNCTION Main()

    DEFINE WINDOW Form_9 AT 0,0 WIDTH 800 HEIGHT 660 TITLE "PRB" CHILD NOSIZE NOMAXIMIZE ; 
			NOMINIMIZE BACKCOLOR aColFdo1
			
        DEFINE WINDOW W_TipWin8 ROW 38 COL -003 WIDTH 806 HEIGHT 580 VIRTUALWIDTH 807 VIRTUALHEIGHT 2400 ;
                WINDOWTYPE PANEL BACKCOLOR aColFdo2 
			
			DEFINE CONTEXT MENU OF W_TipWin8
				MENUITEM "Color" ACTION CambiaColor( ThisWindow.Name )
			END MENU
        END WINDOW
		
    END WINDOW
    CENTER WINDOW   Form_9
    ACTIVATE WINDOW Form_9
RETURN Nil

FUNCTION CambiaColor( cWinName )
	aColFdo2 := GetColor( { 0 , 0 , 0 }, NIL, .T.)
	SetProperty( cWinName, "BACKCOLOR", aColFdo2 )
	BT_ClientAreaInvalidateAll( cWinName, .T. )
RETURN Nil


Quizá por esto ?
*------------------
Maybe for this?




- BackColor (D)

(D) Available at definition only
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by dragancesu »

In this case you can re-define windows like ( release, change color, define )

Code: Select all

 if IsWindowActive( FmdPrev )
       DoMethod( 'FmdPrev', "RELEASE" )
   endif
   
   DEFINE WINDOW FmdPrev ;
      AT 20, desk_pozx ;
      WIDTH 1000 ; 
      HEIGHT 800 ;
      TITLE 'Preview Form' ;
      PANEL ;
      BACKCOLOR aColFdo2 
      ...
      
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by mol »

Dragan, your method causes to define all control belong to panel window after it's redefinition
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by dragancesu »

You right, but WINDOW is specific control and many properties is only-defined, no change. How change? Recreate, I think
definewindow.jpg
definewindow.jpg (92.87 KiB) Viewed 3247 times
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by mol »

I can change color of main window only during OnInit procedure.

Code: Select all

PROCEDURE ChangeGradient
	param cForm, aColor1, aColor2
        LOCAL Width  := BT_ClientAreaWidth  (cForm)
        LOCAL Height := BT_ClientAreaHeight (cForm)
        LOCAL hDC, BTstruct

   hDC = BT_CreateDC (cForm, BT_HDC_INVALIDCLIENTAREA, @BTstruct)
   BT_DrawGradientFillVertical (hDC, 0, 0, Width, Height, aColor1, aColor2)
   BT_DeleteDC (BTstruct)
RETURN
I've tried this solution for various controls, but it works fine only for window.
After few modifications, I've reached gradient on BUTTON, but it returns to oryginal color after lost focus.

Maybe create background label - it's background color can be changed without problems?
User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by AUGE_OHR »

hi,

you can try Windows Standars

Code: Select all

SetBkColor( hDC, CLR_BLACK )
but this work only if you have no visual Style ... so perhaps you only don't "see" Background Color ...

you can disable Visual Style for just that Control (here ::hButton)

Code: Select all

// disable visual Style
   @UxTheme:SetWindowTheme(::hButton,CHR(0),CHR(0))
https://docs.microsoft.com/en-us/window ... indowtheme

---

when using visual Style "painting" ist different

here a sample from my native WC_Button

Code: Select all

METHOD DXE_BUTTON:Xbp_wndproc(hWnd,nMsg,wp,lp,ctx)
   ...
   ELSEIF nMsg == WM_CTLCOLORBTN


METHOD DXE_BUTTON:Check4Background()
LOCAL hRet := ::BrushSysColor

   DO CASE
      CASE ::ButtonClass = BS_RADIOBUTTON
      CASE ::ButtonClass = BS_3STATE
      CASE ::ButtonClass = BS_CHECKBOX

   OTHERWISE

      IF ::nMMove = 1 .AND. ::lHover = .T.
         IF ::lHilite = .T.
            hRet := ::BrushHiBackColor
         ELSE
            hRet := ::BrushSysColor
         ENDIF
          
         // more ...
      ELSE
         hRet := ::BrushSysColor
      ENDIF
   ENDCASE
RETURN hRet
A window receives this message through its WindowProc function.

#define CTLCOLOR_MSGBOX 0
#define CTLCOLOR_EDIT 1
#define CTLCOLOR_LISTBOX 2
#define CTLCOLOR_BTN 3
#define CTLCOLOR_DLG 4
#define CTLCOLOR_SCROLLBAR 5
#define CTLCOLOR_STATIC 6
#define CTLCOLOR_MAX 7
here you find more to read

WM_CTLCOLORSTATIC message
https://docs.microsoft.com/en-us/window ... olorstatic

WM_CTLCOLORBTN message
https://docs.microsoft.com/en-us/window ... tlcolorbtn

WM_CTLCOLOREDIT message
https://docs.microsoft.com/en-us/window ... lcoloredit
! Note : it have EM_SETBKGNDCOLOR

---

Question : does harbour / HMG support Owner Draw :?:
https://docs.microsoft.com/en-us/window ... rols-intro

Ownerdraw is the "older" Way to paint what you want.
Listview and other also support Customdraw (NM_CUSTOMDRAW)

that is the Way to get Darkmode (if not using CCS ) in a App
have fun
Jimmy
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by andyglezl »

Lo encontré !!!
Gracias al Foro y los que colaboran en el.
*----------------------
I found it !!!
Thanks to the Forum and those who collaborate on it.


https://www.hmgforum.com/viewtopic.php? ... tov#p22870

Code: Select all


#include "hmg.ch"

STATIC aColFdo1 := { 000, 023, 052 }, aColFdo2 := { 112 , 128 , 144 }, aColFdo3 := { 140 , 160 , 180 }, aColFte := WHITE

FUNCTION Main()

    DEFINE WINDOW Form_9 AT 0,0 WIDTH 800 HEIGHT 660 TITLE "PRB" CHILD NOSIZE NOMAXIMIZE ; 
			NOMINIMIZE BACKCOLOR aColFdo1
			
        DEFINE WINDOW W_TipWin8 ROW 38 COL -003 WIDTH 806 HEIGHT 580 VIRTUALWIDTH 807 VIRTUALHEIGHT 2400 ;
                WINDOWTYPE PANEL BACKCOLOR aColFdo2 
			
			DEFINE CONTEXT MENU OF W_TipWin8
				MENUITEM "Color" ACTION ChangeBackGround( ThisWindow.Name, { 0 , 200 , 0 }, NIL )
			END MENU
        END WINDOW

    END WINDOW
    CENTER WINDOW   Form_9
    ACTIVATE WINDOW Form_9
RETURN Nil

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

	xToChange := GetColor( { 0 , 0 , 0 }, NIL, .T.)

	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 )
		BT_ClientAreaInvalidateAll( cWindow, .T. )
	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

Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by mol »

Amazing!
But, when I used gradient, sometimes it was lost after switching computer to sleep mode and return.
Try to test it
Last edited by mol on Fri Nov 01, 2019 1:43 pm, edited 1 time in total.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by andyglezl »

Hola mol

Hice la prueba de Suspender, Minimizar, Maximizar, "sacar" de la pantalla y en todas,
continua con el color asignado.
*--------------------------------------------------------------------------------------------------------
I did the Suspend, Minimize, Maximize, "take out" screen test and in all,
Continue with the assigned color.
Andrés González López
Desde Guadalajara, Jalisco. México.
MICROVOLUTION
Posts: 146
Joined: Sat May 30, 2015 5:15 am

Re: CHANGE BACKCOLOR OF WINDOWS PANEL ???

Post by MICROVOLUTION »

Pessoal boa noite!
tenho o interesse de mudar a cor BAKCOLOR e COLOR dos objetos em 2 situações:
- TEMA NORMAL (.F.)
- TEMA MODO ESCURO (.T.)
Então, estou tentando assim:

Code: Select all

DEFINE WINDOW F_UTIL_MENU_HMG AT 5, 5 WIDTH 450 HEIGHT 385 TITLE win_ansitoOem("Menu Utilitários") MODAL BACKCOLOR iif (lTEMA,"DarkGrey","Orange")
EU EXPLICO:
as "DarkGrey" e "Orange" estão definidas no início do .PRG assim:

Code: Select all

#define "DarkGrey", "169 169 169"
#define "OrangeRed4", "139 37 0"
Então, seja como for, não está pegando cor alguma, está tudo vindo como COR PRETA ou nenhuma, aparecendo PRETA.
o comando BACKCOLOR se usar assim:

Code: Select all

BACKCOLOR iif (lTEMA,"DarkGrey","Orange")
não pega a cor. Mas, se usar como abaixo, apenas uma cor, aí funciona:

Code: Select all

BACKCOLOR "DarkGrey"
Eu sei que eu poderia criar uma condição tipo assim:

Code: Select all

if lTEMA
   BkColor := "darkgrey"
else
   BKColor := "orange"
endif
DEFINE WINDOW F_UTIL_MENU_HMG AT 5, 5 WIDTH 450 HEIGHT 385 TITLE win_ansitoOem("Menu Utilitários") MODAL BACKCOLOR bkColor
aí funcionaria, mas, tomará um enorme tempo para modificar o código inteiro. preciso de algo mais prático usando o IIF() ou o IF()
Alguém tem sugestão?
Post Reply