PSet and SetPixel Bug

M

Mike Williams

I've just come across what appears to be a very interesting little bug in
the VB Pset method when drawing to either a Form or PictureBox (Autoredraw =
False). At first I thought it might be just something to do with VB itself,
but the bug also appears to exists in the GDI SetPixel function, which of
course the VB Pset method uses.

I don't normally set pixels individually on bitmaps and when I do I usually
use much faster methods than SetPixel so it is probably quite some time
since I have used Pset or SetPixel and I don't therefore know how long the
bug has existed on my system. I'm sure that if it was a long time I would
have come across it before though, so I expect it is something new, perhaps
something to do with Vista or one of its updates, although it could of
course be a hardware problem on my own system that I've not noticed before.

The bug causes the pixel to fail to be drawn for certain values of X
coordinate (pixels) but not for others. A quick test seems to indicate that
it fails to be drawn whenever bit 8 of X is set. For example, X values of 0
to &HFF, &H200 to &H2FF and &H400 to &H4FF work fine but X values of &H100
to &H1FF and &H300 to &H3FF do not. For example, if I attempt to use
SetPixel (or the GDI Pset function) to draw a horizontal line on a maximized
Form I get a "dashed" line where the width of the individual lines and
spaces is 256 pixels.

The problem does not exist on an Autoredraw Form or PictureBox, and neither
does it exists for any values of the Y coordinate whether Autoredraw is on
or not. It is just non Autoredraw and X coordinates that seem to have the
problem. This is such an unusual thing that it would almost certainly have
been noticed by lots of other people had it been in existence for any length
of time, so I'm beginning to think that it might be just my own particular
combination of hardware and software and drivers that is causing the
problem. I'm currently using Vista Home Edition with Service Pack 1 and
which is regularly updated on a Intel Core2 Quad Q6600 processor and an ATI
Radeon HD 4850 graphics card. I'm using VB6 with Service Pack 6 installed
(perhaps Service Pack 6 is the cause of the problem?).

There is some simple test code below which, on my system, produces the fault
I have described. Just paste the code into a VB Form containing a Command
Button and run the program and click the button. I really would appreciate
it if anyone here would be prepared to try it on their own system and report
the result. On my system both the blue and the red horizontal lines are
"dashed lines" with 256 pixel wide dashes and spaces, instead of the
continuous horizontal lines that I was expecting.

The code is so straight forward that I can't believe I've done something
wrong myself, although I am getting a bit long in the tooth these days and
my brain is not quite as agile as it used to be so it is always possible
that I've slipped up! If anyone notices a problem with my code then I would
appreciate it if you would let me know.

Mike

Option Explicit
Private Declare Function SetPixel Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal crColor As Long) As Long

Private Sub Form_Load()
Me.WindowState = vbMaximized
Me.AutoRedraw = False
Me.ScaleMode = vbPixels
End Sub

Private Sub Command1_Click()
Dim x As Long
For x = 0 To Me.ScaleWidth
Me.PSet (x, 10), vbBlue
SetPixel Me.hdc, x, 20, vbRed
Next x
End Sub
 
A

Armin Zingler

Mike said:
The problem does not exist on an Autoredraw Form or PictureBox, and
neither does it exists for any values of the Y coordinate whether
Autoredraw is on or not. It is just non Autoredraw and X coordinates
that seem to have the problem. This is such an unusual thing that it
would almost certainly have been noticed by lots of other people had
it been in existence for any length of time, so I'm beginning to
think that it might be just my own particular combination of hardware
and software and drivers that is causing the problem. I'm currently
using Vista Home Edition with Service Pack 1 and which is regularly
updated on a Intel Core2 Quad Q6600 processor and an ATI Radeon HD
4850 graphics card. I'm using VB6 with Service Pack 6 installed
(perhaps Service Pack 6 is the cause of the problem?).

Problem does not exist here. (HD 3850+Catalyst 8.12, XP/SP3)

BTW, a VB6 group would have been the better place to post to.


Armin
 
M

Mike Williams

Problem does not exist here. (HD 3850+Catalyst 8.12, XP/SP3)
BTW, a VB6 group would have been the better place to post to.

Sorry about that. I appear to have clicked New Message in the wrong group
:-( For any others here, please kindly ignore my post to this group.
Thanks.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top