use of windows clipboard

hi to all
my problem is this:

i have a string in windows clipboard from an another program and would like to use it in pascal
(i'm using turbo pascal for windows 1.5)

so my question is this
how do i get the string, and later how do i set the data in WINDOWS clipboard


thank you very much in advance




w:=getactivewindow;
h:=getclipboarddata(CF_TEXT);
p:=globallock(h);

help?

Comments

  • p:pointer;
    pc:pcchar;
    pb:pcbyte;


    openclipboard(getactivewindow);
    p:=globallock(getclipboarddata(CF_TEXT));
    pb:=pbyte(p);
    pc:=pchar(p);
    writeln(pc);
    globalunlock(getclipboarddata(CF_TEXT));
    closeclipboard;



    can someone tell me if this is correct, and can i clear the code a bit? what don't i require?
  • post-removed
  • post-removed
  • the above code check's out, it's been functional all day long, no glitches with windows API

    but i have a problem now: how do i copy string into clipboard?


    i guess it's gonna be using:
    globalalloc
    strcopy
    setclipboarddata


    globalalloc - gives me the THandle of an allocated space in memory
    strcopy - i can't even begin to understand how it fits in here
    setclipboarddata - i set the format at CF_TEXT, but i don't know how to find the (local or global) handle of a varible string

    im using:

    uses WinDos,WinCrt,WinProcs,WinTypes,WObjects,Strings;
    var s:string;

    please help
  • : the above code check's out, it's been functional all day long, no
    : glitches with windows API
    :
    : but i have a problem now: how do i copy string into clipboard?
    :
    :
    Here's an example how to do it with Free Pascal, since I don't have TPW 1.5 (Tried to keep it simple)[code][color=Blue]{$apptype console}
    {$mode fpc}

    uses windows;

    type buffer=array[0..255] of char;

    var s:string;
    sl:byte absolute s; { length of s }
    b:buffer;
    i:byte;
    p:pointer;
    h:handle; { handle <=> longint }

    begin
    if openclipboard(0) then begin { reserve clipboard for current task }
    emptyclipboard; { must empty clipboard to be able to write into }
    write('Enter a text here:');readln(s); { get user input }
    for i:=1 to sl do b[i-1]:=s[i];b[sl]:=#0; { convert pascal string into a windows string }
    h:=globalalloc(2{GMEM_MOVABLE},sl+1); { allocate windows memory }
    p:=globallock(h); { locking global mem object }
    move(b,p^,sl+1); { copy our string into global mem object }
    globalunlock(h); { unlock global mem object }
    if setclipboarddata(1{CF_TEXT},h)=0 then { <--- }
    begin
    globalfree(h);
    writeln('It did''t work for some reason !');
    end else writeln('Success !');
    closeclipboard;
    globaldiscard(h); { free memory previously reserved }
    end else writeln('Unable to access clipboard.');
    readln;
    end.
    [/color][/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories