Page 1 of 2

Error in modifying the color of the main menu

Posted: Sun Apr 22, 2012 7:37 pm
by jairpinho
I'm not getting in hmg change the color of the menu following example

Code: Select all

#include <hmg.ch>

Function Main

        Load Window Main
        Main.Center
        Main.Activate

Return



Func CMenu()
 Local hMenu    := _GetMenuId(GetFormHandle("MAIN"))
 Local aColor   := {255,255,255}
 Local lSubMenu := .F.
 _ColorMenu(GetFormHandle("MAIN"),aColor, lSubMenu)
Return Nil




#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"
#include "winreg.h"
#include "tchar.h"

HB_FUNC( _GETMENUID)
{
 hb_retnl((LONG)GetMenu((HWND)hb_parnl(1)));
}

HB_FUNC ( _COLORMENU )
{
HMENU iMenu;
MENUINFO iMenuInfo ;
COLORREF lColor = {255,255,255};
BOOL lSubMenu = hb_parl(3);


iMenu = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize = sizeof(MENUINFO);



iMenuInfo.hbrBack = CreateSolidBrush(lColor);


SetMenuInfo(iMenu, &iMenuInfo);

if (lSubMenu)
 {
   iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS ;
 }
else
 {
   iMenuInfo.fMask    = MIM_BACKGROUND;
 }



SetMenuInfo(iMenu, &iMenuInfo);


}



HB_FUNC ( _COLORSUBMENU )
{
HMENU      iMenu;
MENUINFO   iMenuInfo ;
iMenu              = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize   = sizeof(MENUINFO);
iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
iMenuInfo.hbrBack  = CreateSolidBrush(RGB(hb_parni(2,1),hb_parni(2,2),hb_parni(2,3)));
SetMenuInfo(iMenu, &iMenuInfo);
DrawMenuBar((HWND) hb_parnl(1));
}


#pragma ENDDUMP


error build.log

hbmk2: Harbour: Compilando m¢dulos...
Harbour 3.0.0 (Rev. 16951)
Copyright (c) 1999-2011, http://harbour-project.org/
hbmk2: Compilando...
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg: In function 'HB_FUN__COLORMENU':
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:42:1: warning: excess elements in scalar initializer
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:42:1: warning: (near initialization for 'lColor')
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:42:1: warning: excess elements in scalar initializer
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:42:1: warning: (near initialization for 'lColor')
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:59:25: error: 'MIM_BACKGROUND' undeclared (first use in this function)
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:59:25: note: each undeclared identifier is reported only once for each function it appears in
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:59:42: error: 'MIM_APPLYTOSUBMENUS' undeclared (first use in this function)
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg: In function 'HB_FUN__COLORSUBMENU':
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:82:22: error: 'MIM_BACKGROUND' undeclared (first use in this function)
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:82:39: error: 'MIM_APPLYTOSUBMENUS' undeclared (first use in this function)
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:83:1: error: too many arguments to function 'hb_parni'
C:/HMG3.0.38/harbour/include/hbapi.h:637:31: note: declared here
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:83:1: error: too many arguments to function 'hb_parni'
C:/HMG3.0.38/harbour/include/hbapi.h:637:31: note: declared here
K:\@Prog-Xbase\HMG-3038\Projetos\HMGFORUM\Menucolor\main.prg:83:1: error: too many arguments to function 'hb_parni'
C:/HMG3.0.38/harbour/include/hbapi.h:637:31: note: declared here
hbmk2: Erro: Executando compilador C/C++. 1
gcc.exe -c -O3 -march=i586 -mtune=pentiumpro -fomit-frame-pointer -W -Wall -pipe -IC:/HMG3.0.38/harbour/include -I../../.. -IC:/HMG3.0.38/include ../../../.hbmk/win/mingw/main.c
[u]Moderator Notes[/u] (Pablo César) wrote:Topic moved from Forum en Español.

Re: Error in modifying the color of the main menu

