CListCtrl column format
Christian Rosner -- crosner@csci.csc.com
Monday, December 02, 1996
Environment: VC++ 4.2b, Win 95
Hi,
I'm having two problems using the column format feature of the CListCtrl.
First, if I try to set the first column to a right-justified format (using
CListCtrl::InsertColumn() either with an LV_COLUMN or the nFormat
parameter), it is displayed left justified. Setting the second or third
column works fine, but the first column seems to refuse that (but I
get no error code!).
Second, querying the column format of an existing column doesn't
seem to work too. If I call GetColumn() for any column like in
LV_COLUMN Column;
Column.mask = LVCF_FMT;
GetColumn(ColumnNo,&Column);
if (Column.fmt == LVCFMT_LEFT)
{
// do some work ...
}
I always get the return value 16384 and my code within the if-statement is
never executed. The return value 16384 doesn't make sense to me and doesn't
match any LVCFMT_ constant.
Do I make a mistake or is there an error in the CListCtrl column format
methods? Has anyone already used a first right-justified column in a
CListCtrl?
Christian Rosner
--------------
crosner@csci.csc.com
Bryan Schilling -- brsclv@execpc.com
Wednesday, December 04, 1996
[Mini-digest: 3 responses]
Christian Rosner wrote:
>
> Environment: VC++ 4.2b, Win 95
>
> Hi,
>
> I'm having two problems using the column format feature of the CListCtrl.
>
> First, if I try to set the first column to a right-justified format (using
> CListCtrl::InsertColumn() either with an LV_COLUMN or the nFormat
> parameter), it is displayed left justified. Setting the second or third
> column works fine, but the first column seems to refuse that (but I
> get no error code!).
>
> Second, querying the column format of an existing column doesn't
> seem to work too. If I call GetColumn() for any column like in
>
> LV_COLUMN Column;
> Column.mask = LVCF_FMT;
> GetColumn(ColumnNo,&Column);
> if (Column.fmt == LVCFMT_LEFT)
> {
> // do some work ...
> }
>
> I always get the return value 16384 and my code within the if-statement is
> never executed. The return value 16384 doesn't make sense to me and doesn't
> match any LVCFMT_ constant.
>
> Do I make a mistake or is there an error in the CListCtrl column format
> methods? Has anyone already used a first right-justified column in a
> CListCtrl?
>
> Christian Rosner
>
> --------------
> crosner@csci.csc.com
Somewhere in the VC++ help, it states that the left-most column will
always be left-justified. To get around this, you might consider
creating the left column to the smallest width possible in your
circumstance (depending on the image used, if any) and setting the text
for the column to "" (i.e. nothing).
-----From: Mike Blaszczak
At 15:51 12/2/96 -0500, Christian Rosner wrote:
>Environment: VC++ 4.2b, Win 95
>Do I make a mistake or is there an error in the CListCtrl column format
>methods? Has anyone already used a first right-justified column in a
>CListCtrl?
The mistake you're making is not reading the documentation. The docs
for LV_COLUMN say "The leftmost column in a list view control must be
left aligned." right where the fmt member is described.
Your experience doesn't demonstrate a bug in MFC.
.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.
-----From: Mark_Eastman@qsp.co.uk (Mark Eastman)
If you look in the help for LV_COLUMN you will find that it states
that the left most column of a ListCtrl can only be left justified.
I tried the GetColumn and it appears that the result in Column.fmt is
the format anded with hex 0x4000. I don't know why this bit is set,
maybe someone could explain why. A fix would be
if ((Column.fmt & 0x00FF) == LVCFMT_LEFT)
MarkE@qsp.co.uk
______________________________ Reply Separator _________________________________
Subject: CListCtrl column format
Author: "Christian Rosner" at internet
Date: 02/12/96 20:51
Environment: VC++ 4.2b, Win 95
Hi,
I'm having two problems using the column format feature of the CListCtrl.
First, if I try to set the first column to a right-justified format (using
CListCtrl::InsertColumn() either with an LV_COLUMN or the nFormat
parameter), it is displayed left justified. Setting the second or third
column works fine, but the first column seems to refuse that (but I
get no error code!).
Second, querying the column format of an existing column doesn't
seem to work too. If I call GetColumn() for any column like in
LV_COLUMN Column;
Column.mask = LVCF_FMT;
GetColumn(ColumnNo,&Column);
if (Column.fmt == LVCFMT_LEFT)
{
// do some work ...
}
I always get the return value 16384 and my code within the if-statement is
never executed. The return value 16384 doesn't make sense to me and doesn't
match any LVCFMT_ constant.
Do I make a mistake or is there an error in the CListCtrl column format
methods? Has anyone already used a first right-justified column in a
CListCtrl?
Christian Rosner
--------------
crosner@csci.csc.com
Mike Blaszczak -- mikeblas@nwlink.com
Saturday, December 07, 1996
At 23:51 12/4/96 -0600, Bryan Schilling wrote:
>-----From: Mark_Eastman@qsp.co.uk (Mark Eastman)
> I tried the GetColumn and it appears that the result in Column.fmt is
> the format anded with hex 0x4000.
I think you might mean "ored" instead of "anded".
> I don't know why this bit is set,
> maybe someone could explain why. A fix would be
> if ((Column.fmt & 0x00FF) == LVCFMT_LEFT)
That bit isn't documented. Testing for equality on a bunch of flags is
an ill-fated endeavour. The code should have originally been written as:
if (Column.fmt & LVCFMT_LEFT)
{
// we're left-alignged!
}
If you really have to test for equality, for some sick reason, you should
mask the bits you're interested in, at least:
if ((Colum.fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
{
// we're left-aligned!
}
to avoid problems later. LVCFMT_JUSTIFY mask is lots less bits than 0x00FF.
This kind of thing might seem pedantic, but it's important to make sure you've
coded in a way that makes your code live longer in adverse conditions... like
COMCTL32.DLL changing more rapidly than your application changes.
.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.
Gonzalo Isaza -- gonzaloi@microsoft.com
Friday, March 14, 1997
On your first issue: The leftmost column always needs to be left
aligned, by design.
On the second issue, you don't verify the return value for GetColumn.
If the return value is FALSE, the information on column.fmt is going to
be bogus. Since you do not provide enough information there is no way
to determine what is wrong.
Gonzalo
I don't speak for Microsoft. I speak for myself
> -----Original Message-----
> From: Christian Rosner [SMTP:crosner@csci.csc.com]
> Sent: Monday, December 02, 1996 12:51 PM
> To: MFC mailing list
> Subject: CListCtrl column format
>
> Environment: VC++ 4.2b, Win 95
>
> Hi,
>
> I'm having two problems using the column format feature of the
> CListCtrl.
>
> First, if I try to set the first column to a right-justified format
> (using
> CListCtrl::InsertColumn() either with an LV_COLUMN or the nFormat
> parameter), it is displayed left justified. Setting the second or
> third
> column works fine, but the first column seems to refuse that (but I
> get no error code!).
>
> Second, querying the column format of an existing column doesn't
> seem to work too. If I call GetColumn() for any column like in
>
> LV_COLUMN Column;
> Column.mask = LVCF_FMT;
> GetColumn(ColumnNo,&Column);
> if (Column.fmt == LVCFMT_LEFT)
> {
> // do some work ...
> }
>
> I always get the return value 16384 and my code within the
> if-statement is
> never executed. The return value 16384 doesn't make sense to me and
> doesn't
> match any LVCFMT_ constant.
>
> Do I make a mistake or is there an error in the CListCtrl column
> format
> methods? Has anyone already used a first right-justified column in a
> CListCtrl?
>
> Christian Rosner
>
> --------------
> crosner@csci.csc.com
>
Become an MFC-L member
| Вернуться в корень Архива
|