Using Win32 functions in Visual FoxPro Image Gallery
Memory Management
..msdn
CopyMemory
FillMemory
GetProcessHeap
GetProcessHeaps
GlobalAlloc
GlobalFree
GlobalLock
GlobalMemoryStatus
GlobalReAlloc
GlobalSize
GlobalUnlock
HeapAlloc
HeapCompact
HeapFree
HeapLock
HeapReAlloc
HeapSize
HeapUnlock
HeapValidate
HeapWalk
LocalAlloc
LocalFree
LocalSize
VirtualAllocEx
VirtualFreeEx
ZeroMemory
Code examples:
Accessing LSA Policy object (Local Security Authority)
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Adding and deleting User Accounts
Adding printer to the list of supported printers for the specified server
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
Attaching menu to a top-level form
Browsing Windows Known Folders (Special Folders)
Compressing and decompressing files with Windows API Runtime Library routines
Converting command-line string to a set of Unicode argument strings (WinNT only)
Creating the Open dialog box to specify the drive, directory, and name of a file to open
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Custom HttpRequest class (WinHTTP)
Deleting files into the Recycle Bin
Displaying dimmed window behind VFP top-level form
Displaying standard progress dialog box when copying files
Displaying system dialog that selects a folder
Dynamic strings implemented through VFP Custom class
Enumerating data formats currently available on the clipboard
Enumerating files opened on the network
Extensible Storage Engine class library
How to assemble an array of strings and pass it to external function
How to display a user-defined icon in the MessageBox dialog
How to display advanced Task Dialog (Vista)
How to display the Print property sheet
How to display the Properties dialog box for a file (ShellExecuteEx)
How to enumerate sessions and processes on a specified terminal server
How to enumerate terminal servers within the specified Windows domain
How to enumerate, add and delete shares on the local computer (WinNT/XP)
How to extract frames from AVI files
How to ping a remote site using ICMP API calls
How to prevent users from accessing the Windows Desktop and from switching to other applications
How to remove a directory that is not empty
How to write and read Window Properties for the specified window
Loading a string resource from an executable file
MapiSendMail class for Visual FoxPro application
Mapping and disconnecting network drives
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Passing data records between VFP applications via the Clipboard
Printing Image File, programmatically set print page orientation to landscape
Reading and setting explicit Application User Model ID for the current process (Win7)
Reading entries from Event logs
Retrieving configuration information for the specified server (Win2000/XP)
Retrieving the command line for the VFP session
Sending email messages with Simple MAPI
Shortcut Menu Class
Starting a dialog box for connecting to network resources and passing input parameters
Storing the environment strings in cursor
URL: splitting into its component parts
Using Change Notification Objects to monitor changes to the printer or print server
Using WM_COPYDATA for interprocess communication (VFP9)
Windows Shell Icons displayed and exported to ICO files (Vista)
Winsock: connecting to a news server (NNTP, port 119)
Writing entries to custom Event Log
Attaching menu to a top-level form

