How do you output to clipboard?
Results 1 to 6 of 6

Thread: How do you output to clipboard?

  1. #1
    Member
    Join Date
    Sep 2003
    Posts
    42

    Question How do you output to clipboard?

    (I am using C/C++)
    I am learning to program, and I was wondering... how exactly do you output to the clipboard? Is there a way I can take and output information to the clipboard? (like a string or a character, whatever) I am sure there has to be some way of doing it, how is it done?
    --------------------------------------------------------------------
    E, the modern pi.

  2. #2
    Senior Member
    Join Date
    Jan 2003
    Posts
    220
    Umm....Im thinking you could use API. I use this for visual basic but Im sure it will work in C/C++ too.

    Declaration:
    Declare Function SetClipboardData Lib "user32" Alias "SetClipboardDataA" (ByVal wFormat As Long, ByVal hMem As Long) As Long

    uFormat
    Specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats listed in the following Remarks section. For information about registered clipboard formats, see the RegisterClipboardFormat function. For this you`ll need a constant here ares the ones I think you`ll need

    Const CF_TEXT = 1------For Text
    Const CF_BITMAP = 2------For Bitmaps


    hMem
    Identifies the data in the specified format. This parameter can be NULL, indicating that the window provides data in the specified clipboard format (renders the format) upon request. If a window delays rendering, it must process the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages.
    Once SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the GlobalAlloc function with the GMEM_MOVEABLE and GMEM_DDESHARE flags.


    Also, You may need to open the clipboard first.

    Declaration:
    Declare Function OpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hwnd As Long) As Long

    Just use your windows own handle for the hwnd parameter

    Close it when your done.

    Declaration:
    Declare Function CloseClipboard Lib "user32" Alias "CloseClipboard" () As Long

    Hope this helped. I used APIGuide for this. http://www.allapi.net
    [gloworange]And then it happened... a door opened to a world... rushing through the phone line like heroin through an addict\'s veins, an electronic pulse is sent out, a refuge from the day-to-day incompetencies is sought... a board is found. \"This is it... this is where I belong...\" I know everyone here... even if I\'ve never met them, never talked to them, may never hear from them again... I know you all...[/gloworange]

  3. #3
    Member
    Join Date
    Sep 2003
    Posts
    42

    Question ???

    oK... can you please show me the code as if you were going to output a hello world message
    --------------------------------------------------------------------
    E, the modern pi.

  4. #4
    Senior Member
    Join Date
    Jan 2003
    Posts
    220
    Well I dont exactly know C++ but I know the API You just delcare the functions

    //Declare Variables and Constants
    chr string = "Hello World"
    Const CF_TEXT = 1
    Const CF_BITMAP = 2

    //Open the Clipboard
    OpenClipboard(your windows handle)

    //Set Data in Clipboard
    SetClipboardData(CF_TEXT,string)

    //Close Clipboard
    CloseClipboard()
    [gloworange]And then it happened... a door opened to a world... rushing through the phone line like heroin through an addict\'s veins, an electronic pulse is sent out, a refuge from the day-to-day incompetencies is sought... a board is found. \"This is it... this is where I belong...\" I know everyone here... even if I\'ve never met them, never talked to them, may never hear from them again... I know you all...[/gloworange]

  5. #5
    Member
    Join Date
    Sep 2003
    Posts
    42

    Question anyone else

    Anyone else have any ideas?
    --------------------------------------------------------------------
    E, the modern pi.

  6. #6
    Senior Member
    Join Date
    May 2002
    Posts
    344
    for C++ i bet you will be using the fstream library...you can read up on it in this tutorial, it should have basically everything you need:

    http://www.antionline.com/showthread...hreadid=247364
    Support your right to arm bears.


    ^^This was the first video game which i played on an old win3.1 box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •