Disabling/removing menu

Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Disabling/removing menu

Post by Roberto Parisi »

Hi Antonio,
I can't disable or remove menuitems... is it a FWPPC bug??

I post you a sample:

#include "FWCE.ch"

static oMenu1, oMenu2, oMenu

function Main()

local oWnd

DEFINE WINDOW oWnd TITLE "TestMenu" ;
MENU BuildMenu()

@0,0 button "Disable" size 100, 20 action oMenu1:Disable() pixel
@30,0 button "Remove" size 100, 20 action RemoveMenu(oMenu:hMenu, 1) pixel

ACTIVATE WINDOW oWnd ;
ON CLICK MsgInfo( "Click!" )

return nil

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

function BuildMenu()

DEFINE MENU oMenu RESOURCE 102

REDEFINE MENUITEM oMenu1 ID 110 OF oMenu ACTION MsgInfo( "First" ) when .F.

REDEFINE MENUITEM oMenu2 ID 120 OF oMenu ACTION MsgInfo( "Second" )

return oMenu

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

#pragma BEGINDUMP
#include "windows.h"

HB_FUNC(REMOVEMENU) {
RemoveMenu((HMENU) hb_parnl(1), (UINT) hb_parnl(2), MF_BYPOSITION);
}

#pragma ENDDUMP


Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

We are going to review it and we will provide you an answer asap
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

Please try these functions:

Code: Select all

TB_ENABLE( oMenu:hMenu, oMenuItem:nId )
TB_DISABLE( oMenu:hMenu, oMenuItem:nId )

Code: Select all

HB_FUNC( TB_DISABLE )
{
   HWND hMenuBar = (HWND)SHFindMenuBar(hb_parnl(1));

   TBBUTTONINFO tbbi;
   tbbi.cbSize = sizeof(tbbi);
   tbbi.dwMask = TBIF_STATE;
   tbbi.fsState = TBSTATE_INDETERMINATE;

   SendMessage( hMenuBar, TB_SETBUTTONINFO, hb_parnl( 2 ), ( LPARAM ) &tbbi ); 
   return; 
}

HB_FUNC ( TB_ENABLE )
{
   HWND hMenuBar = ( HWND ) SHFindMenuBar( hb_parnl( 1 ) );

   TBBUTTONINFO tbbi;
   tbbi.cbSize = sizeof(tbbi);
   tbbi.dwMask = TBIF_STATE;
   tbbi.fsState = TBSTATE_ENABLED;

   SendMessage( hMenuBar, TB_SETBUTTONINFO, hb_parnl( 2 ), ( LPARAM ) &tbbi); 
   return; 
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

Thx Antonio but it seems doesn't work:

This is the full sample code:

#include "FWCE.ch"

static oMenuItem1, oMenuItem2, oMenu

function Main()

local oWnd

DEFINE WINDOW oWnd TITLE "TestMenu" ;
MENU BuildMenu()

@0,0 button "Disable" size 100, 20 action TB_Disable(oMenu:hMenu, oMenuItem1:nID) pixel
@30,0 button "Remove" size 100, 20 action TB_Enable(oMenu:hMenu, oMenuItem1:nID) pixel

ACTIVATE WINDOW oWnd ;
ON CLICK MsgInfo( "Click!" )

return nil

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

function BuildMenu()

DEFINE MENU oMenu RESOURCE 102

REDEFINE MENUITEM oMenuItem1 ID 110 OF oMenu ACTION MsgInfo( "First" ) when .F.

REDEFINE MENUITEM oMenuItem2 ID 120 OF oMenu ACTION MsgInfo( "Second" )

return oMenu

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

#pragma BEGINDUMP
#include "windows.h"
#include "commctrl.h"

HB_FUNC( TB_DISABLE )
{
HWND hMenuBar = (HWND)SHFindMenuBar(hb_parnl(1));

TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_STATE;
tbbi.fsState = TBSTATE_INDETERMINATE;

SendMessage( hMenuBar, TB_SETBUTTONINFO, hb_parnl( 2 ), ( LPARAM ) &tbbi );
return;
}

HB_FUNC ( TB_ENABLE )
{
HWND hMenuBar = ( HWND ) SHFindMenuBar( hb_parnl( 1 ) );

TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_STATE;
tbbi.fsState = TBSTATE_ENABLED;

SendMessage( hMenuBar, TB_SETBUTTONINFO, hb_parnl( 2 ), ( LPARAM ) &tbbi);
return;
}

#pragma ENDDUMP

Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

This sample is working fine. No need for the functions that I told you, sorry:

Code: Select all

#include "FWCE.ch" 

static oMenuItem1, oMenuItem2, oMenu 

function Main() 

local oWnd 

DEFINE WINDOW oWnd TITLE "TestMenu" ; 
MENU BuildMenu() 

@  0, 0 button "Disable" size 100, 20 action oMenuItem1:Disable() pixel 
@ 30, 0 button "Enable" size 100, 20 action oMenuItem1:Enable() pixel 

ACTIVATE WINDOW oWnd ; 
ON CLICK MsgInfo( "Click!" ) 

return nil 

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

function BuildMenu() 

DEFINE MENU oMenu RESOURCE 102 

REDEFINE MENUITEM oMenuItem1 ID 110 OF oMenu ACTION MsgInfo( "First" ) 

REDEFINE MENUITEM oMenuItem2 ID 120 OF oMenu ACTION MsgInfo( "Second" ) 

return oMenu 

//----------------------------------------------------------------------------// 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

Sorry Antonio, but it doesn't work. After pressing "Disable" I still can press on menuitem first and get the MsgInfo()

Have you tried with your testmenu.rc sample?

Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

You must be doing something wrong as here it is working fine.

Please download it and test it:
http://rapidshare.com/files/87217677/test.zip.html
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

Ok Antonio, I understand.

I use another rc file (the same of your testmenu.prg sample) without child menuitems.

This is the rc file:

#ifdef _CE
#include "c:\vce\include\arm\windows.h"
#include "c:\vce\include\arm\commctrl.h"
#endif

#define I_IMAGENONE (-2)
#define IDS_HELP 104

#ifdef _CE
102 RCDATA
BEGIN
102, 2,
I_IMAGENONE, 110, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE, 202, 0, 0,
I_IMAGENONE, 120, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE, 203, 0, 0,
END
#endif

STRINGTABLE DISCARDABLE
BEGIN
202 "First"
203 "Second"
END

102 MENU DISCARDABLE
BEGIN
MENUITEM "", 110
MENUITEM "", 120
END

Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

So is it working fine now for you ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

No, Antonio.

If you use the rc file I provided you, you can't disable the menu item.

Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

Ok, for the top menuitems you have to use the functions that I told you, this way:

@ 0, 0 button "Disable" size 100, 20 action TB_Disable( oWnd:hWnd, 110 ) pixel

tested and working fine
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

Ok Antonio,
now it works, I needed to pass hWnd instead hMenu as first parameter in TB_Enable.

Many many thx.

Now I've troubles with GetKeyState() function, it returns always .F.

Regards,
Roberto Parisi
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

What value are you checking with GetKeyState() ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Roberto Parisi
Posts: 116
Joined: Thu Oct 13, 2005 5:14 pm
Location: Italy

Post by Roberto Parisi »

Every value...

With the sample try to press SHIFT + TAB to go to previous control... it goes always to the next control forward.

Regards,
Roberto Parisi

#include "FWCE.ch"

function Main()

local oWnd, cText := Space( 50 ), cText1 := Space( 50 ), cText2 := Space( 50 )

DEFINE WINDOW oWnd TITLE "Test"

@ 0, 0 GET cText SIZE 200, 20 pixel

@ 30, 2 GET cText1 SIZE 200, 20 pixel

@ 60, 2 GET cText2 SIZE 200, 20 pixel

ACTIVATE WINDOW oWnd

return nil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Roberto,

Shift+Tab is working fine here on the WM2003 emulator.

Its going to the previous control

I email you my EXE
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply