Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
How to change display settings: screen resolution, screen refresh rate
GDI+: Storing content of the Clipboard to a bitmap file
GDI+: saving image of FoxPro form to graphics file (BMP, GIF, JPG, PNG, TIF)
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Custom GDI+ class
How to convert a bitmap file to monochrome format (1 bpp)
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Capturing keyboard activity of another application with the Raw Input API (VFP9)
GDI+: Implementing image scrolling with inertia
Storing content of the Clipboard to a bitmap file
Retrieving the name of the primary domain controller (PDC) and join status information
How to display Windows On-Screen Keyboard
Custom HttpRequest class (WinHTTP)
How to put a horizontal text scrolling on the form (a news line, marquee)
GDI+: converting image file to another graphics format
Winsock: sending email messages (SMTP, port 25)
How to detect if additional monitor is connected and active
Extended MessageBox Class
GDI+: creating scaled copy of image file
Mapping and disconnecting network drives
Custom HttpRequest class (WinINet)
GDI+: reading and writing metadata in JPEG and TIFF files
How to create MD-5 and SHA-1 hash values from a string
Using WM_COPYDATA for interprocess communication (VFP9)

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:
An application sends the WM_COPYDATA message to pass data to another application running on the same PC.


The screen copy above shows a message sent from VFP to C# application. The MessageBox is invoked by C# form upon receiving the message.

See also:
  • Peer-to-peer LAN messenger built with Mailslot API functions
  • Using mailslots to send messages on the network
  • Using named pipes for interprocess communication
  • Using the NetMessageBufferSend to send messages on the network
  • How to create non-blocking Winsock server
  • using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    //compile with /unsafe
    
    namespace CopyDataInterop
    {
        public partial class Form1 : Form
        {
            public const int WM_COPYDATA = 0x004a;
    
            [StructLayout(LayoutKind.Sequential)]
            public struct COPYDATASTRUCT
            {
                [MarshalAs(UnmanagedType.I4)]
                public int dwData;
                [MarshalAs(UnmanagedType.I4)]
                public int cbData;
                [MarshalAs(UnmanagedType.SysInt)]
                public IntPtr lpData;
            }
    
            public Form1()
            {
                InitializeComponent();
                this.Text = "HWND " + this.Handle.ToString();
            }
    
            unsafe protected override void WndProc(ref Message message)
            {
                if (message.Msg == WM_COPYDATA)
                {
                    COPYDATASTRUCT data = (COPYDATASTRUCT)
                        message.GetLParam(typeof(COPYDATASTRUCT));
    
                    string str = new string((char*)(data.lpData), 
                        0, data.cbData/2);
    
                    MessageBox.Show(str, "Data received", 
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                base.WndProc(ref message);
            }
    
            unsafe private void SendString()
            {
                string s = this.textBox2.Text;
                IntPtr lpData = Marshal.StringToHGlobalUni(s);
    
                COPYDATASTRUCT data = new COPYDATASTRUCT();
                data.dwData = 0;
                data.cbData = s.Length * 2;
                data.lpData = lpData;
    
                IntPtr lpStruct = Marshal.AllocHGlobal(
                    Marshal.SizeOf(data));
    
                Marshal.StructureToPtr(data, lpStruct, false);
    
                int hTarget = Convert.ToInt32(textBox1.Text);
    
                SendMessage(hTarget, WM_COPYDATA, 
                    this.Handle, lpStruct);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                SendString();
            }
    
            [DllImport("User32.dll")]
            private static extern bool SendMessage(int hWnd,
                int wMsg, IntPtr wParam, IntPtr lParam);
    
        }
    }
    

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    2220 bytes  
    Created: 2008-03-28 13:32:01  
    Modified: 2008-04-03 11:52:28  
    Visits in 7 days: 113  
    Listed functions:
    CallWindowProc
    GetWindowLong
    GlobalAlloc
    GlobalFree
    GlobalSize
    SendMessage
    Printer friendly API declarations
    My comment:
    The forms belonging to different VFP sessions (different processes) can exchange data in the same way. The window handle stays global through the Windows session.

    The C# and VFP versions of this code sample are functionally identical. That allows exchanging data between .NET and VFP forms (applications).

    In real life situation, prior to exchanging data the forms must have exchanged their window handles. That can be arranged by each form broadcasting a specific message that the other forms would recognize and respond. The FindWindow API is another option.

    * * *
    Comparing to other ways of interprocess communication (named pipes, mailslots, Winsock) the WM_COPYDATA has a certain edge: no need to implement any listening part. The OS does it for you.

    * * *
    http://blogs.msdn.com/oldnewthing/archive/2003/12/11/56043.aspx
    if you need to pass more than 32767 characters of information to a child process, you`ll have to use something other than the command line.
    * * *
    Articles:
  • Interprocess Communications chapter on MSDN.
  • Foxpro Advisor Exchange Data Between Applications with Visual FoxPro 9 by Christof Wollenhaupt (recommended).
  • 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-2014 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.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.211.79.241)
    6 sec.Function: 'HeapFree'
    12 sec.Example: 'GDI+: loading image file, drawing on it, saving the result to another file'
    15 sec.Function: 'waveInGetErrorText'
    Function group: 'Windows Multimedia'
    16 sec.Function: 'GetPhysicalMonitorsFromHMONITOR'
    17 sec.Function: 'CryptDestroyKey'
    18 sec.Function: 'NetScheduleJobEnum'
    Function group: 'Network Management'
    19 sec.Examples
    Page 4
    20 sec.Function: 'waveOutOpen'
    Function group: 'Windows Multimedia'
    21 sec.Function: 'SQLTables'
     Function: 'SCardListReaderGroups'
    Google
    Advertise here!