打印本文 打印本文 关闭窗口 关闭窗口
DX: Full Screen GUI Development 2
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4138  更新时间:2009/4/23 16:39:24  文章录入:mintao  责任编辑:mintao
sp;   Else

                bDrawCaption = False

            End If

    End Select

   

    lBltFlags = DDBLT_WAIT

    ''''Need to use transparency if it''''s a radio button

    If iObjectType = RadioBtn Then

        lBltFlags = DDBLT_WAIT Or DDBLT_KEYSRC

    End If

   

    ''''Don''''t blit if it a frame control

    If iObjectType <> FrameWnd Then lRet = objSurface.Blt(rectBitmap, objBitmap, rectObject, lBltFlags)

   

    If bDrawCaption Then

        lOldColor = objSurface.GetForeColor

        objSurface.SetForeColor RGB(255, 255, 255)

        objSurface.DrawText iCaptionX, iCaptionY, sCaption, False

        objSurface.SetForeColor lOldColor

    End If

   

    For iLp = 1 To colChildren.Count

        colChildren(iLp).DrawObject objSurface

    Next iLp

 

    Exit Function

   

DrawObjectErr:

    objErr.WriteLine "Error drawing " & sName & " - " & Err.Description

   

    Exit Function

End Function

 

As you can see the changes are pretty extensive. The function now has to handle the two new controls and the new Caption member. The RadioBtn is fairly simple since it pretty much acts like the ChkBox inside the class. If you looked at the files included with this project you抣l notice that there抯 no bitmap for the frame object. That抯 because it uses DirectDraw抯 DrawLine function to draw the outline of the frame. Open the framesample.bmp file and zoom in to see how it抯 actually drawn.

 

We抳e added a function in the class to return a child object. This is necessary to change the RadioBtn抯 ObjectState member when one radio button in a group is clicked:

 

Public Function GetChild(ByVal sKey As String) As clsWindow

    Set GetChild = colChildren(sKey)

End Function

 

The AddChild method was changed to specify a key when adding a child in order to support this function:

 

Public Sub AddChild(clsChild As clsWindow)

    colChildren.Add clsChild, clsChild.WindowName

End Sub

 

Take a minute to run the app and play with the new controls. There are a couple of things that could be changed to make the class better but I抣l leave them up to you. Some things could be:

 

  • Add members to allow the font type, size and color to be changed.
  • Add a Style member to allow the ChkBox and RadioBtn objects to be graphical similar to the way the VB controls act.
  • Change the frame drawing to not draw under the caption.
  • Adapt the class to add a LabelWnd object type. This would just use the Caption property

 

That抯 it for this lesson. I hope it抯 been fun and interesting. The next lesson will attempt to cover listboxes and comboboxes. Hope to see you there.

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口