GradientFillRect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NickP

    #1

    GradientFillRect

    Hi there,

    I am trying to use GradientFillRec t in a VB.NET application.

    Does anyone have any examples of the correct PInvoke signature and
    marshaling that I need to perform in order to achieve this?

    BTW, I do not want to use .Nets gradient fill capabilities, and so far I
    have this.

    ----------------------------------------------

    Private Const GRADIENT_FILL_R ECT_H As Long = &H0
    Private Const GRADIENT_FILL_R ECT_V As Long = &H1

    <StructLayout(L ayoutKind.Seque ntial)_
    Public Structure TRIVERTEX
    Public x As Int32
    Public y As Int32
    Public Red As Int16
    Public Green As Int16
    Public Blue As Int16
    Public Alpha As Int16
    End Structure

    <StructLayout(L ayoutKind.Seque ntial)_
    Public Structure GRADIENT_RECT
    Public UpperLeft As Integer
    Public LowerRight As Integer
    End Structure

    <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
    Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
    ByVal pVertex As IntPtr, _
    ByVal dwNumVertex As Integer, _
    ByRef pMesh As GRADIENT_RECT, _
    ByVal dwNumMesh As Integer, _
    ByVal dwMode As Long) As Integer
    End Function

    Private Sub doGradientFill( ByVal iGraphics As Graphics, _
    ByVal iSize As Size)
    '//--------------------------------------------------
    With iGraphics
    Dim pTVxVert(2) As TRIVERTEX
    Dim pGRtRect As GRADIENT_RECT
    pTVxVert(0).x = 0
    pTVxVert(0).y = 0
    pTVxVert(0).Red = (Color.Green.R)
    pTVxVert(0).Gre en = (Color.Green.G)
    pTVxVert(0).Blu e = (Color.Green.B)
    pTVxVert(0).Alp ha = (Color.Green.A)
    pTVxVert(1).x = iSize.Width
    pTVxVert(1).y = iSize.Height
    pTVxVert(1).Red = (Color.Red.R)
    pTVxVert(1).Gre en = (Color.Red.G)
    pTVxVert(1).Blu e = (Color.Red.B)
    pTVxVert(1).Alp ha = (Color.Red.A)
    pGRtRect.UpperL eft = 0
    pGRtRect.LowerR ight = 1

    Dim pIPrVert As IntPtr =
    Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
    Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
    Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
    GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
    GRADIENT_FILL_R ECT_H)
    'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
    GRADIENT_FILL_R ECT_V)
    Call iGraphics.Relea seHdc(pIPrHDC)
    End With
    End Sub

    ----------------------------------------------

    Unfortunately this does not work as pTVxVert is an array and the size
    cannot be calculated correctly. Any ideas?

    Many thanks in advance.

    Nick.


  • NickP

    #2
    Re: GradientFillRec t

    Just noticed 2 things but still can't get it working, just getting a solid
    black block rather than gradient.

    My API declaration for GradientFillRec t includes a "Long" parameter, should
    be Integer. Also I was not converting the RGB values to shorts, this is now
    being done but still no luck :-(

    Oh yeah and my array was 1 too big, not that this shoud effect the output.

    Nick.

    "NickP" <a@a.comwrote in message
    news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
    Hi there,
    >
    I am trying to use GradientFillRec t in a VB.NET application.
    >
    Does anyone have any examples of the correct PInvoke signature and
    marshaling that I need to perform in order to achieve this?
    >
    BTW, I do not want to use .Nets gradient fill capabilities, and so far
    I have this.
    >
    ----------------------------------------------
    >
    Private Const GRADIENT_FILL_R ECT_H As Long = &H0
    Private Const GRADIENT_FILL_R ECT_V As Long = &H1
    >
    <StructLayout(L ayoutKind.Seque ntial)_
    Public Structure TRIVERTEX
    Public x As Int32
    Public y As Int32
    Public Red As Int16
    Public Green As Int16
    Public Blue As Int16
    Public Alpha As Int16
    End Structure
    >
    <StructLayout(L ayoutKind.Seque ntial)_
    Public Structure GRADIENT_RECT
    Public UpperLeft As Integer
    Public LowerRight As Integer
    End Structure
    >
    <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
    Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
    ByVal pVertex As IntPtr, _
    ByVal dwNumVertex As Integer, _
    ByRef pMesh As GRADIENT_RECT, _
    ByVal dwNumMesh As Integer, _
    ByVal dwMode As Long) As Integer
    End Function
    >
    Private Sub doGradientFill( ByVal iGraphics As Graphics, _
    ByVal iSize As Size)
    '//--------------------------------------------------
    With iGraphics
    Dim pTVxVert(2) As TRIVERTEX
    Dim pGRtRect As GRADIENT_RECT
    pTVxVert(0).x = 0
    pTVxVert(0).y = 0
    pTVxVert(0).Red = (Color.Green.R)
    pTVxVert(0).Gre en = (Color.Green.G)
    pTVxVert(0).Blu e = (Color.Green.B)
    pTVxVert(0).Alp ha = (Color.Green.A)
    pTVxVert(1).x = iSize.Width
    pTVxVert(1).y = iSize.Height
    pTVxVert(1).Red = (Color.Red.R)
    pTVxVert(1).Gre en = (Color.Red.G)
    pTVxVert(1).Blu e = (Color.Red.B)
    pTVxVert(1).Alp ha = (Color.Red.A)
    pGRtRect.UpperL eft = 0
    pGRtRect.LowerR ight = 1
    >
    Dim pIPrVert As IntPtr =
    Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
    Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
    Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
    GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
    GRADIENT_FILL_R ECT_H)
    'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
    GRADIENT_FILL_R ECT_V)
    Call iGraphics.Relea seHdc(pIPrHDC)
    End With
    End Sub
    >
    ----------------------------------------------
    >
    Unfortunately this does not work as pTVxVert is an array and the size
    cannot be calculated correctly. Any ideas?
    >
    Many thanks in advance.
    >
    Nick.
    >

    Comment

    • NickP

      #3
      Re: GradientFillRec t

      "GradientFi ll" API rather!

      "NickP" <a@a.comwrote in message
      news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
      Hi there,
      >
      I am trying to use GradientFillRec t in a VB.NET application.
      >
      Does anyone have any examples of the correct PInvoke signature and
      marshaling that I need to perform in order to achieve this?
      >
      BTW, I do not want to use .Nets gradient fill capabilities, and so far
      I have this.
      >
      ----------------------------------------------
      >
      Private Const GRADIENT_FILL_R ECT_H As Long = &H0
      Private Const GRADIENT_FILL_R ECT_V As Long = &H1
      >
      <StructLayout(L ayoutKind.Seque ntial)_
      Public Structure TRIVERTEX
      Public x As Int32
      Public y As Int32
      Public Red As Int16
      Public Green As Int16
      Public Blue As Int16
      Public Alpha As Int16
      End Structure
      >
      <StructLayout(L ayoutKind.Seque ntial)_
      Public Structure GRADIENT_RECT
      Public UpperLeft As Integer
      Public LowerRight As Integer
      End Structure
      >
      <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
      Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
      ByVal pVertex As IntPtr, _
      ByVal dwNumVertex As Integer, _
      ByRef pMesh As GRADIENT_RECT, _
      ByVal dwNumMesh As Integer, _
      ByVal dwMode As Long) As Integer
      End Function
      >
      Private Sub doGradientFill( ByVal iGraphics As Graphics, _
      ByVal iSize As Size)
      '//--------------------------------------------------
      With iGraphics
      Dim pTVxVert(2) As TRIVERTEX
      Dim pGRtRect As GRADIENT_RECT
      pTVxVert(0).x = 0
      pTVxVert(0).y = 0
      pTVxVert(0).Red = (Color.Green.R)
      pTVxVert(0).Gre en = (Color.Green.G)
      pTVxVert(0).Blu e = (Color.Green.B)
      pTVxVert(0).Alp ha = (Color.Green.A)
      pTVxVert(1).x = iSize.Width
      pTVxVert(1).y = iSize.Height
      pTVxVert(1).Red = (Color.Red.R)
      pTVxVert(1).Gre en = (Color.Red.G)
      pTVxVert(1).Blu e = (Color.Red.B)
      pTVxVert(1).Alp ha = (Color.Red.A)
      pGRtRect.UpperL eft = 0
      pGRtRect.LowerR ight = 1
      >
      Dim pIPrVert As IntPtr =
      Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
      Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
      Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
      GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
      GRADIENT_FILL_R ECT_H)
      'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
      GRADIENT_FILL_R ECT_V)
      Call iGraphics.Relea seHdc(pIPrHDC)
      End With
      End Sub
      >
      ----------------------------------------------
      >
      Unfortunately this does not work as pTVxVert is an array and the size
      cannot be calculated correctly. Any ideas?
      >
      Many thanks in advance.
      >
      Nick.
      >

      Comment

      • NickP

        #4
        Re: GradientFillRec t

        I now have this.... (which doesn't work also)... Even after hardcoding some
        colours!

        ------------------

        Private Const GRADIENT_FILL_R ECT_H As Long = &H0
        Private Const GRADIENT_FILL_R ECT_V As Long = &H1

        <StructLayout(L ayoutKind.Seque ntial)_
        Public Structure TRIVERTEX
        Public x As Int32
        Public y As Int32
        Public Red As UInt16
        Public Green As UInt16
        Public Blue As UInt16
        Public Alpha As UInt16
        End Structure

        <StructLayout(L ayoutKind.Seque ntial)_
        Public Structure GRADIENT_RECT
        Public UpperLeft As Integer
        Public LowerRight As Integer
        End Structure

        <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
        Public Shared Function GradientFill(By Val hdc As IntPtr, _
        <MarshalAs(Unma nagedType.LPArr ay, ArraySubType:=U nmanagedType.St ruct)_
        ByRef pVertex() As TRIVERTEX, _
        ByVal dwNumVertex As Integer, _
        ByRef pMesh As GRADIENT_RECT, _
        ByVal dwNumMesh As Integer, _
        ByVal dwMode As Integer) As Boolean
        End Function

        Private Sub doGradientFill( ByVal iGraphics As Graphics, _
        ByVal iSize As Size)
        '//--------------------------------------------------
        With iGraphics
        Dim pTVxVert(1) As TRIVERTEX
        Dim pGRtRect As GRADIENT_RECT
        pTVxVert(0).x = 0
        pTVxVert(0).y = 0
        pTVxVert(0).Red = 0 'ByteToUShort(2 55)
        pTVxVert(0).Gre en = &HFF00 'ByteToUShort(0 )
        pTVxVert(0).Blu e = 0 'ByteToUShort(0 )
        pTVxVert(0).Alp ha = 0 'ByteToUShort(0 )
        pTVxVert(1).x = iSize.Width
        pTVxVert(1).y = iSize.Height
        pTVxVert(1).Red = &HFF00 'ByteToUShort(0 )
        pTVxVert(1).Gre en = 0 'ByteToUShort(2 55)
        pTVxVert(1).Blu e = 0 'ByteToUShort(0 )
        pTVxVert(1).Alp ha = &HFF00 'ByteToUShort(0 )
        pGRtRect.UpperL eft = 0
        pGRtRect.LowerR ight = 1
        Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
        Console.WriteLi ne(GradientFill (pIPrHDC, pTVxVert, 2, pGRtRect, 1,
        GRADIENT_FILL_R ECT_V).ToString )
        Call iGraphics.Relea seHdc(pIPrHDC)
        End With
        End Sub
        ------------------

        I've tried to add as much marshaling information as I can think of as well
        as assuring the signatures are correct but the lack of information with
        regard to this method and .NET is upsetting :-(

        If anyone else has done this, some info would be great. I'll post this on
        the graphics one too just incase.

        Nick.

        "NickP" <a@a.comwrote in message
        news:e4WC9EAMHH A.4916@TK2MSFTN GP06.phx.gbl...
        Just noticed 2 things but still can't get it working, just getting a solid
        black block rather than gradient.
        >
        My API declaration for GradientFillRec t includes a "Long" parameter,
        should be Integer. Also I was not converting the RGB values to shorts,
        this is now being done but still no luck :-(
        >
        Oh yeah and my array was 1 too big, not that this shoud effect the output.
        >
        Nick.
        >
        "NickP" <a@a.comwrote in message
        news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
        >Hi there,
        >>
        > I am trying to use GradientFillRec t in a VB.NET application.
        >>
        > Does anyone have any examples of the correct PInvoke signature and
        >marshaling that I need to perform in order to achieve this?
        >>
        > BTW, I do not want to use .Nets gradient fill capabilities, and so far
        >I have this.
        >>
        > ----------------------------------------------
        >>
        > Private Const GRADIENT_FILL_R ECT_H As Long = &H0
        > Private Const GRADIENT_FILL_R ECT_V As Long = &H1
        >>
        > <StructLayout(L ayoutKind.Seque ntial)_
        > Public Structure TRIVERTEX
        > Public x As Int32
        > Public y As Int32
        > Public Red As Int16
        > Public Green As Int16
        > Public Blue As Int16
        > Public Alpha As Int16
        > End Structure
        >>
        > <StructLayout(L ayoutKind.Seque ntial)_
        > Public Structure GRADIENT_RECT
        > Public UpperLeft As Integer
        > Public LowerRight As Integer
        > End Structure
        >>
        > <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
        > Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
        > ByVal pVertex As IntPtr, _
        > ByVal dwNumVertex As Integer, _
        > ByRef pMesh As GRADIENT_RECT, _
        > ByVal dwNumMesh As Integer, _
        > ByVal dwMode As Long) As Integer
        > End Function
        >>
        > Private Sub doGradientFill( ByVal iGraphics As Graphics, _
        > ByVal iSize As Size)
        > '//--------------------------------------------------
        > With iGraphics
        > Dim pTVxVert(2) As TRIVERTEX
        > Dim pGRtRect As GRADIENT_RECT
        > pTVxVert(0).x = 0
        > pTVxVert(0).y = 0
        > pTVxVert(0).Red = (Color.Green.R)
        > pTVxVert(0).Gre en = (Color.Green.G)
        > pTVxVert(0).Blu e = (Color.Green.B)
        > pTVxVert(0).Alp ha = (Color.Green.A)
        > pTVxVert(1).x = iSize.Width
        > pTVxVert(1).y = iSize.Height
        > pTVxVert(1).Red = (Color.Red.R)
        > pTVxVert(1).Gre en = (Color.Red.G)
        > pTVxVert(1).Blu e = (Color.Red.B)
        > pTVxVert(1).Alp ha = (Color.Red.A)
        > pGRtRect.UpperL eft = 0
        > pGRtRect.LowerR ight = 1
        >>
        > Dim pIPrVert As IntPtr =
        >Marshal.AllocH Global(Marshal. SizeOf(pTVxVert ))
        > Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
        > Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
        > GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
        >GRADIENT_FILL_ RECT_H)
        > 'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
        >GRADIENT_FILL_ RECT_V)
        > Call iGraphics.Relea seHdc(pIPrHDC)
        > End With
        > End Sub
        >>
        > ----------------------------------------------
        >>
        > Unfortunately this does not work as pTVxVert is an array and the size
        >cannot be calculated correctly. Any ideas?
        >>
        > Many thanks in advance.
        >>
        >Nick.
        >>
        >
        >

        Comment

        • Stuart Nathan

          #5
          Re: GradientFillRec t

          why not use GDI?


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: GradientFillRec t

            Nick,
            BTW, I do not want to use .Nets gradient fill capabilities, and so far
            I have this.
            As Stuart asked: Why not??????

            ..NET has already done all the hard work for you.


            If you have an actual need to call the API itself, I would recommend you
            start here:

            http://pinvoke.net/search.aspx?searc...ill&namespace=[All]

            NOTE: I have not used the API, as I find using .NET's simply & very
            flexible.

            --
            Hope this helps
            Jay B. Harlow [MVP - Outlook]
            ..NET Application Architect, Enthusiast, & Evangelist
            T.S. Bradley - http://www.tsbradley.net


            "NickP" <a@a.comwrote in message
            news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
            Hi there,
            >
            I am trying to use GradientFillRec t in a VB.NET application.
            >
            Does anyone have any examples of the correct PInvoke signature and
            marshaling that I need to perform in order to achieve this?
            >
            BTW, I do not want to use .Nets gradient fill capabilities, and so far
            I have this.
            >
            ----------------------------------------------
            >
            Private Const GRADIENT_FILL_R ECT_H As Long = &H0
            Private Const GRADIENT_FILL_R ECT_V As Long = &H1
            >
            <StructLayout(L ayoutKind.Seque ntial)_
            Public Structure TRIVERTEX
            Public x As Int32
            Public y As Int32
            Public Red As Int16
            Public Green As Int16
            Public Blue As Int16
            Public Alpha As Int16
            End Structure
            >
            <StructLayout(L ayoutKind.Seque ntial)_
            Public Structure GRADIENT_RECT
            Public UpperLeft As Integer
            Public LowerRight As Integer
            End Structure
            >
            <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
            Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
            ByVal pVertex As IntPtr, _
            ByVal dwNumVertex As Integer, _
            ByRef pMesh As GRADIENT_RECT, _
            ByVal dwNumMesh As Integer, _
            ByVal dwMode As Long) As Integer
            End Function
            >
            Private Sub doGradientFill( ByVal iGraphics As Graphics, _
            ByVal iSize As Size)
            '//--------------------------------------------------
            With iGraphics
            Dim pTVxVert(2) As TRIVERTEX
            Dim pGRtRect As GRADIENT_RECT
            pTVxVert(0).x = 0
            pTVxVert(0).y = 0
            pTVxVert(0).Red = (Color.Green.R)
            pTVxVert(0).Gre en = (Color.Green.G)
            pTVxVert(0).Blu e = (Color.Green.B)
            pTVxVert(0).Alp ha = (Color.Green.A)
            pTVxVert(1).x = iSize.Width
            pTVxVert(1).y = iSize.Height
            pTVxVert(1).Red = (Color.Red.R)
            pTVxVert(1).Gre en = (Color.Red.G)
            pTVxVert(1).Blu e = (Color.Red.B)
            pTVxVert(1).Alp ha = (Color.Red.A)
            pGRtRect.UpperL eft = 0
            pGRtRect.LowerR ight = 1
            >
            Dim pIPrVert As IntPtr =
            Marshal.AllocHG lobal(Marshal.S izeOf(pTVxVert) )
            Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
            Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
            GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
            GRADIENT_FILL_R ECT_H)
            'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
            GRADIENT_FILL_R ECT_V)
            Call iGraphics.Relea seHdc(pIPrHDC)
            End With
            End Sub
            >
            ----------------------------------------------
            >
            Unfortunately this does not work as pTVxVert is an array and the size
            cannot be calculated correctly. Any ideas?
            >
            Many thanks in advance.
            >
            Nick.
            >

            Comment

            • NickP

              #7
              Re: GradientFillRec t

              Hi Jay,
              NOTE: I have not used the API, as I find using .NET's simply & very
              flexible.
              And also very slow in comparrison. All .net graphics methods are slow in
              comparrison. Currently I have a drawing routine that has 1 bottle neck, it
              is the drawing of this gradient unfortunately.

              I'll check that link out, many thanks :-)

              Nick.

              "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.netw rote in
              message news:eJuVvxqMHH A.5104@TK2MSFTN GP06.phx.gbl...
              Nick,
              > BTW, I do not want to use .Nets gradient fill capabilities, and so far
              >I have this.
              As Stuart asked: Why not??????
              >
              .NET has already done all the hard work for you.
              >
              >
              If you have an actual need to call the API itself, I would recommend you
              start here:
              >
              http://pinvoke.net/search.aspx?searc...ill&namespace=[All]
              >
              NOTE: I have not used the API, as I find using .NET's simply & very
              flexible.
              >
              --
              Hope this helps
              Jay B. Harlow [MVP - Outlook]
              .NET Application Architect, Enthusiast, & Evangelist
              T.S. Bradley - http://www.tsbradley.net
              >
              >
              "NickP" <a@a.comwrote in message
              news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
              >Hi there,
              >>
              > I am trying to use GradientFillRec t in a VB.NET application.
              >>
              > Does anyone have any examples of the correct PInvoke signature and
              >marshaling that I need to perform in order to achieve this?
              >>
              > BTW, I do not want to use .Nets gradient fill capabilities, and so far
              >I have this.
              >>
              > ----------------------------------------------
              >>
              > Private Const GRADIENT_FILL_R ECT_H As Long = &H0
              > Private Const GRADIENT_FILL_R ECT_V As Long = &H1
              >>
              > <StructLayout(L ayoutKind.Seque ntial)_
              > Public Structure TRIVERTEX
              > Public x As Int32
              > Public y As Int32
              > Public Red As Int16
              > Public Green As Int16
              > Public Blue As Int16
              > Public Alpha As Int16
              > End Structure
              >>
              > <StructLayout(L ayoutKind.Seque ntial)_
              > Public Structure GRADIENT_RECT
              > Public UpperLeft As Integer
              > Public LowerRight As Integer
              > End Structure
              >>
              > <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
              > Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
              > ByVal pVertex As IntPtr, _
              > ByVal dwNumVertex As Integer, _
              > ByRef pMesh As GRADIENT_RECT, _
              > ByVal dwNumMesh As Integer, _
              > ByVal dwMode As Long) As Integer
              > End Function
              >>
              > Private Sub doGradientFill( ByVal iGraphics As Graphics, _
              > ByVal iSize As Size)
              > '//--------------------------------------------------
              > With iGraphics
              > Dim pTVxVert(2) As TRIVERTEX
              > Dim pGRtRect As GRADIENT_RECT
              > pTVxVert(0).x = 0
              > pTVxVert(0).y = 0
              > pTVxVert(0).Red = (Color.Green.R)
              > pTVxVert(0).Gre en = (Color.Green.G)
              > pTVxVert(0).Blu e = (Color.Green.B)
              > pTVxVert(0).Alp ha = (Color.Green.A)
              > pTVxVert(1).x = iSize.Width
              > pTVxVert(1).y = iSize.Height
              > pTVxVert(1).Red = (Color.Red.R)
              > pTVxVert(1).Gre en = (Color.Red.G)
              > pTVxVert(1).Blu e = (Color.Red.B)
              > pTVxVert(1).Alp ha = (Color.Red.A)
              > pGRtRect.UpperL eft = 0
              > pGRtRect.LowerR ight = 1
              >>
              > Dim pIPrVert As IntPtr =
              >Marshal.AllocH Global(Marshal. SizeOf(pTVxVert ))
              > Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
              > Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
              > GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
              >GRADIENT_FILL_ RECT_H)
              > 'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
              >GRADIENT_FILL_ RECT_V)
              > Call iGraphics.Relea seHdc(pIPrHDC)
              > End With
              > End Sub
              >>
              > ----------------------------------------------
              >>
              > Unfortunately this does not work as pTVxVert is an array and the size
              >cannot be calculated correctly. Any ideas?
              >>
              > Many thanks in advance.
              >>
              >Nick.
              >>
              >

              Comment

              • NickP

                #8
                Re: GradientFillRec t

                BTW,

                I don't see Stuarts reply, I think my outlook express is borked :-(

                "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.netw rote in
                message news:eJuVvxqMHH A.5104@TK2MSFTN GP06.phx.gbl...
                Nick,
                > BTW, I do not want to use .Nets gradient fill capabilities, and so far
                >I have this.
                As Stuart asked: Why not??????
                >
                .NET has already done all the hard work for you.
                >
                >
                If you have an actual need to call the API itself, I would recommend you
                start here:
                >
                http://pinvoke.net/search.aspx?searc...ill&namespace=[All]
                >
                NOTE: I have not used the API, as I find using .NET's simply & very
                flexible.
                >
                --
                Hope this helps
                Jay B. Harlow [MVP - Outlook]
                .NET Application Architect, Enthusiast, & Evangelist
                T.S. Bradley - http://www.tsbradley.net
                >
                >
                "NickP" <a@a.comwrote in message
                news:%23QwdKh$L HHA.1816@TK2MSF TNGP06.phx.gbl. ..
                >Hi there,
                >>
                > I am trying to use GradientFillRec t in a VB.NET application.
                >>
                > Does anyone have any examples of the correct PInvoke signature and
                >marshaling that I need to perform in order to achieve this?
                >>
                > BTW, I do not want to use .Nets gradient fill capabilities, and so far
                >I have this.
                >>
                > ----------------------------------------------
                >>
                > Private Const GRADIENT_FILL_R ECT_H As Long = &H0
                > Private Const GRADIENT_FILL_R ECT_V As Long = &H1
                >>
                > <StructLayout(L ayoutKind.Seque ntial)_
                > Public Structure TRIVERTEX
                > Public x As Int32
                > Public y As Int32
                > Public Red As Int16
                > Public Green As Int16
                > Public Blue As Int16
                > Public Alpha As Int16
                > End Structure
                >>
                > <StructLayout(L ayoutKind.Seque ntial)_
                > Public Structure GRADIENT_RECT
                > Public UpperLeft As Integer
                > Public LowerRight As Integer
                > End Structure
                >>
                > <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
                > Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
                > ByVal pVertex As IntPtr, _
                > ByVal dwNumVertex As Integer, _
                > ByRef pMesh As GRADIENT_RECT, _
                > ByVal dwNumMesh As Integer, _
                > ByVal dwMode As Long) As Integer
                > End Function
                >>
                > Private Sub doGradientFill( ByVal iGraphics As Graphics, _
                > ByVal iSize As Size)
                > '//--------------------------------------------------
                > With iGraphics
                > Dim pTVxVert(2) As TRIVERTEX
                > Dim pGRtRect As GRADIENT_RECT
                > pTVxVert(0).x = 0
                > pTVxVert(0).y = 0
                > pTVxVert(0).Red = (Color.Green.R)
                > pTVxVert(0).Gre en = (Color.Green.G)
                > pTVxVert(0).Blu e = (Color.Green.B)
                > pTVxVert(0).Alp ha = (Color.Green.A)
                > pTVxVert(1).x = iSize.Width
                > pTVxVert(1).y = iSize.Height
                > pTVxVert(1).Red = (Color.Red.R)
                > pTVxVert(1).Gre en = (Color.Red.G)
                > pTVxVert(1).Blu e = (Color.Red.B)
                > pTVxVert(1).Alp ha = (Color.Red.A)
                > pGRtRect.UpperL eft = 0
                > pGRtRect.LowerR ight = 1
                >>
                > Dim pIPrVert As IntPtr =
                >Marshal.AllocH Global(Marshal. SizeOf(pTVxVert ))
                > Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
                > Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
                > GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
                >GRADIENT_FILL_ RECT_H)
                > 'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
                >GRADIENT_FILL_ RECT_V)
                > Call iGraphics.Relea seHdc(pIPrHDC)
                > End With
                > End Sub
                >>
                > ----------------------------------------------
                >>
                > Unfortunately this does not work as pTVxVert is an array and the size
                >cannot be calculated correctly. Any ideas?
                >>
                > Many thanks in advance.
                >>
                >Nick.
                >>
                >

                Comment

                • Jay B. Harlow [MVP - Outlook]

                  #9
                  Re: GradientFillRec t

                  And also very slow in comparrison.
                  Slow is a user perception.

                  For where & how I'm using gradients I don't see/perceive that they are slow.

                  Although I realize there are places where high performant graphics is
                  important. Which is where having 3 systems to choose from; GDI, GDI+ or
                  DirectX is nice...

                  --
                  Hope this helps
                  Jay B. Harlow [MVP - Outlook]
                  ..NET Application Architect, Enthusiast, & Evangelist
                  T.S. Bradley - http://www.tsbradley.net


                  "NickP" <a@a.comwrote in message
                  news:ORakXyzMHH A.5012@TK2MSFTN GP02.phx.gbl...
                  Hi Jay,
                  >
                  >NOTE: I have not used the API, as I find using .NET's simply & very
                  >flexible.
                  >
                  And also very slow in comparrison. All .net graphics methods are slow in
                  comparrison. Currently I have a drawing routine that has 1 bottle neck,
                  it is the drawing of this gradient unfortunately.
                  >
                  I'll check that link out, many thanks :-)
                  >
                  Nick.
                  >
                  "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.netw rote in
                  message news:eJuVvxqMHH A.5104@TK2MSFTN GP06.phx.gbl...
                  >Nick,
                  >> BTW, I do not want to use .Nets gradient fill capabilities, and so
                  >>far I have this.
                  >As Stuart asked: Why not??????
                  >>
                  >.NET has already done all the hard work for you.
                  >>
                  >>
                  >If you have an actual need to call the API itself, I would recommend you
                  >start here:
                  >>
                  >http://pinvoke.net/search.aspx?searc...ill&namespace=[All]
                  >>
                  >NOTE: I have not used the API, as I find using .NET's simply & very
                  >flexible.
                  >>
                  >--
                  >Hope this helps
                  >Jay B. Harlow [MVP - Outlook]
                  >.NET Application Architect, Enthusiast, & Evangelist
                  >T.S. Bradley - http://www.tsbradley.net
                  >>
                  >>
                  >"NickP" <a@a.comwrote in message
                  >news:%23QwdKh$ LHHA.1816@TK2MS FTNGP06.phx.gbl ...
                  >>Hi there,
                  >>>
                  >> I am trying to use GradientFillRec t in a VB.NET application.
                  >>>
                  >> Does anyone have any examples of the correct PInvoke signature and
                  >>marshaling that I need to perform in order to achieve this?
                  >>>
                  >> BTW, I do not want to use .Nets gradient fill capabilities, and so
                  >>far I have this.
                  >>>
                  >> ----------------------------------------------
                  >>>
                  >> Private Const GRADIENT_FILL_R ECT_H As Long = &H0
                  >> Private Const GRADIENT_FILL_R ECT_V As Long = &H1
                  >>>
                  >> <StructLayout(L ayoutKind.Seque ntial)_
                  >> Public Structure TRIVERTEX
                  >> Public x As Int32
                  >> Public y As Int32
                  >> Public Red As Int16
                  >> Public Green As Int16
                  >> Public Blue As Int16
                  >> Public Alpha As Int16
                  >> End Structure
                  >>>
                  >> <StructLayout(L ayoutKind.Seque ntial)_
                  >> Public Structure GRADIENT_RECT
                  >> Public UpperLeft As Integer
                  >> Public LowerRight As Integer
                  >> End Structure
                  >>>
                  >> <DllImport("msi mg32.dll", EntryPoint:="Gr adientFill")_
                  >> Public Shared Function GradientFillRec t(ByVal hdc As IntPtr, _
                  >> ByVal pVertex As IntPtr, _
                  >> ByVal dwNumVertex As Integer, _
                  >> ByRef pMesh As GRADIENT_RECT, _
                  >> ByVal dwNumMesh As Integer, _
                  >> ByVal dwMode As Long) As Integer
                  >> End Function
                  >>>
                  >> Private Sub doGradientFill( ByVal iGraphics As Graphics, _
                  >> ByVal iSize As Size)
                  >> '//--------------------------------------------------
                  >> With iGraphics
                  >> Dim pTVxVert(2) As TRIVERTEX
                  >> Dim pGRtRect As GRADIENT_RECT
                  >> pTVxVert(0).x = 0
                  >> pTVxVert(0).y = 0
                  >> pTVxVert(0).Red = (Color.Green.R)
                  >> pTVxVert(0).Gre en = (Color.Green.G)
                  >> pTVxVert(0).Blu e = (Color.Green.B)
                  >> pTVxVert(0).Alp ha = (Color.Green.A)
                  >> pTVxVert(1).x = iSize.Width
                  >> pTVxVert(1).y = iSize.Height
                  >> pTVxVert(1).Red = (Color.Red.R)
                  >> pTVxVert(1).Gre en = (Color.Red.G)
                  >> pTVxVert(1).Blu e = (Color.Red.B)
                  >> pTVxVert(1).Alp ha = (Color.Red.A)
                  >> pGRtRect.UpperL eft = 0
                  >> pGRtRect.LowerR ight = 1
                  >>>
                  >> Dim pIPrVert As IntPtr =
                  >>Marshal.Alloc HGlobal(Marshal .SizeOf(pTVxVer t))
                  >> Call Marshal.Structu reToPtr(pTVxVer t, pIPrVert, False)
                  >> Dim pIPrHDC As IntPtr = iGraphics.GetHd c()
                  >> GradientFillRec t(pIPrHDC, pIPrVert, 2, pGRtRect, 1,
                  >>GRADIENT_FILL _RECT_H)
                  >> 'GradientFillRe ct(pIPrHDC, pTVxVert, 2, pGRtRect, 1,
                  >>GRADIENT_FILL _RECT_V)
                  >> Call iGraphics.Relea seHdc(pIPrHDC)
                  >> End With
                  >> End Sub
                  >>>
                  >> ----------------------------------------------
                  >>>
                  >> Unfortunately this does not work as pTVxVert is an array and the size
                  >>cannot be calculated correctly. Any ideas?
                  >>>
                  >> Many thanks in advance.
                  >>>
                  >>Nick.
                  >>>
                  >>
                  >
                  >

                  Comment

                  Working...