Shifty Maths

  • Thread starter Thread starter Jeff Gaines
  • Start date Start date
J

Jeff Gaines

I am writing a custom Rich Text Box based on the Windows Forms control.

I need to set up a PARAFORMAT2 structure then call SendMessage.

In the help it says:
wBorders
Border location, style, and color. Bits 0 to 7 specify the border
locations, bits 8 to 11 specify the border style, and bits 12 to 15
specify the border color index.
and
Specify the border style using one of the following values for bits 8 to 11.
(list of numbers)
and
Specify the border color using one of the following values for bits 12 to
15.
(list of numbers)

Although I have used bitwise AND and OR I have never used shift so...
The border colour for red is 5 and that needs to go in bits 12 to 15 - can
I use:
5 << 12 ?

I have tried it without success - otherwise I guess the answer would be
'yes'.

I will try later to work it out on paper but at the moment it is making my
brain hurt so I'd appreciate knowing if it's as simple as 5 << 12 or if I
need to get even closer to the electrons.

Many thanks.
 
Jeff Gaines said:
I am writing a custom Rich Text Box based on the Windows Forms control.

I need to set up a PARAFORMAT2 structure then call SendMessage.

In the help it says:
wBorders
Border location, style, and color. Bits 0 to 7 specify the border
locations, bits 8 to 11 specify the border style, and bits 12 to 15
specify the border color index.
and
Specify the border style using one of the following values for bits 8 to 11.
(list of numbers)
and
Specify the border color using one of the following values for bits 12 to
15.
(list of numbers)

Although I have used bitwise AND and OR I have never used shift so...
The border colour for red is 5 and that needs to go in bits 12 to 15 - can
I use:
5 << 12 ?

Yes.
w.wBorders = (5 << 12) | (2 << 8) | 15;

Since the fields don't overlap, you can also use + instead of |.

Did you set PFM_BORDER in dwMask?
 
Yes.
w.wBorders = (5 << 12) | (2 << 8) | 15;

Since the fields don't overlap, you can also use + instead of |.

Did you set PFM_BORDER in dwMask?

Many thanks Tim :-)

I think I misunderstood the PFM_BORDER flag, I wanted to set a margin but
I don't think that's the way to do it.

My numbering is fine but it stops at 254 - when loading a file it just
repeats 254 as the line number once it has reached it. When adding lines
it leaves a blank so I guess something is over-flowing.

Interestingly grepping for PFM_NUMBERING in the VS2008 directory produces
no hits, I found them in some old header files. It makes me wonder if they
are no longer supported?
 
Jeff Gaines said:
I think I misunderstood the PFM_BORDER flag, I wanted to set a margin but
I don't think that's the way to do it.

No, PFM_BORDER draws lines at the edges, like the cell borders in Excel.
Interestingly grepping for PFM_NUMBERING in the VS2008 directory produces
no hits, I found them in some old header files. It makes me wonder if they
are no longer supported?

No, it's still supported. It's still in the Windows 7 SDK.

The issue is that, starting in VS2008, they no longer include the Platform
SDK files in the VS directory. This has changed many times over the years.
In VC98, the SDK includes files were in the Include directory along with
the CRT files. In VS2002, they moved the SDK files to PlatformSDK\Include,
so only the CRT files were in Include. This remained true until VS2008;
now the PlatformSDK files are separate. On my machine, they're in \Program
Files\Microsoft SDKs\Windows\6.0A.

One of my pet peeves is that they do not ASK me where I want those
installed. I do most of my work in the command line, so I want my commonly
used paths to be short. I put the SDKs in \Data\SDK\(version).
 
Back
Top