Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to print a bitmap file
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Winsock: sending email messages (SMTP, port 25)
System Image List Viewer
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Custom HttpRequest class (WinHTTP)
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
The window and its ancestors
Mapping and disconnecting network drives
How to download a file from the FTP server using FtpGetFile
Using EnumPrinters function to enumerate locally installed printers
Custom FTP Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
Displaying icons in the system tray (VFP9)
How to activate Windows Calculator
Drawing Windows predefined bitmaps using the LoadBitmap functions
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Sending email messages with Simple MAPI
Obtaining names and positions for shortcuts located on the Windows Desktop

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
This code sample shows how to retrieve names and positions of the shortcuts located on the Windows Desktop.

The VFP version of this code sample works with no changes on either 32-bit or 64-bit systems.

See also:
  • Moving shortcut to a specified position on the Windows Desktop
  • How to create a desktop shortcut
  •  
    #include "stdafx.h"
    #include < windows.h >
    #include < Commctrl.h >
    #include < conio.h >
     
    void EnumerateDesktopItems();
     
    int _tmain()
    {
        EnumerateDesktopItems();
     
        printf("\n\nAny key...");
        getch();
     
        return 0;
    }
     
    HWND GetDesktopListViewHandle()
    {
        HWND hwnd = FindWindow("Progman", NULL);
        hwnd = GetWindow(hwnd, GW_CHILD);
        hwnd = GetWindow(hwnd, GW_CHILD);
     
        LPTSTR pClassName = (LPTSTR) calloc(1, MAX_PATH);
        int bufsize = GetClassName(hwnd, pClassName, MAX_PATH);
     
        if (_stricmp(pClassName, "SysListView32") != 0)
        {
            hwnd = (HWND)0;
        }
     
        free(pClassName);
     
        return hwnd;
    }
     
    LPVOID AllocProcessMem(HANDLE hProcess, SIZE_T size)
    {
        return VirtualAllocEx(
            hProcess, 
            NULL, 
            size, 
            MEM_COMMIT, 
            PAGE_READWRITE);
    }
     
    void FreeProcessMem(HANDLE hProcess, LPVOID address)
    {
        VirtualFreeEx(
            hProcess, 
            address, 
            0, 
            MEM_RELEASE);
    }
     
    void EnumerateDesktopItems()
    {
        HWND hwndListView = GetDesktopListViewHandle();
        if (!IsWindow(hwndListView)) return;
     
        DWORD dwProcessId = 0;
        GetWindowThreadProcessId(hwndListView, &dwProcessId);
     
        HANDLE hProcess = OpenProcess(
            PROCESS_ALL_ACCESS, 
            FALSE, 
            dwProcessId);
     
        if (!hProcess) return;
     
        LVITEM lvi = {0};
        lvi.cchTextMax=MAX_PATH;
     
        char item[MAX_PATH], subitem[MAX_PATH];
        POINT point;
     
        LVITEM * _lvi = (LVITEM*) AllocProcessMem(hProcess, sizeof(LVITEM));
        LPTSTR _item = (LPTSTR) AllocProcessMem(hProcess, MAX_PATH);
        LPTSTR _subitem = (LPTSTR) AllocProcessMem(hProcess, MAX_PATH);
        POINT* _point = (POINT*) AllocProcessMem(hProcess, sizeof(POINT));
     
        int count = ListView_GetItemCount(hwndListView);
     
        for (int itemIndex=0; itemIndex < count; itemIndex++)
        {
            lvi.iSubItem=0;
            lvi.pszText=_item;
     
            WriteProcessMemory(
                hProcess, 
                _lvi, 
                &lvi, 
                sizeof(LVITEM), 
                NULL);
     
            SIZE_T size = SendMessage(
                hwndListView, 
                LVM_GETITEMTEXT, 
                (WPARAM)itemIndex, 
                (LPARAM)_lvi);
     
            ReadProcessMemory(
                hProcess, 
                _item, 
                item, 
                MAX_PATH, 
                NULL);
     
            SendMessage(
                hwndListView, 
                LVM_GETITEMPOSITION, 
                (WPARAM)itemIndex, 
                (LPARAM)_point);
     
            ReadProcessMemory(
                hProcess, 
                _point, 
                &point, 
                sizeof(POINT), 
                NULL);
     
            printf("%d. %s - [x=%d, y=%d]\n", 
                itemIndex+1, 
                item, 
                point.x, 
                point.y);
     
            for (int subItemIndex=1; subItemIndex <= 3; subItemIndex++)
            {
                lvi.iSubItem=subItemIndex;
                lvi.pszText=_subitem;
     
                WriteProcessMemory(
                    hProcess, 
                    _lvi, 
                    &lvi, 
                    sizeof(LVITEM), 
                    NULL);
     
                size = SendMessage(
                    hwndListView, 
                    LVM_GETITEMTEXT, 
                    (WPARAM)itemIndex, 
                    (LPARAM)_lvi);
     
                if (size)
                {
                    ReadProcessMemory(
                        hProcess, 
                        _subitem, 
                        subitem, 
                        MAX_PATH, 
                        NULL);
     
                    printf("\t- (%d) %s\n", subItemIndex, subitem);
                }
            }
        }
     
        FreeProcessMem(hProcess, _point);
        FreeProcessMem(hProcess, _subitem);
        FreeProcessMem(hProcess, _item);
        FreeProcessMem(hProcess, _lvi);
     
        CloseHandle(hProcess);
    }
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    3079 bytes  
    Created: 2012-02-07 09:24:06  
    Modified: 2012-02-19 18:42:35  
    Visits in 7 days: 125  
    Listed functions:
    CloseHandle
    FindWindow
    GetCurrentProcess
    GetWindow
    GetWindowThreadProcessId
    IsWindow
    IsWow64Process
    OpenProcess
    ReadProcessMemory
    SendMessage
    VirtualAllocEx
    VirtualFreeEx
    WriteProcessMemory
    Printer friendly API declarations
    My comment:
    On the picture below, the window with title "FolderView" and class "SysListView32" is actually a ListView control. The OS uses this ListView control for displaying shortcuts on the Windows desktop.


    For manipulating ListViews, Windows has an exhaustive set of LVM macros. Each LVM macro wraps a call to the SendMessage API function.

    Take in account that the Desktop ListView belongs to a different process. That makes calling the LVM macros a bit more complex than if both a caller and a ListView had shared the same process. Some memory needs to be allocated directly in the address space of that process, and some data moved back and forth.

    And here is one more thing. On 64-bit system the Desktop ListView obviously belongs to a 64-bit process. And remember that Visual FoxPro is a 32-bit application.

    That 32 to 64-bit issue makes LVM calls that use the LVITEM structure even more convoluted. The structure clearly cannot be used as is. Instead some of its members (the pointers) must be "padded" with extra bytes to fit a pattern recognizable by 64-bit OS.
    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:
    There are no notes on this subject.


    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.16.132.180)
    20.63 min.Function: 'CeRapiFreeBuffer'
    Function group: 'Remote Application Programming (RAPI)'
    20.72 min.Example: 'How to create a desktop shortcut (shell link)'
    54.93 min.Example: 'Winsock: retrieving Web pages using sockets (HTTP, port 80)'
    55 min.Example: 'Retrieving graphic capabilities of your display'
    55.05 min.Function: 'CloseEventLog'
    Function group: 'Event Logging'
    1.69 hrs.Example: 'Placing an arbitrary rectangular area of main VFP window on the Clipboard'
     Function: 'LookupAccountSid'
    1.79 hrs.Function: 'GetEnvironmentStrings'
    Function group: 'Process and Thread'
    1.8 hrs.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
     Function: 'socket'
    Google
    Advertise here!