User rating: 8.5/10 (2 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:
In this example menu is created and attached to a top-level VFP form. The System popup and a user-defined popup are inserted in the menu.



See also:
  • Adding user-defined items to the Control Menu of VFP form (requires VFP9)
  • Transparent Menu Class (requires VFP9)
  • Reading structure of menu attached to the main VFP window
  • Accessing Adobe Reader 7.0 main menu from VFP application

  •  
    PUBLIC frm
    frm = CreateObject("Tform")
    frm.Visible = .T.
     
    DEFINE CLASS Tform As Form
    PROTECTED hWindow, hMenu, hPopup, hSysPopup
        Autocenter=.T.
        ShowWindow=2  && this is important
     
    PROCEDURE Load
        THIS.declare
     
    PROCEDURE Init
        STORE 0 TO THIS.hWindow, THIS.hMenu,;
            THIS.hPopup, THIS.hSysPopup
     
    PROCEDURE Destroy
        * DestroyMenu is recursive, which means 
        * it destroys the menu including all submenus
        = DestroyMenu(THIS.hMenu)
     
    PROCEDURE Activate
        IF THIS.hWindow = 0
            THIS.InitMenu()
        ENDIF
     
    PROCEDURE InitMenu
    #DEFINE MF_STRING  0
        THIS.hWindow = GetFocus()
     
        THIS.hSysPopup = GetSystemMenu(THIS.hWindow, 0)
        THIS.hPopup = CreateMenu()
        = AppendMenu(THIS.hPopup, MF_STRING, 1, "Option &1")
        = AppendMenu(THIS.hPopup, MF_STRING, 1, "Option &2")
        = AppendMenu(THIS.hPopup, MF_STRING, 1, "Option &3")
     
        THIS.hMenu = CreateMenu()
        THIS.AddMenuItem(THIS.hMenu, 0, "&Form", THIS.hPopup)
        THIS.AddMenuItem(THIS.hMenu, 1, "&System", THIS.hSysPopup)
     
        = SetMenu(THIS.hWindow, THIS.hMenu)
     
    PROCEDURE AddMenuItem(hMenu, lnPosition, lcCaption, lnPopup)
    *| typedef struct tagMENUITEMINFO {
    *|   UINT    cbSize;         0:4
    *|   UINT    fMask;          4:4
    *|   UINT    fType;          8:4
    *|   UINT    fState;        12:4
    *|   UINT    wID;           16:4
    *|   HMENU   hSubMenu;      20:4
    *|   HBITMAP hbmpChecked;   24:4
    *|   HBITMAP hbmpUnchecked; 28:4
    *|   ULONG_PTR dwItemData;  32:4
    *|   LPTSTR  dwTypeData;    36:4
    *|   UINT    cch;           40:4
    *|   HBITMAP hbmpItem;      44:4
    *| } MENUITEMINFO, *LPMENUITEMINFO; total = 48 bytes
    #DEFINE MENUITEMINFO_SIZE  48
     
    #DEFINE MFT_STRING 0
    #DEFINE MIIM_STATE 1
    #DEFINE MIIM_ID 2
    #DEFINE MIIM_SUBMENU 4
    #DEFINE MIIM_TYPE 16
    #DEFINE MFS_ENABLED 0
     
        LOCAL lcMask, lcItemInfo, loCaption
        loCaption = CREATEOBJECT("PChar", lcCaption)
        lcMask = MIIM_STATE + MIIM_ID + MIIM_TYPE + MIIM_SUBMENU
     
        * fill MENUITEMINFO structure
        lcItemInfo =;
            num2dword(MENUITEMINFO_SIZE) +;
            num2dword(lcMask) +;
            num2dword(MFT_STRING) +;
            num2dword(MFS_ENABLED) +;
            num2dword(lnPosition) +;
            num2dword(lnPopup) +;
            num2dword(0) +;
            num2dword(0) +;
            num2dword(0) +;
            num2dword(loCaption.GetAddr()) +;
            num2dword(Len(lcCaption)) +;
            num2dword(0)
     
        = InsertMenuItem(hMenu, lnPosition, 1, @lcItemInfo)
    RETURN
     
    PROCEDURE declare
        DECLARE INTEGER GetFocus IN user32
        DECLARE INTEGER CreateMenu IN user32
        DECLARE INTEGER CreatePopupMenu IN user32
        DECLARE INTEGER DestroyMenu IN user32 INTEGER hMenu
     
        DECLARE INTEGER SetMenu IN user32;
            INTEGER hWindow, INTEGER hMenu
     
        DECLARE INTEGER GetSystemMenu IN user32;
            INTEGER hWindow, INTEGER bRevert
     
        DECLARE INTEGER AppendMenu IN user32;
            INTEGER hMenu, INTEGER uFlags,;
            INTEGER uIDNewItem, STRING @lpNewItem
     
        DECLARE INTEGER InsertMenuItem IN user32;
            INTEGER hMenu, INTEGER uItem,;
            INTEGER fByPosition, STRING @lpmii
    ENDDEFINE
     
    DEFINE CLASS PChar As Session
    PROTECTED hMem
     
    PROCEDURE Init(lcString)
        THIS.hMem = 0
        THIS.setValue(lcString)
     
    PROCEDURE Destroy
        THIS.ReleaseString
     
    FUNCTION GetAddr
    RETURN THIS.hMem
     
    FUNCTION GetValue
        LOCAL lnSize, lcBuffer
        lnSize = THIS.getAllocSize()
        lcBuffer = SPACE(lnSize)
     
        IF THIS.hMem <> 0
            DECLARE RtlMoveMemory IN kernel32 As MemToStr;
                STRING @, INTEGER, INTEGER
            = MemToStr(@lcBuffer, THIS.hMem, lnSize)
        ENDIF
    RETURN lcBuffer
     
    FUNCTION GetAllocSize
        DECLARE INTEGER GlobalSize IN kernel32 INTEGER hMem
    RETURN Iif(THIS.hMem=0, 0, GlobalSize(THIS.hMem))
     
    PROCEDURE SetValue(lcString)
    #DEFINE GMEM_FIXED 0 
        THIS.ReleaseString
     
        DECLARE INTEGER GlobalAlloc IN kernel32 INTEGER, INTEGER
        DECLARE RtlMoveMemory IN kernel32 As StrToMem;
            INTEGER, STRING @, INTEGER
     
        LOCAL lnSize
        lcString = lcString + Chr(0)
        lnSize = Len(lcString)
        THIS.hMem = GlobalAlloc(GMEM_FIXED, lnSize)
        IF THIS.hMem <> 0
            = StrToMem(THIS.hMem, @lcString, lnSize)
        ENDIF
     
    PROCEDURE ReleaseString
        IF THIS.hMem <> 0
            DECLARE INTEGER GlobalFree IN kernel32 INTEGER
            = GlobalFree (THIS.hMem)
            THIS.hMem = 0
        ENDIF
    ENDDEFINE
     
    FUNCTION num2dword(lnValue)
    #DEFINE m0 0x0000100
    #DEFINE m1 0x0010000
    #DEFINE m2 0x1000000
        IF lnValue < 0
            lnValue = 0x100000000 + lnValue
        ENDIF
        LOCAL b0, b1, b2, b3
        b3 = Int(lnValue/m2)
        b2 = Int((lnValue - b3*m2)/m1)
        b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
        b0 = Mod(lnValue, m0)
    RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
     
     
     

    User rating: 8.5/10 (2 votes)
    Rate this code sample:
    • ~
    4446 bytes  
    Created: 2001-12-09 11:26:57  
    Modified: 2006-05-18 08:46:40  
    Visits in 7 days: 95  
    Listed functions:
    AppendMenu
    CreateMenu
    CreatePopupMenu
    DestroyMenu
    GetFocus
    GetSystemMenu
    GlobalAlloc
    GlobalFree
    GlobalSize
    InsertMenuItem
    SetMenu
    Printer friendly API declarations
    My comment:
    Take a note that the ShowWindow property for the form should be set to 2. That means "a top-level form in which child forms can be placed".

    See also:
  • BINDEVENT()
  • ShowWindow
  • Adding a Menu to a Top-Level Form.
  • 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:
    Carlos Alloatti | 2006-05-08 11:44:43
    Maybe with VFP 9 Bindevent to window messages this can be made to react to user selections?
    64.229.225.52 | 2006-05-08 13:45:00
    Carlos, this example is quite old. I should have it rewritten logn time ago.

    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 (50.19.155.235)
    4 sec.Example: 'Enumerating ports that are available for printing on a specified server'
    1.06 hrs.Example: 'Obtaining physical parameters for a drive: sectors, clusters, cylinders...'
     Example: 'Extensible Storage Engine class library'
    3.49 hrs.Example: 'Using MessageBeep'
    Google
    Advertise here!