Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Custom GDI+ class
Converting Unicode data from the Clipboard to a character string using a given code page
Custom FTP Class for Visual FoxPro application
Custom HttpRequest class (WinINet)
Splash Screen for the VFP application
Displaying bitmap using the AlphaBlend function
Establishing connection using the SQLDriverConnect
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
How to put a vertical text scrolling on the form (a movie cast)
How to make a VFP form fading out when released (GDI+ version)
How to make a VFP form fading out when released (GDI version)
Using FlashWindowEx to flash the taskbar button of the VFP application
How to create non-blocking Winsock server
Winsock: sending email messages (SMTP, port 25)
Using WM_COPYDATA for interprocess communication (VFP9)
Creating a mailslot
Detecting changes in connections to removable drives (VFP9)
Peer-to-peer LAN messenger built with Mailslot API functions
Sending a standard message with one or more attached files using default email client
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
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: 188  
    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 (23.22.76.170)
    29.4 min.Example: 'Locking the workstation'
    3.18 hrs.Example: 'Saving available locale records into a cursor'
    15.34 hrs.Function: 'GdipGetPropertyCount'
    Function group: 'GDI+ Image'
     Example: 'Loading a string resource from an executable file'
    16.03 hrs.Example: 'Connecting a local device to a network resource'
    Google
    Advertise here!