Posted: Fri Apr 27, 2012 4:32 am
by danielmaximiliano
Ola Jair :
MenuColor só existe em MiniGUI, olhar para o novo exemplo
Espero que ajude.
C:\MiniGUI\SAMPLES\Advanced\MenuEx\demo.exe
Greenshot_2012-04-27_01-12-23.jpg
Greenshot_2012-04-27_01-12-23.jpg (105.73 KiB) Viewed 11853 times
Function GetMenuColors() está em
C:\MiniGUI\SOURCE\c_menu.c

IsExtendedMenuStyleActive() no i_menu.ch

Code: Select all

#translate IsExtendedMenuStyleActive () => _NewMenuStyle ()
_NewMenuStyle () No C:\MiniGUI\SOURCE\c_menu.c

Code: Select all

HB_FUNC( _NEWMENUSTYLE )
{
   if( HB_ISLOG(1) )
      newStyle = hb_parl(1);
   hb_retl( newStyle );
}

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 1:32 am
by Carlos Britos
jairpinho wrote:I'm not getting in hmg change the color of the menu following example
Hi, try this, it's working for me.

Code: Select all

/*-----------------------------------------------------------------*/

#define MIM_BACKGROUND              0x00000002
#define MIM_APPLYTOSUBMENUS         0x80000000

/*-----------------------------------------------------------------*/

HB_FUNC ( MENU_BACKCOLOR )
{
   PHB_ITEM pSelf = hb_param( 0, HB_IT_OBJECT );
   HMENU hMenu = (HMENU) ObjGetNL( pSelf, "NHANDLEMENU" );
   HWND hPadre = (HWND)ObjGetNL( ObjGetObject( pSelf, "OPADRE" ), "HANDLE" );
   MENUINFO   iMenuInfo ;
   LONG       nColor ;

   // si es un solo param es el color
   if( HB_ISNIL(2) )
   {
      nColor = (LONG) hb_parnl(1) ;
   }
   // si son 2 params el priemro es el numero del submenu, el segundo es el color
   else
   {
      hMenu = GetSubMenu( hMenu, hb_parni(1) -1 );
      nColor = (LONG) hb_parnl(2) ;
   }

   GetMenuInfo( hMenu, &iMenuInfo );
   iMenuInfo.cbSize   = sizeof(MENUINFO);
   iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
   iMenuInfo.hbrBack  = CreateSolidBrush( nColor );
   SetMenuInfo( hMenu, &iMenuInfo );
   DrawMenuBar( (HWND) hPadre );
}

