For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > CHARFORMAT::dwReserved ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CHARFORMAT::dwReserved ?
Bonj

2005-05-31, 9:14 am

Hi
In writing a syntax highlighter, I want to be able to tell whether a certain
portion of text in the richedit control is block comments or line comments.
However these will both be the same color. Is there any reason why I
shouldn't use the dwReserved flag of the CHARFORMAT structure? It says in
the documentation 'reserved - must be zero'. But does that actually mean
'reserved - completely ignored' ?


Bonj

2005-05-31, 9:14 am

or would it be better to define my 'own' CHARFORMAT2?
I notice that CHARFORMAT2 is bigger than CHARFORMAT, so it must allow enough
space for that...
would it be legitimate to do
typedef struct tagMYCHARFORMAT
{
CHARFORMAT cf;
LONG myowndata;
} MYCHARFORMAT, *LPMYCHARFORMAT;

MYCHARFORMAT mycf;
mycf.cf.cbSize = sizeof(MYCHARFORMAT);
SendMessage(hWndRTB, EM_SETCHARFORMAT, TRUE, (LPARAM)(&mycf));

as long as I sort the dwMask member out correctly?

....??
(when I say 'legitimate', I mean 'the technique couldn't fail in future
versions of windows', not necessarily guaranteed, but logically determined)

"Bonj" <a@b.com> wrote in message
news:%23eoElQbZFHA.3780@tk2msftngp13.phx.gbl...
> Hi
> In writing a syntax highlighter, I want to be able to tell whether a
> certain portion of text in the richedit control is block comments or line
> comments. However these will both be the same color. Is there any reason
> why I shouldn't use the dwReserved flag of the CHARFORMAT structure? It
> says in the documentation 'reserved - must be zero'. But does that
> actually mean 'reserved - completely ignored' ?
>
>



Igor Tandetnik

2005-06-02, 4:01 pm

"Bonj" <a@b.com> wrote in message
news:%23eoElQbZFHA.3780@tk2msftngp13.phx.gbl
> In writing a syntax highlighter, I want to be able to tell whether a
> certain portion of text in the richedit control is block comments or
> line comments. However these will both be the same color. Is there
> any reason why I shouldn't use the dwReserved flag of the CHARFORMAT
> structure? It says in the documentation 'reserved - must be zero'.


Sounds like reason enough to me. What part of "must" do you have
difficulty understanding?

> But does that actually mean 'reserved - completely ignored' ?


It may be completely ignored now, but used for something in the next
version, and your application will break.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Igor Tandetnik

2005-06-02, 4:01 pm

"Bonj" <a@b.com> wrote in message
news:OYDlQXbZFHA.1368@tk2msftngp13.phx.gbl
> or would it be better to define my 'own' CHARFORMAT2?
> I notice that CHARFORMAT2 is bigger than CHARFORMAT, so it must allow
> enough space for that...
> would it be legitimate to do
> typedef struct tagMYCHARFORMAT
> {
> CHARFORMAT cf;
> LONG myowndata;
> } MYCHARFORMAT, *LPMYCHARFORMAT;
>
> MYCHARFORMAT mycf;
> mycf.cf.cbSize = sizeof(MYCHARFORMAT);
> SendMessage(hWndRTB, EM_SETCHARFORMAT, TRUE, (LPARAM)(&mycf));


Why don't you try it? Most likely it won't work. The control expects
cbSize to be either sizeof(CHARFORMAT) or sizeof(CHARFORMAT2). It knows
what to do with these two. If it gets a size it does not expect, it will
probably reject the message.

Even if the control accepts the message, I don't believe it would
actually store the data it does not understand. In other words, I don't
think you would be able to later get your data back with
EM_GETCHARFORMAT, which appears to be the only point of the exercise.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Bonj

2005-06-05, 3:58 am

I have ended up using the sStyle bit of the CHARFORMAT2, and it works fine.


"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:e9Ijc$2ZFHA.720@TK2MSFTNGP15.phx.gbl...
> "Bonj" <a@b.com> wrote in message
> news:OYDlQXbZFHA.1368@tk2msftngp13.phx.gbl
>
> Why don't you try it? Most likely it won't work. The control expects
> cbSize to be either sizeof(CHARFORMAT) or sizeof(CHARFORMAT2). It knows
> what to do with these two. If it gets a size it does not expect, it will
> probably reject the message.
>
> Even if the control accepts the message, I don't believe it would actually
> store the data it does not understand. In other words, I don't think you
> would be able to later get your data back with EM_GETCHARFORMAT, which
> appears to be the only point of the exercise.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com