ExtCreatePen does not work in Windows 2000 but works in Windows 98 
Author Message
 ExtCreatePen does not work in Windows 2000 but works in Windows 98

I am using geometric type of pen for drawing sqaure (end cap) lines using
ExtCreatePen.

The below function works in Windows 98 but does not work in Windows 2000.

'
'   API Declaration
'
Private Declare Function ExtCreatePen Lib "gdi32" _
      (ByVal dwPenStyle&, ByVal dwWidth&, _
      lplb As Any, dwStyleCount As Any, lpStyle As Any) As Long

'
'   Types
'
Private Type LOGBRUSH
   lbStyle As Long
   lbColor As Long
   lbHatch As Long
End Type

Function DrawLine(ByRef picBox As PictureBox, _
                        ByVal x1 As Long, y1 As Long, _
                        ByVal X2 As Long, Y2 As Long, _
                        ) as Boolean
   Dim old_pen          As Long
   Dim new_pen          As Long
   Dim pen_style        As Long
   Dim log_brush        As LOGBRUSH

   Const PS_ENDCAP_SQUARE = &H100
   Const PS_JOIN_MITER = &H2000
   Const PS_SOLID = 0
   Const BS_SOLID = 0

   log_brush.lbColor = RGB(200,0,0)
   log_brush.lbHatch = 0
   log_brush.lbStyle = BS_SOLID

   pen_style = PS_GEOMETRIC + PS_ENCAP_SQUARE + PS_JOIN_MITER + PS_SOLID

   '
   ' ExtCreatePen returns a hDC for the created pen.
   ' if it does not succeed it will return 0 (zero).
   '
   new_pen = ExtCreatePen(pen_style, _
         10, _
         log_brush, _
         Null, _
         Null)

   '
   '  If pen is not created, use the primitive method.
   '
   If new_pen = 0 Then
      DrawLine = False
      Exit Function
   End If

   old_pen = SelectObject(picBox.hdc, _
         new_pen)

   BeginPath picBox.hdc

   MoveToEx picBox.hdc, x1, y1, Null
   LineTo picBox.hdc, X2, Y2

   EndPath picBox.hdc

   StrokePath picBox.hdc
   SelectObject picBox.hdc, old_pen
   DeleteObject new_pen

   DrawLine = True

End Function

In Windows 2000, ExtCreatePen does not return the handle to the pen that is
it does not succeed in creating a pen and hence returns 0.

If any one can help please let me know.

Thanks

Rupesh Kokal.



Sat, 04 Sep 2004 11:46:00 GMT  
 ExtCreatePen does not work in Windows 2000 but works in Windows 98
I just noticed you're adding the pen styles. That ain't right. They must be
Bitwise OR'd together
I can't remember what the bitwise OR operator is in VB, but you'll find it.
Windows 2000 is stricter on what you feed it. It'll generally inform you
better than w98 if you've given
it bad input. Chances are, you're not constructing your pen correctly in 98
but it just happens to pass through.


Quote:
> I am using geometric type of pen for drawing sqaure (end cap) lines using
> ExtCreatePen.

> The below function works in Windows 98 but does not work in Windows 2000.

> '
> '   API Declaration
> '
> Private Declare Function ExtCreatePen Lib "gdi32" _
>       (ByVal dwPenStyle&, ByVal dwWidth&, _
>       lplb As Any, dwStyleCount As Any, lpStyle As Any) As Long

> '
> '   Types
> '
> Private Type LOGBRUSH
>    lbStyle As Long
>    lbColor As Long
>    lbHatch As Long
> End Type

> Function DrawLine(ByRef picBox As PictureBox, _
>                         ByVal x1 As Long, y1 As Long, _
>                         ByVal X2 As Long, Y2 As Long, _
>                         ) as Boolean
>    Dim old_pen          As Long
>    Dim new_pen          As Long
>    Dim pen_style        As Long
>    Dim log_brush        As LOGBRUSH

>    Const PS_ENDCAP_SQUARE = &H100
>    Const PS_JOIN_MITER = &H2000
>    Const PS_SOLID = 0
>    Const BS_SOLID = 0

>    log_brush.lbColor = RGB(200,0,0)
>    log_brush.lbHatch = 0
>    log_brush.lbStyle = BS_SOLID

>    pen_style = PS_GEOMETRIC + PS_ENCAP_SQUARE + PS_JOIN_MITER + PS_SOLID

>    '
>    ' ExtCreatePen returns a hDC for the created pen.
>    ' if it does not succeed it will return 0 (zero).
>    '
>    new_pen = ExtCreatePen(pen_style, _
>          10, _
>          log_brush, _
>          Null, _
>          Null)

>    '
>    '  If pen is not created, use the primitive method.
>    '
>    If new_pen = 0 Then
>       DrawLine = False
>       Exit Function
>    End If

>    old_pen = SelectObject(picBox.hdc, _
>          new_pen)

>    BeginPath picBox.hdc

>    MoveToEx picBox.hdc, x1, y1, Null
>    LineTo picBox.hdc, X2, Y2

>    EndPath picBox.hdc

>    StrokePath picBox.hdc
>    SelectObject picBox.hdc, old_pen
>    DeleteObject new_pen

