Using Win32 functions in Visual FoxPro Image Gallery
Menu
..msdn
AppendMenu
CreateMenu
CreatePopupMenu
DeleteMenu
DestroyMenu
DrawMenuBar
GetMenu
GetMenuBarInfo
GetMenuItemCount
GetMenuItemID
GetMenuItemInfo
GetMenuString
GetSubMenu
GetSystemMenu
InsertMenuItem
IsMenu
SetMenu
TrackPopupMenuEx
Code examples:
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
Attaching menu to a top-level form
Shortcut Menu Class
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form

User rating: 9.4/10 (5 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
Download an archive file with FoxTray.ocx. Check the Readme file.



Register control before testing the VFP code below:
REGSVR32 FoxTray.ocx (use full path to the file).

This control has been created in VB6 and so -- alas! -- requires certain VB support files installed on your computer: MSVBVM60.DLL

See also:
  • Adding icon to the systray (requires VFP9)
  • Adding user-defined items to the Control Menu of VFP form (requires VFP9)

  •  
    #DEFINE ccIcon  "house.ico"  && replace with valid ICO file name
     
    PUBLIC objForm
    objForm = CreateObject("Tform")
    objForm.Visible = .T.
     
    DEFINE CLASS Tform As Form
        Width=400
        Height=240
        MaxButton=.F.
        MinButton=.F.
        Autocenter=.T.
        Caption = " Using Systray icon and menu"
     
        ADD OBJECT cmdShowIcon As CommandButton WITH;
        Caption="Show Icon", Width=100, Height=27,;
        Left=20, Top=20
     
        ADD OBJECT cmdHideIcon As CommandButton WITH;
        Caption="Hide Icon", Width=100, Height=27,;
        Left=20, Top=56
     
        ADD OBJECT chPopup As CheckBox WITH;
        Caption=" Popup enabled", Value=.T.,;
        Left=240, Top=20, Autosize=.T., BackStyle=1
     
    PROCEDURE Init
        THIS.AddTrayCtrl
     
    PROCEDURE AddTrayCtrl
        LOCAL lErr
        ON ERROR lErr = .T.
        THIS.AddObject("FoxTray", "TFoxTray")
        ON ERROR
        IF lErr
            = MessageB("ActiveX control not registered   " + Chr(13) +;
                "or VB support not available.            " + Chr(13) + Chr(13) +;
                "Class: FoxTrayCtl.cFoxTray              " + Chr(13) +;
                "File: FoxTray.ocx   " + Chr(13) +;
                "VB support: msvbvm60.dll   ", 48, " FoxTray Control")
        ENDIF
     
    PROCEDURE cmdShowIcon.Click
        WITH ThisForm.FoxTray
            .IconSource = ccIcon
            .ShowIcon
        ENDWITH
     
    PROCEDURE cmdHideIcon.Click
        ThisForm.FoxTray.HideIcon
    ENDDEFINE
     
    DEFINE CLASS TFoxTray As OLEControl
        OleClass="FoxTrayCtl.cFoxTray"
     
    PROCEDURE Init
        WITH THIS
            .IconSource = ccIcon
            .IconTip = "FoxPro App"
            .ShowIcon
     
            * setting popup items, max number = 5
            .GetPopupItem(1).Caption = "Settings"
            .GetPopupItem(2).Caption = "About"
            .GetPopupItem(3).Caption = "-"  && separator
            .GetPopupItem(4).Caption = "Close form"
            .GetPopupItem(5).Caption = "\Exit"  && item disabled
        ENDWITH
     
    PROCEDURE BeforePopupActivate
    PARAMETERS lResult
        lResult = ThisForm.chPopup.Value && .F. cancels popup activation
     
    PROCEDURE OnPopupItemSelected
    LPARAMETERS lnItem, lcCaption
        DO CASE
        CASE lnItem = 2
            = MessageB("System Tray Icon and Menu Control   ", 64, " About")
        CASE lnItem = 4
            ThisForm.Release
        CASE lnItem = 5
            IF MessageB("Exit FoxPro?   ", 32+4, " FoxTray Control") = 6
                QUIT
            ENDIF
        OTHER
            = MessageB("Popup item selected: " + LTRIM(STR(lnItem)) +;
                ", [" + lcCaption + "]")
        ENDCASE
    ENDDEFINE
     
    * * *
    *|The FoxPro code contains no Win32 functions, all calls moved 
    *|to the ActiveX part:
    *|
    *| LoadImage 
    *| ExtractAssociatedIcon 
    *| DestroyIcon 
    *| GetModuleFileName 
    *| Shell_NotifyIcon 
    *| CallWindowProc 
    *| GetWindowLong 
    *| SetWindowLong 
    *| CopyMemory 
    *| GetCursorPos 
    *| SetRectEmpty 
    *| CreatePopupMenu 
    *| TrackPopupMenuEx 
    *| InsertMenuItem 
     
     
     

    User rating: 9.4/10 (5 votes)
    Rate this code sample:
    • ~
    2637 bytes  
    Created: 2002-10-21 21:37:43  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 120  
    Listed functions:
    CallWindowProc
    CopyMemory
    CreatePopupMenu
    DestroyIcon
    ExtractAssociatedIcon
    GetCursorPos
    GetModuleFileName
    GetWindowLong
    InsertMenuItem
    LoadImage
    SetWindowLong
    Shell_NotifyIcon
    TrackPopupMenuEx
    Printer friendly API declarations
    My comment:
    A fragment of Visual Studion Spy++ screen shows windows inside the system tray:



    Among those windows you may notice Windows Start button, Quick Launch toolbar, minimized windows for running applications, system tray clock, window with system tray icons and more.

    With quite simple code you may hide the whole system tray:

    #DEFINE SW_HIDE 0
    #DEFINE SW_SHOWNORMAL 1

    DECLARE INTEGER ShowWindow IN user32 AS ShowWindowA;
            INTEGER hWindow, INTEGER nCmdShow

    DECLARE INTEGER FindWindow IN user32;
            STRING lpClassName, STRING lpWindowName

    hWindow = FindWindow("Shell_TrayWnd", Null)
    = ShowWindowA(hWindow, SW_HIDE)

    Call ShowWindow with SW_SHOWNORMAL to make the system tray visible again. You may try same code with TrayNotifyWnd and other child windows.

    * * *
    Take a look at this example as well How to block the ALT+TAB shortcut (WinXP):

    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    german developer | 2006-03-22 03:20:49
    thanks!!
    szicsaba | 2006-05-12 02:47:02
    That's great!! I've been looking for this function for a long time.
    Thank you.
    alek161@yahoo.es | 2006-06-11 10:42:00
    el foxtray es gratis
    Nassar Ti | 2011-02-24 07:54:36
    Good Morning! I'm using win7 64 and foxtray.ocx do not registry correctly. i can't no use it. Can any one help me? Thanks.
    AM | 2011-02-25 12:00:21
    Hi Nassar! I am currently developing a new FoxTray ActiveX control (C++, ATL). It works on 64-bit versions Windows. This new control will be available in the first week of March, 2001.
    AM | 2011-02-26 12:53:16
    This may help you with registering OCX on 64-bit system:

    http://social.msdn.microsoft.com/Forums/en/sbappdev/thread/91cf3127-70fe-4726-8a27-31b8964430c5

    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (107.20.129.212)
    39.15 min.Function: 'UrlUnescape'
    Function group: 'Shell Lightweight Utility APIs -- Path Functions'
    39.2 min.Example: 'Passing data records between VFP applications via the Clipboard'
    3.31 hrs.Example: 'Reading VFP settings from the Windows Registry'
     Function: 'GetDIBits'
    5.51 hrs.Example: 'Enumerating servers of the specified type (e.g. SQL Server) in the primary domain'
    7.28 hrs.Example: 'How to detect if additional monitor is connected and active'
     Function: 'GetComputerName'
    10.15 hrs.Example: 'Retrieving long values associated with the class of the VFP window'
     Example: 'How to download this reference`s archive through WinInet functions using InternetOpenUrl'
    12.01 hrs.Example: 'Scanning a hierarchy of child windows down from the Windows Desktop'
    Google
    Advertise here!