Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Solution to disabling BARs with bmps
Message
General information
Forum:
Visual FoxPro
Category:
Menus & Menu designer
Miscellaneous
Thread ID:
00781920
Message ID:
00782031
Views:
24
Hi Terry,

It would be helpfull if you explain what this code suppouse to do that cannot be achieved with regular VFP menus and how it does that.

>
>* MenuTest PRG as framework for UT support
>
>* A few days back after working with sample HFDofo code
>* I asked for help on how to disable a popup with an
>* embedded BMP file in the BAR.
>
>* As I wrote some code for the membership to help me with
>* I stumbled into 'a' solution. Well it works! I want it
>* to be stable and correctly implemented.
>
>* The SKIP FOR clause in the DEFINE BAR syntax will turn
>* off the Graphics. To enable/ disable a 'graphic' popup
>* BAR, the implementation in the ResetMenu procedure
>* seems to work.
>
>* API's are pretty foreign to me, but this implementation
>* uses the ModifyMenu API. MSDN says ModifyMenu has been
>* superceded by SetMenuItemInfo. If anyone can share the
>* solution using SetMenuItemInfo or could offer suggestions
>* to better mange the 'enabling' of graphic BARs, by all
>* means, respond!
>
>* To test, open a new PRG named "MENUTEST.PRG", and paste
>* this code. Then save. Assure you have a BMP file local
>* to the directory (this code uses "TEST.BMP")
>
>* The handles are public for convience, in the real app
>* an object will contain the values.
>
>* Thanks for your help
>
>CLOSE ALL
>CLEAR ALL
>RELEASE ALL
>ON ERROR
>PUBLIC frmMenuTest,ucTestBmp,uhnMenu,uhnPADMenu,unBARMenu,;
>       unTog
>unTog=0
>frmMenuTest=CREATEOBJECT('subfrmMenuTest')
>WITH frmMenuTest
>.ADDOBJECT('cmdResetMenu','subcmdResetMenu')
>ENDWITH
>frmMenuTest.SHOW
>* END OF SHOW
>
>PROCEDURE AddMenu(oform)
>DEFINE MENU mnuTest IN (oform.Name) BAR COLOR SCHEME 8
>DEFINE PAD FILE  OF mnuTest PROMPT "File" COLOR SCHEME 3 KEY ALT+F
>ON PAD FILE OF mnuTest ACTIVATE POPUP popFile
>DEFINE POPUP popFile MARGIN RELATIVE SHADOW COLOR SCHEME 4
>DEFINE BAR 1 OF popFile PROMPT "Menu Disable Test"
>ON SELECTION BAR 1 OF popFile MESSAGEBOX("Menu Disable Test")
>ACTIVATE MENU mnuTest NOWAIT
>DECLARE INTEGER FindWindow IN win32api STRING,STRING
>DECLARE INTEGER GetMenu IN win32api INTEGER
>DECLARE INTEGER GetSubMenu IN win32api INTEGER,INTEGER
>DECLARE INTEGER LoadImage IN win32api INTEGER,STRING,INTEGER,INTEGER,INTEGER,INTEGER
>DECLARE INTEGER SetMenuItemBitmaps IN win32api INTEGER,INTEGER,INTEGER,INTEGER,INTEGER
>DECLARE INTEGER GetMenuItemID IN win32api INTEGER,INTEGER
>DECLARE INTEGER ModifyMenu IN win32api INTEGER,INTEGER,INTEGER,INTEGER,string
>DECLARE INTEGER DrawMenuBar IN win32api INTEGER
>HWnd = FindWindow(0,oform.caption)
>uhnMenu = GetMenu(HWND)
>uhnPADMenu  = GetSubMenu(uhnMenu,0)
>ucTestBmp = "TEST.BMP" && Any small bmp file local to this PRG's folder
>SetMenuImage (uhnMenu,ucTestBmp,uhnPADMenu,0,0,"Menu Disable Test")
>ENDPROC
>
>PROCEDURE ResetMenu(oform)
>unTog=IIF(unTog=0,1,0)
>nBarID  = GetMenuItemId(uhnPADMenu, unBARMenu)
>ModifyMenu(uhnMenu, nBarID ,unTog, nBarID,"Menu Disable Test") && The one should gray it
>ENDPROC
>
>PROCEDURE SetMenuImage (lhnMenu,lcBMP,lhnPADMenu,lnBARMenu,nEnable,lcBARPrompt)
>nBMP  = LoadImage(0,lcBMP,0,13,13,32768+16+2)
>nBarID  = GetMenuItemId(lhnPADMenu, lnBARMenu)
>SetMenuItemBitMaps(lhnPADMenu, nBarID,0,nBMP,nBMP)
>ModifyMenu(lhnMenu, nBarID ,nEnable, nBarID,lcBARPrompt)
>ENDPROC
>
>DEFINE CLASS subfrmMenuTest AS FORM
>SHOWWINDOW=2 && As top level form
>CAPTION=[Menu Test]
>AUTOCENTER=.T.
>PROCEDURE INIT
>AddMenu(this)
>ENDPROC
>PROCEDURE QUERYUNLOAD
>DEACTIVATE MENU
>THIS.RELEASE
>CLEAR EVENTS
>CANCEL
>ENDPROC
>ENDDEF
>
>DEFINE CLASS subcmdResetMenu AS COMMANDBUTTON
>CAPTION=[Toggle popMenu BAR Enabled]
>HEIGHT=30
>WIDTH=200
>VISIBLE=.T.
>TOP=100
>LEFT=80
>PROCEDURE CLICK
>ResetMenu(THIS.PARENT)
>ENDPROC
>ENDDEFINE
>
>* END MENUTEST
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform