Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
Splash Screen for the VFP application
Subclassing CommandButton control to create BackColor property
Obtaining names and positions for shortcuts located on the Windows Desktop
Enumerating devices installed on the local machine
How to make a VFP form fading out when released (GDI version)
Displaying dimmed window behind VFP top-level form
How to put a vertical text scrolling on the form (a movie cast)
GDI+: Implementing image scrolling with inertia
Printing text with the Escape function
Moving shortcut to a specified position on the Windows Desktop
How to put a horizontal text scrolling on the form (a news line, marquee)
Storing content of the Clipboard to a bitmap file
Vertical Label control
Disconnecting USB Mass Storage Device programmatically
Monitoring clipboard content changes (VFP9)
System Image List Viewer
Detecting changes in connections to removable drives (VFP9)
How to play AVI file on the _screen
How to enable the SE_SHUTDOWN_NAME privilege for the application
Creating a console window for Visual FoxPro application
How to ping a remote site using ICMP API calls
Class library providing access to the System Registry
Enumerating Processes -- WinNT
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
        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 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")
    PROCEDURE cmdShowIcon.Click
        WITH ThisForm.FoxTray
            .IconSource = ccIcon
    PROCEDURE cmdHideIcon.Click
    DEFINE CLASS TFoxTray As OLEControl
        WITH THIS
            .IconSource = ccIcon
            .IconTip = "FoxPro App"
            * 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
    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
        CASE lnItem = 5
            IF MessageB("Exit FoxPro?   ", 32+4, " FoxTray Control") = 6
            = MessageB("Popup item selected: " + LTRIM(STR(lnItem)) +;
                ", [" + lcCaption + "]")
    * * *
    *|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: 200  
    Listed functions:
    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:


    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 offers instant, free translations of text or web pages.
    User Contributed Notes:
    german developer | 2006-03-22 03:20:49
    szicsaba | 2006-05-12 02:47:02
    That's great!! I've been looking for this function for a long time.
    Thank you. | 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:

    Copyright 2001-2018 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.6.39), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (
    4 sec.Example: 'Using File Mapping for enumerating files opened by Visual FoxPro'
    8 sec.Example: 'How to view icons stored in executable files (Icon Viewer) - II'
    10 sec.Function: 'GetBestRoute'
    13 sec.
    Function group: 'Event Logging'
    16 sec.
    Function group: 'Device Context'
    20 sec.Function: 'CeRapiFreeBuffer'
    Function group: 'Remote Application Programming (RAPI)'
    22 sec.Function: 'sndPlaySound'
    Function group: 'Windows Multimedia'
    24 sec.Function: 'CopyFile'
    26 sec.
    Function group: 'Windows Multimedia'
    29 sec.
    Function group: 'Hook'
    Advertise here!