4

I've got an old VB6 program that hasn't changed in a while but now has a new behavior. I'm thinking a common component was upgraded from underneath it. Here are the details.

I've got a standard ListView control in SmallIcon mode. Code snippet:

'setup the listview
With lvwMap
   .Appearance = ccFlat
   .BackColor = vbBlack
   .BorderStyle = ccNone
   .Font.Name = "Arial" 
   .Font.Bold = True
   .Font.Size = 9
   .ForeColor = vbYellow
   .LabelEdit = lvwManual
   .LabelWrap = True
   .OLEDropMode = ccOLEDropManual
   .PictureAlignment = lvwTopLeft
   .TextBackground = lvwOpaque
   .View = lvwSmallIcon
End With

Most ListItems that are added have both an SmallIcon and a Caption (Text). The TextBackground is set as Opaque, meaning the text is rendered in an enclosing colored rectangle.

Some items though may not have a caption provided or the user can change it such that there is no caption. This used to be fine, with just the SmallIcon showing. But now any ListItem that has an empty Text property renders a fairly wide enclosing rectangle with no text inside (as if a user keyed in a bunch of spaces perhaps).

The code to add a ListItem is straight-forward:

 Set oLI = lvwMap.ListItems.Add(lvwMap.ListItems.Count + 1, Key:=sKey)
 oLI.SmallIcon = sIcon
 oLI.Text = sCaption

I stopped the debugger here and thried the following in the immediate window:

oLI.Text= "AAAAAAA"
?oLI.Width
 100.0063 

oLI.Text= "AAAAAA"
?oLI.Width
 91.99371 

oLI.Text= "AAAAA"
?oLI.Width
 84.0189 

oLI.Text= "AAAA"
?oLI.Width
 76.0063 

oLI.Text= "AA"
?oLI.Width
 60.0189 

oLI.Text= "A"
?oLI.Width
 52.0063 

oLI.Text= ""
?oLI.Width
 96.00001 

As you can see the ListItem.Width correctly recalculates until the Text becomes empty and then jumps to 96 pixels.

Does anyone know any way to compensate for this behavior? Some windows message I can use to configure the default empty wdith? Any information on a change to ListView behavior might be helpful as well.

Deanna
  • 23,876
  • 7
  • 71
  • 156
tcarvin
  • 10,715
  • 3
  • 31
  • 52

1 Answers1

2

Mscomctl.ocx was updated in April to fix a security vulnerability in IE – and I'm guessing this is when its behaviour changed as I have a VM machine with an older version of the file (from 2004) that doesn't behave this way and I'm pretty sure that was the last release before the recent one.

As for what to do about it: well, I guess that depends on what it is about it that's causing you a problem. If it's because you're using the item's width property you could easily just multiply it with a Boolean evaluation, like this: iWidth = oLi.Width * Abs(oLi.Text <> ""). But if it's the appearance of it you don't like, the only thing I can think of is to mitigate the effect by adding a single space when/if the user sets it to empty. From a usage point of view the new behaviour is probably better if label editing is enabled, as it provides a wider area to click in.

Deanna
  • 23,876
  • 7
  • 71
  • 156
Antagony
  • 1,750
  • 12
  • 17
  • What is causing a problem is that the label is opaque. Picture yellow text on a black bounding rectangle exactly the right size to encapsulatethe text. This is required because the ListView itself has a background image. But now the icons with no text have these great big (almost 100 px), ugly, empty bars floating next to them. It is the icons, and their position that is most important. The text is optional. Also, the text is not edited by clicking on it, so that is not important. I wonder if I can manually deploy a version of this ocx in a side-by-side/local configuration. – tcarvin May 22 '12 at 14:42
  • @tcarvin Right, sorry, I hadn't fully appreciated the effect of the TextBackground property, as the ListView I tried it with didn't have a background picture – I see what you mean now. Interesting idea to try and run it with an older local version of the ocx side-by-side. I tried something similar once, to make a small portable application, but I gave up when it proved to be more difficult than I thought it was worth. :-). So good luck with that and please let us know how you get on. – Antagony May 23 '12 at 11:36
  • I don't suppose you could put that older version of the ocx some place I could download it? – tcarvin May 23 '12 at 11:56
  • @tcarvin You can download it directly from Microsoft, [here](http://www.microsoft.com/en-us/download/details.aspx?id=10019). Then instead of running the installer use something like 7zip to extract just the mscomctl ocx. – Antagony May 23 '12 at 13:55
  • 7zip can bust open an exe installer?...confirmed, great! Now I just have to see if I can SxS it – tcarvin May 25 '12 at 12:47
  • I ended up using dll redirection instead because it was easier. At some point I'll tackle the manafest issue and do it right with SxS – tcarvin May 25 '12 at 13:19