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

                    rectObject.Top = 0

                    rectObject.Bottom = iHeight

                Case iPressed

                    rectObject.Top = iHeight

                    rectObject.Bottom = iHeight * 2

            End Select

 

If you run the app, you抣l see the new buttons in the upper right hand corner of the window. You抣l also notice that we抳e added a caption for the window. This is held by the sCaption member of the clsWindow class.  If you look at the declarations section for the class you抣l also see two other new members:

 

Private iCaptionX As Integer

Private iCaptionY As Integer

 

These will be used to draw the caption where it is needed for the specific control type. If you look at the DrawObject function in the class you抣l see we抳e added the code necessary to handle the caption:

 

        Case BaseWindow

            ''''Nothing needed here since we use the base rectangle

            If Len(sCaption) > 0 Then

                iCaptionX = iX + 10

                iCaptionY = iY + 5

                bDrawCaption = True

            Else

                bDrawCaption = False

            End If

 

?/SPAN>

 

    If bDrawCaption Then

        lOldColor = objSurface.GetForeColor

        objSurface.SetForeColor RGB(255, 255, 255)

        objSurface.DrawText iCaptionX, iCaptionY, sCaption, False

        objSurface.SetForeColor lOldColor

    End If

 

The setup of the base window object has been changed to add the caption:

 

    With frmMain.Window

        .ObjectSurface = objDD.CreateSurfaceFromFile(App.Path & "\window.bmp", ddsdSurf2)

        .ParentX = 0

        .ParentY = 0

        .ParentHeight = 600

        .ParentWidth = 800

        .CenterX = True

        .CenterY = True

        .WindowName = "Base"

        .Caption = "Test Window"

    End With

 

The next thing that has been added is the event raising. Take a look at the MouseUp function in the clsWindow class:

 

Public Function MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) As Boolean

   

    Dim iLp As Integer

    Dim bRetVal As Boolean

   

    MouseUp = False

   

    If X >= iX And X <= iX + iWidth And Y >= iY And Y <= iY + iHeight Then

        For iLp = 1 To colChildren.Count

            ''''If a child handles the event no need to do anything else

            bRetVal = colChildren(iLp).MouseUp(Button, Shift, X, Y)

            If bRetVal Then Exit Function

        Next iLp

   

        If iObjectType >= CloseBtn Then

            iObjectState = iEnabled

            If iObjectType = CloseBtn Then

                RaiseEvent Clicked

            End If

        Else

            If Not (iObjectState = iDisabled) Then

                If iObjectState = iPressed And iObjectType = Btn Then

                    iObjectState = iEnabled

                    RaiseEvent Clicked

                End If

            End If

           

        End If

        MouseUp = True

       

    End If

   

End Function

 

If the control has been clicked we use RaiseEvent to notify the app that this is so. The app can then decide what to do based on which control has been clicked. In our case we do two things ?destroy the window and close the app:

 

Private Sub CloseButton_Clicked()

    Window.RemoveChildren

    Set Window = Nothing

End Sub

 

Private Sub OKButton_Clicked()

    gbRun = False

End Sub

 

You can recreate the window by pressing the F1 key. Try it and see. I抣l wait while you do. J

 

Got all that? Good, then lets more on to more cool stuff.

 

Next Up

 

Open up the WindowSample4 project and take a look at the modMain module. You抣l see we抳e added RadioBtn and FrameWnd enums. Also not the constant cFrameGrey. We抣l be using this a little later on to help draw the FrameWnd control.

 

Next take a look at the frmMain code. We抳e added declarations for the new frame and radio button objects. Notice the two sets of radio buttons ?WindowRadio1,2, and 3 and Radio1, 2, and 3. The WindowRadio controls will go on the base window and the Radio controls will be contained by the Frame control. You抣l see that you can change a control in one group without affecting the other, just as you can in VB. This is due to the Parent/Child relationship of the clsWindow objects. We抳e also added the code to support the RaiseEvent call in the class for each of the objects. We merely set two controls that weren抰 clicked to be unchecked.

 

Not much has changed in the modDirectDraw module. The only thing of significance is in setting up the radio buttons that are contained

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

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