>    DrawLine = True

> End Function

> In Windows 2000, ExtCreatePen does not return the handle to the pen that
is
> it does not succeed in creating a pen and hence returns 0.

> If any one can help please let me know.

> Thanks

> Rupesh Kokal.



Sat, 04 Sep 2004 21:28:41 GMT  
 ExtCreatePen does not work in Windows 2000 but works in Windows 98

Quote:
> I just noticed you're adding the pen styles. That ain't right. They must
be
> Bitwise OR'd together
> I can't remember what the bitwise OR operator is in VB,

"Or", surprisingly ;)

Quote:
> but you'll find it.
> Windows 2000 is stricter on what you feed it. It'll generally inform you
> better than w98 if you've given it bad input.

Flags should never overlap bit places though and as such simple addition is
usually equally valid (And produces the same result)

'***
FlagA = &H1 '0001
FlagB = &H2 '0010
FlagC = &H4 '0100
FlagD = &H8 '1000

'Either way returns 11 (1011)
MsgBox FlagA + FlagB + FlagD
MsgBox FlagA Or FlagB Or FlagD
'***

Quote:
> Chances are, you're not constructing your pen correctly in 98
> but it just happens to pass through.

Have a look at what GetLastError() brings back and have a look at the
doccumentnation over on Http://msdn.microsoft.com/library/ or on
Http://www.allapi.net/
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Sat, 04 Sep 2004 22:31:24 GMT  
 ExtCreatePen does not work in Windows 2000 but works in Windows 98
[irrelevant groups removed]

Rupesh,

Quote:
>The below function works in Windows 98 but does not work in Windows 2000.

>'
>'   API Declaration
>'
>Private Declare Function ExtCreatePen Lib "gdi32" _
>      (ByVal dwPenStyle&, ByVal dwWidth&, _
>      lplb As Any, dwStyleCount As Any, lpStyle As Any) As Long
>   '
>   new_pen = ExtCreatePen(pen_style, _
>         10, _
>         log_brush, _
>         Null, _
>         Null)

Not ever having used the function, I would begin by instead
declaring and calling it as follows:

Private Declare Function ExtCreatePen Lib "gdi32" _
        (ByVal dwPenStyle As Long, _
        ByVal dwWidth As Long, _
        lplb As LOGBRUSH, _
        ByVal dwStyleCount As Long, _
        lpStyle As Any) As Long

   new_pen = ExtCreatePen(pen_style, _
         10, _
         log_brush, _
         0, _
         ByVal 0&)

dwStyleCount is not a pointer, i.e. it wants to be passed ByVal,
Null is only valid in the context of a Variant data type and should
not be used otherwise.

--
Brad Martinez, http://www.mvps.org
Please direct questions/replies to the newsgroup



Sun, 05 Sep 2004 00:26:24 GMT  
 ExtCreatePen does not work in Windows 2000 but works in Windows 98

Quote:

> I just noticed you're adding the pen styles. That ain't right. They must be
> Bitwise OR'd together

Provided the penstyles are all independent powers of two, like these are,
that shouldn't make any difference.

&H10000 + &H2000 + &H100 + 0

yields the same value as if you or'd them together.



Sun, 05 Sep 2004 00:37:08 GMT  
 ExtCreatePen does not work in Windows 2000 but works in Windows 98
It's been a long week



Quote:
> > I just noticed you're adding the pen styles. That ain't right. They must
> be
> > Bitwise OR'd together
> > I can't remember what the bitwise OR operator is in VB,

> "Or", surprisingly ;)

> > but you'll find it.
> > Windows 2000 is stricter on what you feed it. It'll generally inform you
> > better than w98 if you've given it bad input.

> Flags should never overlap bit places though and as such simple addition
is
> usually equally valid (And produces the same result)

> '***
> FlagA = &H1 '0001
> FlagB = &H2 '0010
> FlagC = &H4 '0100
> FlagD = &H8 '1000

> 'Either way returns 11 (1011)
> MsgBox FlagA + FlagB + FlagD
> MsgBox FlagA Or FlagB Or FlagD
> '***

> > Chances are, you're not constructing your pen correctly in 98
> > but it just happens to pass through.

> Have a look at what GetLastError() brings back and have a look at the
> doccumentnation over on Http://msdn.microsoft.com/library/ or on
> Http://www.allapi.net/
> Hope this helps,

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/





Sun, 05 Sep 2004 17:47:55 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. access db not working passing from windows 98 to windows Me

2. Application runs with Windows 95/NT, but doesn't work with Windows 98

3. Function not working with Windows 2000 or Office 2000

4. VBA problems Going from Windows 98 to Windows 2000

5. VB Code does not work under Windows 2000 PRO

6. Word Fax Wizard not working in Windows 2000

7. Windows 2000 and IIS: Not working properly (aspx)

8. DataReport Not Working in Windows 2000 RC2

9. VB 6.0 Application does not work under Windows 2000

10. VB Component used with ASP (not working with windows 2000)

11. Coffee sample does not work on Windows 2000.

12. Inet does not work in Windows 2000

 

 
Powered by phpBB® Forum Software