Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Data formatting text

26 views
Skip to first unread message

Bertram

unread,
Mar 27, 2013, 7:52:23 AM3/27/13
to


Hi all

I compile with MinGW, the simple programm console, that read
text from clipboard, open a file, and write text in to file.

The question is:

Why the text write in file, lost formatting?

Thanks

Regards




Jongware

unread,
Mar 27, 2013, 8:18:04 AM3/27/13
to
What formatting exactly? If you mean formatting such as fonts and text
sizes, those do not carry over in a plain text file. Simple formatting
such as tabs, spaces, and hard returns do.

[Jw]

Ulrich Eckhardt

unread,
Mar 27, 2013, 8:50:45 AM3/27/13
to
Am 27.03.2013 12:52, schrieb Bertram:
> I compile with MinGW, the simple programm console, that read
> text from clipboard, open a file, and write text in to file.
>
> The question is:
>
> Why the text write in file, lost formatting?

I'd rather ask whether the text in the clipboard lost the formatting
already. If not, the clipboard is irrelevant and it's really just the
writing of the text file. In that case, I'd ask what the actual content
is that you wrote and the content that was written. Note that things
like line-endings can cause confusion, so use a hex editor (maybe mingw
has a "hd" or "hexdump" utility) to look at the file contents.

If all this doesn't give you a hint in the right direction, please
condense your code to the smallest minimum and provide exact steps to
reproduce the problem. The primary info is also what you saw, while your
interpretation "lost formatting" is only of secondary important.

Uli


Bertram

unread,
Mar 27, 2013, 9:52:04 AM3/27/13
to
For formatting intend to, return, space, tab, new line, ect

The cose is:

char *y, *z;

int size;

if (OpenClipboard(hwnd)==0) return NULL;

htext=GetClipboardData(CF_TEXT);

if (htext==0) return NULL;

size=GlobalSize(htext);

z=malloc(size);

if (q==NULL) return NULL;

y=GlobalLock(htext);

memcpy(q,p,size);



...



Regards



Rick C. Hodgin

unread,
Mar 27, 2013, 12:45:01 PM3/27/13
to
See this page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx

It shows the various formats that can be retrieved from the data on the clipboard. You can try to read it in various binary ways, otherwise it will be returned in text.

If you need to do something special with the clipboard in your own application, sometimes you can paste text information about binary objects to the clipboard, which will then be posted and retrieved as text, but they can be parsed to reference a file on disk, or the handle of a named pipe, etc. These things will let you communicate complex data back-and-forth via the generic clipboard.

Best regards,
Rick C. Hodgin

Bertram

unread,
Mar 28, 2013, 9:48:24 AM3/28/13
to

"Jongware" <jong...@no-spam.plz> ha scritto nel messaggio
news:5152e381$0$6886$e4fe...@news2.news.xs4all.nl...
In the text, are missing return, the tab and space are present.
The text write in the file, is a long line the alfanumeric characters.

Regards



Jongware

unread,
Mar 29, 2013, 5:29:14 AM3/29/13
to
That sounds like your plain text viewer does not understand the
end-of-line sequence that you are writing. Most plain text software is
aware of the different options, but Notepad, to name a likely candidate,
does not care about anything else than *just* the magical 'Windows'
combination "Carriage Return/Linefeed" (hex codes: 0x0D 0x0A).

It would not be unreasonable to expect the Clipboard automatically
converting hard returns into "Windows format" -- at least for the Plain
Text Clipboard Format --, but apparently it does not.

So if you want your plain text to be Notepad-compatible, you have to
scan for either 0x0D *or* 0x0A codes, and replace each of them with the
sequence '0x0D+0x0A), before writing to a file.

Before you do so, inspect one of your current text files with a Hex
Viewer. Of course it's also possible you have something weird in your
code, or on your clipboard, and the reason you don't get to see hard
returns is because there *are* no hard returns of any kind in your file.

[Jw]
0 new messages