SetClipBoardData()

This is a discussion on SetClipBoardData() within the Windows Programming forums, part of the Platform Specific Boards category; well, i've had a look as MSDN, and it's really not a help. if anyone could post a quick example ...

  1. #1
    Registered User Kupo's Avatar
    Join Date
    Dec 2001
    Posts
    36

    SetClipBoardData()

    well, i've had a look as MSDN, and it's really not a help.

    if anyone could post a quick example of the code that will *work* i'll love you forever.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Assuming you are interested in text......run this and then paste into any program (MSWord, notepad.....etc)....

    Code:
    #include <windows.h>
    #include <string.h>
    
    int WINAPI WinMain(HINSTANCE hThisInstance,
    				   HINSTANCE hPrevInstance, 
    				   LPSTR lpszArgument, 
    				   int nFunsterStil)
    {
    
    	HANDLE hData;//For the data to send to the clipboard
    	char szData[] = "Hello World (from the clipboard!!)",//phrase
    		 *ptrData = NULL;//pointer to allow char copying
    	int nStrLen = strlen(szData);//length of phrase
    
    	hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
    		nStrLen + 1);//get handle to memory to hold phrase
    	
    	ptrData = (char*)GlobalLock(hData);//get pointer from handle
    
    	memcpy(ptrData,szData,nStrLen + 1);//copy over the phrase
    
    	GlobalUnlock(hData);//free the handle
    
    	OpenClipboard(NULL);//allow you to work with clipboard
    
    	EmptyClipboard();//clear previous contents
    
    	SetClipboardData(CF_TEXT,hData);//set our data
    
    	CloseClipboard();//finished!!
    	
      
       return 0;
    }

    Oh........and there is no need to "love me forever"......

  3. #3
    Registered User Kupo's Avatar
    Join Date
    Dec 2001
    Posts
    36
    *praises Fordy*

    love you man

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  2. Second parameter of SetClipboardData()
    By Dual-Catfish in forum Windows Programming
    Replies: 2
    Last Post: 02-28-2002, 11:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21