/*-----------------------------------------------------------------

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 2:19 pm
by Pablo César
Carlos Britos, when I compile in HMG your code C is presenting errors:

undefined reference to ObjGetNL and ObjGetObject

Probably functions are missing...

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 2:28 pm
by danielmaximiliano
Pablo César wrote:Carlos Britos, when I compile in HMG your code C is presenting errors:

undefined reference to ObjGetNL and ObjGetObject

Probably functions are missing...
Ola Carlos:
você pode postar um exemplo, muitos ajudá-los.

Hola Carlos :
puede Ud publicar un ejemplo , a muchos les serviria.

Hi Carlos:
can you post an example, many would help them.

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 4:51 pm
by Carlos Britos
Pablo César wrote:Carlos Britos, when I compile in HMG your code C is presenting errors:

undefined reference to ObjGetNL and ObjGetObject

Probably functions are missing...
Hi.
Sorry, my fault, the above code is part of a class.
The below code compile ok with hmgee and I think is the same for hmg.

Code: Select all

#include "minigui.ch"

Function main()

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 200 ;
		TITLE 'Menu Test' ;
		MAIN

		DEFINE MAIN MENU

			POPUP 'File'

				ITEM 'Open' 		ACTION MsgInfo ('File:Open') IMAGE 'Check.Bmp'
				ITEM 'Save' 		ACTION MsgInfo ('File:Save') IMAGE 'Free.Bmp' DISABLED
				ITEM 'Print' 		ACTION MsgInfo ('File:Print') IMAGE 'Info.Bmp'
				ITEM 'Save As...' 	ACTION MsgInfo ('File:Save As') DISABLED
				ITEM 'HMG Version' 	ACTION MsgInfo (MiniGuiVersion())
				SEPARATOR
				ITEM 'Exit' 		ACTION Form_1.Release IMAGE 'Exit.Bmp'

			END POPUP

			POPUP 'Test'

				ITEM 'Item 1' 		ACTION MsgInfo ('Item 1')  name xxx
				ITEM 'Item 2' 		ACTION MsgInfo ('Item 2')

				POPUP 'Item 3' name test
					ITEM 'Item 3.1' 		ACTION MsgInfo ('Item 3.1') DISABLED
					ITEM 'Item 3.2' 		ACTION MsgInfo ('Item 3.2')

					POPUP 'Item 3.3'
						ITEM 'Item 3.3.1' 		ACTION MsgInfo ('Item 3.3.1')
						ITEM 'Item 3.3.2' 		ACTION MsgInfo ('Item 3.3.2')

						POPUP 'Item 3.3.3'

							ITEM 'Item 3.3.3.1' 		ACTION MsgInfo ('Item 3.3.3.1')
							ITEM 'Item 3.3.3.2' 		ACTION MsgInfo ('Item 3.3.3.2')
							ITEM 'Item 3.3.3.3' 		ACTION MsgInfo ('Item 3.3.3.3') DISABLED
							ITEM 'Item 3.3.3.4' 		ACTION MsgInfo ('Item 3.3.3.4') DISABLED
							ITEM 'Item 3.3.3.5' 		ACTION MsgInfo ('Item 3.3.3.5')
							ITEM 'Item 3.3.3.6' 		ACTION MsgInfo ('Item 3.3.3.6')

						END POPUP

						ITEM 'Item 3.3.4' 		ACTION MsgInfo ('Item 3.3.4') DISABLED

					END POPUP

				END POPUP

				ITEM 'Item 4' 		ACTION MsgInfo ('Item 4') DISABLED

			END POPUP

			POPUP 'Help'

				ITEM 'About' 		ACTION MsgInfo ('Help:ABout')

			END POPUP

		END MENU

		DEFINE CONTEXT MENU
			ITEM 'Item 1' 		ACTION MsgInfo ('Item 1')
			ITEM 'Item 2' 		ACTION MsgInfo ('Item 2') DISABLED
			SEPARATOR
			ITEM 'Item 3' 		ACTION MsgInfo ('Item 3')
		END MENU

		ON KEY ESCAPE ACTION ThisWindow.Release

	END WINDOW


  MENU_BACKCOLOR( GetFormHandle("Form_1"),{255,0,0}  )
  MENU_BACKCOLOR( GetFormHandle("Form_1"), 1 ,{0,255,255}  )
  MENU_BACKCOLOR( GetFormHandle("Form_1"), 2 ,{255,255,0}  )
  MENU_BACKCOLOR( GetFormHandle("Form_1"), 3 ,{255,0,255}  )

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return Nil

/*-----------------------------------------------------------------*/

#pragma BEGINDUMP

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

HB_FUNC ( MENU_BACKCOLOR )
{
   MENUINFO   iMenuInfo ;
   LONG       nColor ;
   HMENU      hMenu = GetMenu((HWND) hb_parnl(1)); ;

   // si son 2 params el segundo es el color
   // two params. 1 = handle form, 2 = array color
   if( HB_ISNIL(3) )
   {
      nColor = (LONG) RGB(hb_parvni(2,1),hb_parvni(2,2),hb_parvni(2,3)) ;
   }
   // si son 3 params el segundo es el numero del submenu, el tercero es el color
   // three params. 1 = handle form, 2 = index position of subMenu, 3 = array color
   else
   {
      hMenu = GetSubMenu( hMenu, hb_parni(2) -1 );
      nColor = (LONG) RGB(hb_parvni(3,1),hb_parvni(3,2),hb_parvni(3,3)) ;
   }

   GetMenuInfo( (HMENU) hMenu, &iMenuInfo );
   iMenuInfo.cbSize   = sizeof(MENUINFO);
   iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
   iMenuInfo.hbrBack  = CreateSolidBrush( nColor );
   SetMenuInfo( hMenu, &iMenuInfo );
   DrawMenuBar((HWND) hb_parnl(1));
}


