Copy Clipboard in file | | |
Hi
it's possible with language C, (Mingw or Djgpp)
copying the clipboard of WinXp into file.txt?
which function must be use.
Thanks | | | | re: Copy Clipboard in file
Over wrote: Quote:
Hi
>
it's possible with language C, (Mingw or Djgpp)
copying the clipboard of WinXp into file.txt?
>
Probably, but here or a number of the other groups you have multi-posted
(don't do that!) to is not the place to ask.
Ask on a windows group.
--
Ian Collins. | | | | re: Copy Clipboard in file
On 3 Oct 2008 at 22:18, Over wrote: Quote:
it's possible with language C, (Mingw or Djgpp)
copying the clipboard of WinXp into file.txt?
>
which function must be use.
Lots of people here can answer your question, but none of them will.
Wait and see the responses you get if you don't believe me.
(Jacob Navia is the only one able and willing to answer Windows
questions, and he seems to be taking a break from the feverish idiocy of
clc at the moment.)
However, the first result in this search looks like it will lead quickly
to the answer:
<http://www.google.com/search?q=site%3Amsdn.microsoft.com+windows+api+cli pboard> | | | | re: Copy Clipboard in file
ok, many thanks
Regards | | | | re: Copy Clipboard in file
"Over" <over@nospam.overwrote in message
news:48e69a41$0$18147$4fafbaef@reader3.news.tin.it ... Quote:
>
Hi
>
it's possible with language C, (Mingw or Djgpp)
copying the clipboard of WinXp into file.txt?
>
which function must be use.
Try something like this:
#include <stdio.h>
#include <windows.h>
char* pastetext(void) {
HWND hwnd=0;
HWND htext;
char *p, *q;
int size;
if (OpenClipboard(hwnd)==0) return NULL;
htext=GetClipboardData(CF_TEXT);
if (htext==0) return NULL;
size=GlobalSize(htext);
q=malloc(size);
if (q==NULL) return NULL;
p=GlobalLock(htext);
memcpy(q,p,size);
GlobalUnlock(htext);
CloseClipboard();
return q;
}
int main(void) {
char *text;
text=pastetext();
if (text!=NULL) {
printf("Clipboard text = <%s>\n",text);
free(text);
}
}
Notes: windows.h means this is not portable C. But if you're using Winxp
anyway... And I don't know if GlobalLock etc are still needed these days;
better check at MSDN or in gdi32 newsgroup.
--
Bartc | | | | re: Copy Clipboard in file
Bartc wrote: Quote:
"Over" <over@nospam.overwrote in message
> Quote:
>it's possible with language C, (Mingw or Djgpp)
>copying the clipboard of WinXp into file.txt?
>>
>which function must be use.
>
Try something like this:
>
#include <stdio.h>
#include <windows.h>
<windows.hdoes not exist in standard C systems. Thus this is
non-portable and off-topic here.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section. | | | | re: Copy Clipboard in file
On Sat, 04 Oct 2008 03:16:32 -0400, CBFalconer wrote: Quote:
Bartc wrote: Quote:
>"Over" <over@nospam.overwrote in message
>> Quote:
>>it's possible with language C, (Mingw or Djgpp) copying the clipboard
>>of WinXp into file.txt?
>>>
>>which function must be use.
>>
>Try something like this:
>>
>#include <stdio.h>
>#include <windows.h>
>
<windows.hdoes not exist in standard C systems.
<windows.hdoes exist in some standard C systems.
Yes, it's off-topic, but off-topic doesn't mean it only exists in other
people's dream worlds. It's real. | | | | re: Copy Clipboard in file
Over wrote: Quote:
Hi
>
it's possible with language C, (Mingw or Djgpp)
copying the clipboard of WinXp into file.txt?
>
which function must be use.
>
Thanks
>
>
>
The clipboard supports several formats. You can retrieve images, text,
or many other types of data. Lets see how to retrieve the most simple
one: text.
// This function will retrieve the text from the clipboard
// if available. Returns the retrieved text or NULL if an
// error occurs.
// The user should free the text with the free() function when it is
// done with it.
char *ImportClipboard(HWND hwnd)
{
HANDLE hClipData;
char *str = NULL;
char * result = NULL;
result = 0;
if (IsClipboardFormatAvailable(CF_TEXT)) {
if (OpenClipboard(hwnd)) {
hClipData = GetClipboardData(CF_TEXT);
if (hClipData) {
str = GlobalLock(hClipData);
result = strdup(str);
GlobalUnlock(hClipData);
}
}
CloseClipboard();
}
return (result);
}
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32 | | | | re: Copy Clipboard in file
many thanks
Regards | | | | re: Copy Clipboard in file
Antoninus Twink wrote: Quote:
(Jacob Navia is the only one able and willing to answer Windows
questions, and he seems to be taking a break from the feverish idiocy of
clc at the moment.)
>
Yes, I am getting tired of this group. But I answered the OP, see
my reply in this thread.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32 | | | | re: Copy Clipboard in file
In article <48E71850.62602C68@yahoo.com>,
CBFalconer <cbfalconer@maineline.netwrote: Quote:
>Bartc wrote: Quote:
>"Over" <over@nospam.overwrote in message
>> Quote:
>>it's possible with language C, (Mingw or Djgpp)
>>copying the clipboard of WinXp into file.txt?
>>>
>>which function must be use.
>>
>Try something like this:
>>
>#include <stdio.h>
>#include <windows.h>
>
><windows.hdoes not exist in standard C systems. Thus this is
>non-portable and off-topic here.
So true, oh wise one.
Let me add my own 2 cents worth as well:
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
--
Useful clc-related links: http://en.wikipedia.org/wiki/Aspergers http://en.wikipedia.org/wiki/Clique http://en.wikipedia.org/wiki/C_programming_language | | | | re: Copy Clipboard in file
On Sat, 04 Oct 2008 11:17:56 +0200, jacob navia wrote: Quote:
The clipboard supports several formats. You can retrieve images, text,
or many other types of data. LetĒs see how to retrieve the most simple
one: text.
// This function will retrieve the text from the clipboard
// if available. Returns the retrieved text or NULL if an
// error occurs.
// The user should free the text with the free() function when it is
// done with it.
char *ImportClipboard(HWND hwnd)
{
HANDLE hClipData;
char *str = NULL;
char * result = NULL;
result = 0;
if (IsClipboardFormatAvailable(CF_TEXT)) {
if (OpenClipboard(hwnd)) {
hClipData = GetClipboardData(CF_TEXT);
if (hClipData) {
str = GlobalLock(hClipData);
result = strdup(str);
GlobalUnlock(hClipData);
}
}
CloseClipboard();
}
return (result);
}
Jacob--
I've never seen a treatment of the clipboard that didn't have the full
trappings of MFC. I had a couple questions, and I'll try to keep them as
topical as they can be.
1) If things like CF_TEXT were given meaning somewhere earlier, along with
functions like GetClipboardData(), could this be standard C? These would
normally find defintions in windows.h (?), but instaed of including a
non-standard header, couldn't you write the above as C99?
2) I can't get my head around char *ImportClipboard(HWND hwnd) . How do
you call this using C instead of the OS distributing a message.
--
Richard Milhous Nixon
All humor is derrived from pain, ergo nothing in Heaven is funny.
~~ Mark Twain | | | | re: Copy Clipboard in file
Richard Nixon wrote: Quote:
On Sat, 04 Oct 2008 11:17:56 +0200, jacob navia wrote:
> Quote:
>The clipboard supports several formats. You can retrieve images, text,
>or many other types of data. LetĒs see how to retrieve the most simple
>one: text.
>// This function will retrieve the text from the clipboard
>// if available. Returns the retrieved text or NULL if an
>// error occurs.
>// The user should free the text with the free() function when it is
>// done with it.
>char *ImportClipboard(HWND hwnd)
>{
> HANDLE hClipData;
> char *str = NULL;
> char * result = NULL;
> result = 0;
> if (IsClipboardFormatAvailable(CF_TEXT)) {
> if (OpenClipboard(hwnd)) {
> hClipData = GetClipboardData(CF_TEXT);
> if (hClipData) {
> str = GlobalLock(hClipData);
> result = strdup(str);
> GlobalUnlock(hClipData);
> }
> }
> CloseClipboard();
> }
> return (result);
>}
>
Jacob--
>
I've never seen a treatment of the clipboard that didn't have the full
trappings of MFC.
You can use the windows API directly, without going through MFC that
will eventually call the windows API anyway. Quote:
I had a couple questions, and I'll try to keep them as
topical as they can be.
>
1) If things like CF_TEXT were given meaning somewhere earlier, along with
functions like GetClipboardData(), could this be standard C?
You can
#define CF_TEXT 1
but rewriting GetClipboardData() would mean to reimplement
the clipboard, i.e. to write ALL the windows API for the
Clipboard.
This is (of course) doable, since Microsoft did it in C. But it
would mean that you write a NEW clipboard, that would not be
recognized by other applications that use the windows clipboard.
One of the BIG problems under linux is precisely that each
program implements its own clipboard and programs do not
exchange clipboard data unless they happen to use the same
clipboard! Quote:
These would
normally find defintions in windows.h (?), but instaed of including a
non-standard header, couldn't you write the above as C99?
>
It *is* C99. Note that a clipboard is associated to a window that
is the owner of the clipboard. That is why the hwnd parameter is
necessary. Quote:
2) I can't get my head around char *ImportClipboard(HWND hwnd) . How do
you call this using C instead of the OS distributing a message.
There is no "message" here. The window is needed to determine
which application owns the clipboard.
A work around is to just use the GetCurrentWindow() API but then,
depending on which window has the focus, you would get a window
that maybe doesn't even belong to your application.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32 | | | | re: Copy Clipboard in file
jacob navia <jacob@nospam.comwrites: Quote:
Richard Nixon wrote:
[...] Quote: Quote:
>These would
>normally find defintions in windows.h (?), but instaed of including a
>non-standard header, couldn't you write the above as C99?
>
It *is* C99. Note that a clipboard is associated to a window that
is the owner of the clipboard. That is why the hwnd parameter is
necessary.
He asked about using C99 *instead of* including a non-standard header.
C99 itself has no clipboard support. To use the clipboard under
Windows, you need to use Windows-specific extensions. The experts on
the topic hang out in comp.os.ms-windows.programmer.win32. jacob,
shouldn't you have mentined that yourself?
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" | | | | re: Copy Clipboard in file
On 6 Oct 2008 at 5:36, jacob navia wrote: Quote:
One of the BIG problems under linux is precisely that each program
implements its own clipboard and programs do not exchange clipboard
data unless they happen to use the same clipboard!
That's not really true in practice.
*Most* programs choose to support the X convention of using the PRIMARY
atom for currently-selected text, and the CLIPBOARD atom for
Windows-style cut/copy/paste menus. Some programs and GUI toolkits also
have their own clipboard arrangements. | | | | re: Copy Clipboard in file
On Oct 6, 12:48*am, Richard Nixon <rich...@example.invalidwrote: Quote:
On Sat, 04 Oct 2008 11:17:56 +0200, jacob navia wrote:
Quote: Quote:
char *ImportClipboard(HWND hwnd)
Quote:
I've never seen a treatment of the clipboard that didn't have the full
trappings of MFC. *I had a couple questions, and I'll try to keep them as
topical as they can be.
>
1) If things like CF_TEXT were given meaning somewhere earlier, along with
functions like GetClipboardData(), could this be standard C? *These would
normally find defintions in windows.h (?), but instaed of including a
non-standard header, couldn't you write the above as C99?
>
2) *I can't get my head around char *ImportClipboard(HWND hwnd) . *How do
you call this using C instead of the OS distributing a message.
These functions simply exist in a DLL file (although this is Windows-
specific library), I think USER32.DLL. Names like CF_TEXT are just
constants.
Given suitable Docs, you can declare your own versions of
ImportClipboard, CF_TEXT etc, without using windows.h. But you might
find you need to use non-standard features to declare such functions,
due to different call conventions, etc.
--
Bartc | | | | re: Copy Clipboard in file
All these codes work perfectly,but if I want to detect whether there
is a change in the clip board content , how can I know ??? | | | | re: Copy Clipboard in file
On Sun, 05 Oct 2008 23:36:59 -0700, Keith Thompson wrote: Quote:
jacob navia <jacob@nospam.comwrites: Quote:
>Richard Nixon wrote:
[...] Quote: Quote:
>>These would
>>normally find defintions in windows.h (?), but instaed of including a
>>non-standard header, couldn't you write the above as C99?
>>
>It *is* C99. Note that a clipboard is associated to a window that
>is the owner of the clipboard. That is why the hwnd parameter is
>necessary.
>
He asked about using C99 *instead of* including a non-standard header.
>
C99 itself has no clipboard support. To use the clipboard under
Windows, you need to use Windows-specific extensions. The experts on
the topic hang out in comp.os.ms-windows.programmer.win32. jacob,
shouldn't you have mentined that yourself?
>
[...]
I hadn't had good luck with ng's that looked like the above (there are
hundreds), but this seems like a viable group.
Indeed, the fella got his clipboard question answered there.
An interesting article on usenet: http://www.computerworld.com/action/...icleId=9116064
--
Richard Milhous Nixon
It is my belief that nearly any invented quotation, played with confidence,
stands a good chance to deceive.
~~ Mark Twain | | | | re: Copy Clipboard in file
asit <lipun4u@gmail.comwrites: Quote:
All these codes work perfectly,but if I want to detect whether there
is a change in the clip board content , how can I know ???
All *what* codes work perfectly?
When you post a followup, please quote enough context so that your
article makes sense to someone who hasn't seen the article to which
you're replying. (Some newsreaders let you see the parent article,
but (a) it can be inconvenient, and (b) I just tried it, and my
newsreader was unable to fetch the parent article.)
As I think you've already been told, standard C does not include any
support for clipboards; any such support is specific to your C
implementation or to your operating system. If I recall correctly,
you're using MS Windows, so your best bet is probably to post to
comp.os.ms-windows.programmer.win32.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" | | | | re: Copy Clipboard in file
"asit" <lipun4u@gmail.comwrote in message
news:11f90113-4daf-4e42-b34e-8dac4ce52dde@v13g2000pro.googlegroups.com... Quote:
All these codes work perfectly,but if I want to detect whether there
is a change in the clip board content , how can I know ???
Copy the current text contents of the clipboard, as a string.
Next time, compare that string with the current contents (bearing in mind
that the clipboard data can also be non-text).
This is not very demanding C.
If you need a /notification/ of a change, you might want to look at www.msdn.com or ask in topical group (.win32?).
--
Bartc | | | | re: Copy Clipboard in file
asit wrote: Quote:
>
All these codes work perfectly,but if I want to detect whether
there is a change in the clip board content, how can I know ???
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section. | | | | re: Copy Clipboard in file
CBFalconer <cbfalconer@yahoo.comwrites: Quote:
asit wrote: Quote:
>>
>All these codes work perfectly,but if I want to detect whether
>there is a change in the clip board content, how can I know ???
>
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
>
More details at: <http://cfaj.freeshell.org/google/>
I told him essentially the same thing (though without the URL) more
than 8 hours before your followup.
I encourage you to find a way to read Usenet that allows you to check
for other followups before posting. The details are, of course,
off-topic.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" | | | | re: Copy Clipboard in file
On Sun, 5 Oct 2008 17:48:26 -0600, Richard Nixon
<richard@example.invalidwrote: Quote:
On Sat, 04 Oct 2008 11:17:56 +0200, jacob navia wrote:
<snip: accessing Windows clipboard>
Windows itself is offtopic here, but the general concepts of accessing
'system' (OS, layered, etc.) code I consider to be sufficiently on. Quote:
I've never seen a treatment of the clipboard that didn't have the full
trappings of MFC. I had a couple questions, and I'll try to keep them as
topical as they can be.
>
1) If things like CF_TEXT were given meaning somewhere earlier, along with
functions like GetClipboardData(), could this be standard C? These would
normally find defintions in windows.h (?), but instaed of including a
non-standard header, couldn't you write the above as C99?
>
Constants like CF_TEXT, and some simple macros, would be defined in
windows.h (or some variant or piece of it), but routines would only be
_declared_ there, and _defined_ (implemented) as object code in a
library -- for WinAPI routines specifically, a DLL such as gdi32.dll .
You could write the first three of these in standard C (or at least
standard C with minor extensions like __stdcall) yourself, if you
wanted. But they would be of no use without the callable routine(s),
and you won't be able to write those in standard C, at least not
entirely, because they depend on accessing OS features. Moreover the
parts you can write yourself are of no value -- even negative value --
if they aren't consistent with the callable routines, so it is a
Really Good Idea to use the .h file(s) supplied (at least originally)
by the same people who supplied the routines -- in this case, MS.
- formerly david.thompson1 || achar(64) || worldnet.att.net | | | | re: Copy Clipboard in file
In article <amk5f49238fro5pbddivl93dg4fkur7h90@4ax.com>,
David Thompson <dave.thompson2@verizon.netwrote:
.... Quote:
>You could write the first three of these in standard C (or at least
>standard C with minor extensions like __stdcall) yourself, if you
>wanted. But they would be of no use without the callable routine(s),
>and you won't be able to write those in standard C, at least not
>entirely, because they depend on accessing OS features. Moreover the
>parts you can write yourself are of no value -- even negative value --
>if they aren't consistent with the callable routines, so it is a
>Really Good Idea to use the .h file(s) supplied (at least originally)
>by the same people who supplied the routines -- in this case, MS.
No, no, no. You've got it all wrong.
It is established CLC dogma that it is a Good Thing, that adds value to
the world, to write your own versions of OS functions, so that they be
now done in conforming, religiously, pedantically, dogmatically,
CLC-correct form.
For example, see RH's approved version of sleep().
The only version of sleep() that he has ever used (and, of course, the
only version you should ever use - if you want to be a member of the
He-Man CLC society). |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|