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
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
Enumerating data formats currently available on the clipboard
Winsock: sending email messages (SMTP, port 25)
Establishing connection using the SQLDriverConnect
Splash Screen for the VFP application
Detecting changes in connections to removable drives (VFP9)
Custom FTP Class for Visual FoxPro application
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
How to create non-blocking Winsock server
How to print a bitmap file
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Using WM_COPYDATA for interprocess communication (VFP9)
Bitmap Class for Visual FoxPro application
Custom HttpRequest class (WinINet)
Custom HttpRequest class (WinHTTP)
How to activate Windows Calculator
Sending email messages with Simple MAPI
Peer-to-peer LAN messenger built with Mailslot API functions
Displaying bitmap using the AlphaBlend function
How to download a file from the FTP server using FtpGetFile
How to disable the Windows Clipboard (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:

Set the checkbox and the clipboard will be disabled for all running Windows applications.

This FoxPro form is set to be notified when anything is copied to the clipboard -- text, images etc. And it clears the clipboard content on each notification.

Neither timers nor ON KEY handlers are involved.

See also:
  • How to block the PrintScreen key
  • Preventing users from accessing the Windows Desktop and from switching to other applications
  • Capturing keyboard activity of another application using the Raw Input API

  •  
    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace DisablingClipboard
    {
        public class Form1 : System.Windows.Forms.Form
        {
            private System.ComponentModel.Container components = null;
     
            const int WM_DRAWCLIPBOARD=0x0308;
            const int WM_CHANGECBCHAIN=0x030D;
            private System.Windows.Forms.CheckBox checkBox1;
            private IntPtr nextviewer;
     
            public Form1()
            {
                InitializeComponent();
            }
     
            protected override void Dispose( bool disposing )
            {
                if( disposing )
                {
                    if (components != null) 
                    {
                        ChangeClipboardChain(this.Handle, nextviewer);
                        components.Dispose();
                    }
                }
                base.Dispose( disposing );
            }
     
            protected void RegisterWindow() 
            {
                nextviewer = SetClipboardViewer(this.Handle);
            }
     
            protected void UnregisterWindow() 
            {
                ChangeClipboardChain(this.Handle, nextviewer);
            }
     
            protected void ClearClipboard() 
            {
                Clipboard.SetDataObject(new DataObject());
            }
     
            protected override void WndProc(ref Message m) 
            {
                switch (m.Msg)
                {
                    case WM_CHANGECBCHAIN:
                        if (nextviewer==m.WParam) nextviewer=m.LParam;
                        else SendMessage(nextviewer, 
                                 m.Msg, m.WParam, m.LParam);
                        break;
     
                    case WM_DRAWCLIPBOARD:
                        ClearClipboard();
     
                        SendMessage(nextviewer, m.Msg, 
                            m.WParam, m.LParam);
                        break;
                    default:
                        base.WndProc(ref m);
                        break;
                }
            }
     
            #region Windows Form Designer generated code
    // ...skipped...
            #endregion
     
            [STAThread]
            static void Main() 
            {
                Application.Run(new Form1());
            }
     
            private void checkBox1_CheckedChanged(object sender, 
                System.EventArgs e)
            {
                if (this.checkBox1.Checked) RegisterWindow();
                else UnregisterWindow();
            }
     
            [DllImport("user32.dll")]
            static extern IntPtr SendMessage(IntPtr hWnd, 
                int Msg, IntPtr wParam, IntPtr lParam);
     
            [DllImport("User32.dll")]
            public static extern IntPtr SetClipboardViewer(
                IntPtr hWndNewViewer);
     
            [DllImport("User32.dll")]
            public static extern IntPtr ChangeClipboardChain(
                IntPtr hWndRemove, IntPtr hWndNewNext);
     
        }
    }
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    2163 bytes  
    Created: 2005-05-31 18:26:41  
    Modified: 2011-01-08 08:00:28  
    Visits in 7 days: 161  
    Listed functions:
    CallWindowProc
    ChangeClipboardChain
    GetWindowLong
    SendMessage
    SetClipboardViewer
    Printer friendly API declarations
    My comment:
    The Windows OS has a mechanism that allows to notify a window when the content of the clipboard changes.

    Not just one window can be notified but many. They are organized in a chain. The first window in this chain receives a notification and passes it to the next one, so the notification goes down to the last window registered in this chain.

    Any FoxPro window, the _screen or a form, can be registered as a Clipboard viewer -- this is how it is called. The notifications are actually window messages. And VFP9 handles window messages really good due to extended BINDEVENT() function.

    WM_CHANGECBCHAIN -- this notification is sent after a registered window has been removed from the chain of clipboard viewers.

    WM_DRAWCLIPBOARD -- this notification is sent after the content of the clipboard has changed.
    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 (54.234.42.16)
    5 sec.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
    2.58 hrs.Example: 'Displaying the drive type value'
     Function: 'ControlService'
    9.45 hrs.Example: 'Converting a hexadecimal string to an integer'
    13.38 hrs.Function: 'SHAddToRecentDocs'
    13.39 hrs.Function: 'CreatePopupMenu'
    17.08 hrs.Function: 'ImpersonateLoggedOnUser'
     Example: 'Form Magnifier'
    18.43 hrs.Function: 'LockServiceDatabase'
     Function: 'NetConnectionEnum'
    Google
    Advertise here!