#pragma ENDDUMP

/*-----------------------------------------------------------------*/

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 4:54 pm
by danielmaximiliano
Excelente Carlos:

Re: Error in modifying the color of the main menu

Posted: Sat Apr 28, 2012 5:18 pm
by Carlos Britos
danielmaximiliano wrote:Excelente Carlos:
falta la definicion dentro del BEGIN SEQUENCE
de :

#define MIM_BACKGROUND 0x00000002
#define MIM_APPLYTOSUBMENUS 0x80000000

y para compilar con hmg habria que sacar DISABLED del menu.
No puedo en este momento compilarlo con hmg como para probarlo.
----

Is missing the pragam BEGIN SEQUENCE:
the definition of:
#define MIM_BACKGROUND 0x00000002
#define MIM_APPLYTOSUBMENUS 0x80000000

To compile with HMG maybe you have to remove the comand DISABLED from menus
I can't compile with hgm in this moment, I don´t have the zip libs. :(

Re: Error in modifying the color of the main menu

Posted: Sun Apr 29, 2012 1:50 am
by jairpinho
Muito obrigado Carlos Britos e Daniel me ajudaram muito consegui resolver atraves do exemplo do Carlos Britos
segue resultado

Thank you Carlos and Daniel Britos helped me manage to solve through the example of Carlos Britos
result follows

menu color 1

Code: Select all

#include <hmg.ch>

//#include "minigui.ch"

Function Main
        Load Window Form_1
        Form_1.Center
        Form_1.Activate
        
Return Nil


Function teste()
cTeste := REPLICATE("0",100)      

cTeste := STUFF(cTeste,3,1,"1")
msginfo(cTeste)

Return


Func CMenu()
 Local hMenu    := _GetMenuId(GetFormHandle("Form_1"))
 Local aColor   := {255,255,0}
 Local lSubMenu := .t.
 _ColorMenu(GetFormHandle("Form_1"),aColor, lSubMenu,, "BLUSTONE.BMP")
Return Nil

Func ColorMenu()
 Local hMenu    := _GetMenuId(GetFormHandle("Form_1"))
 Local lSubMenu := .t.
 Local aColor   :=GetColor()
 Local aBr := GetControlHandle("ImgTest","Form_1")
 If aColor[1] = Nil
   MsgInfo(" No Selecciono Color ")
 Else
   _ColorMenu(GetFormHandle("Form_1"),aColor, lSubMenu, )
 EndIf
Return Nil

Func ImageMenu()
 Local hMenu    := _GetMenuId(GetFormHandle("Form_1"))
 Local lSubMenu := .t.
 Local aImage   := GetFile(	{ {'BITMAP','*.Bmp'} } , 'Abrir Archivos Bitmap' ,  , .f. , .t. )
 Local aBr := GetControlHandle("ImgTest","Form_1")
 If Empty(aImage)
   MsgInfo(" No Selecciono Imagen ")
 Else
   _ColorMenu(GetFormHandle("Form_1"),, lSubMenu, aImage)
  SetProperty("Form_1","ImgTest","picture",aImage)
 EndIf
Return Nil


#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"
#include "winreg.h"
#include "tchar.h"

#define MIM_BACKGROUND              0x00000002
#define MIM_APPLYTOSUBMENUS         0x80000000


HB_FUNC( _GETMENUID)
{
 hb_retnl((LONG)GetMenu((HWND)hb_parnl(1)));
}

HB_FUNC ( _COLORMENU )
{
HMENU      iMenu;
MENUINFO   iMenuInfo ;

//nRed   = hb_parvni(2,1);
//nGreen = hb_parvni(2,2);
//nBlue  = hb_parvni(2,3);

BOOL  lSubMenu = hb_parl(3);
HWND  himage ;

himage = (HWND)LoadImage(0,hb_parc(4),IMAGE_BITMAP ,0,0,LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );

if (himage==NULL)
  {
	himage = (HWND)LoadImage(GetModuleHandle(NULL),hb_parc(4),IMAGE_BITMAP ,0,0, LR_LOADMAP3DCOLORS	| LR_LOADTRANSPARENT );
  }

iMenu              = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize   = sizeof(MENUINFO);

if (lSubMenu)
 {
   iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS ;
 }
else
 {
   iMenuInfo.fMask    = MIM_BACKGROUND;
 }

if (himage==NULL)
 {
    //iMenuInfo.hbrBack = CreateSolidBrush(RGB(nRed, nGreen, nBlue));
	iMenuInfo.hbrBack = CreateSolidBrush(RGB(hb_parvni(2,1),hb_parvni(2,2),hb_parvni(2,3)));
 }
else
 {
    iMenuInfo.hbrBack = CreatePatternBrush(himage);
 }

SetMenuInfo(iMenu, &iMenuInfo);
DrawMenuBar((HWND) hb_parnl(1));

}


HB_FUNC ( _COLORSUBMENU )
{
HMENU      iMenu;
MENUINFO   iMenuInfo ;
iMenu              = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize   = sizeof(MENUINFO);
iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
iMenuInfo.hbrBack  = CreateSolidBrush(RGB(hb_parvni(2,1),hb_parvni(2,2),hb_parvni(2,3)));
SetMenuInfo(iMenu, &iMenuInfo);
DrawMenuBar((HWND) hb_parnl(1));
}

#pragma ENDDUMP



Menu color 2

Code: Select all

#include <hmg.ch>

//#include "minigui.ch"

Function Main
        Load Window Form_1
			MENU_BACKCOLOR( GetFormHandle("Form_1"),{255,0,0}  )
			MENU_BACKCOLOR( GetFormHandle("Form_1"), 1 ,{0,255,255}  )
			//MENU_BACKCOLOR( GetFormHandle("Form_1"), 2 ,{255,255,0}  )
			//MENU_BACKCOLOR( GetFormHandle("Form_1"), 3 ,{255,0,255}  )

		
        Form_1.Center
        Form_1.Activate
        
Return Nil




   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return Nil

#pragma BEGINDUMP

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

#define MIM_BACKGROUND              0x00000002
#define MIM_APPLYTOSUBMENUS         0x80000000

HB_FUNC ( MENU_BACKCOLOR )
{
   MENUINFO   iMenuInfo ;
   LONG       nColor ;
   HMENU      hMenu = GetMenu((HWND) hb_parnl(1)); ;

   // si son 2 params el segundo es el color
   // two params. 1 = handle form, 2 = array color
   if( HB_ISNIL(3) )
   {
      nColor = (LONG) RGB(hb_parvni(2,1),hb_parvni(2,2),hb_parvni(2,3)) ;
   }
   // si son 3 params el segundo es el numero del submenu, el tercero es el color
   // three params. 1 = handle form, 2 = index position of subMenu, 3 = array color
   else
   {
      hMenu = GetSubMenu( hMenu, hb_parni(2) -1 );
      nColor = (LONG) RGB(hb_parvni(3,1),hb_parvni(3,2),hb_parvni(3,3)) ;
   }

   GetMenuInfo( (HMENU) hMenu, &iMenuInfo );
   iMenuInfo.cbSize   = sizeof(MENUINFO);
   iMenuInfo.fMask    = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
   iMenuInfo.hbrBack  = CreateSolidBrush( nColor );
   SetMenuInfo( hMenu, &iMenuInfo );
   DrawMenuBar((HWND) hb_parnl(1));
}


#pragma ENDDUMP



Re: Error in modifying the color of the main menu

Posted: Mon Apr 30, 2012 3:36 am
by Rathinagiri
Wow! Very nice implementation.

Can we change the color of an individual menu item alone? (Like 'red' color for File->Delete)