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

Full Screen GUI Development

Pt 2 ?More Controls & Text

By Jim (Machaira) Perry

 

 

Welcome back! If you抮e saying 揌uh?!?then you probably haven抰 read the first part of this tutorial. Please read it before continuing because we抣l be building on it.

 

Download this tutorial (in Word format) and the sample projects in a zip file (40 KB)

 

First Up

 

Let抯 build on our base window by adding the standard Minimize, Maximize/Restore, and Close buttons (see WindowSample3 project).

 

We抳e added enums for the new buttons:

 

    CloseBtn

    MinBtn

    MaxBtn

    RestoreBtn

 

created bitmaps for them (close.bmp, minimize.bmp, maximize.bmp, and restore.bmp), and added instances of the clsWindow class in the modDirectDraw module to create them:

 

Public WithEvents CloseButton As New clsWindow

Public WithEvents MinButton As New clsWindow

Public WithEvents MaxButton As New clsWindow

Public WithEvents RestoreButton As New clsWindow

 

Notice that we抳e added WithEvents to the declarations. This will allow us to do things outside of the class when the control is clicked. We抣l go over this a little later.

 

New controls mean that we have to add them as child controls to the base window object. We抳e done this in the CreateWindowObjects function, setting the necessary properties for them:

 

    With frmMain.CloseButton

        .ObjectType = CloseBtn

        .ParentHeight = frmMain.Window.Height

        .ParentWidth = frmMain.Window.Width

        .ParentX = frmMain.Window.X

        .ParentY = frmMain.Window.Y

        .ObjectSurface = objDD.CreateSurfaceFromFile(App.Path & "\close.bmp", ddsdSurf4)

        .WindowName = "CloseBtn"

    End With

    frmMain.Window.AddChild frmMain.CloseButton

   

    With frmMain.MinimizeButton

        .ObjectType = MinBtn

        .ParentHeight = frmMain.Window.Height

        .ParentWidth = frmMain.Window.Width

        .ParentX = frmMain.Window.X

        .ParentY = frmMain.Window.Y

        .ObjectSurface = objDD.CreateSurfaceFromFile(App.Path & "\minimize.bmp", ddsdSurf4)

        .WindowName = "MinBtn"

    End With

    frmMain.Window.AddChild frmMain.MinimizeButton

   

    With frmMain.MaximizeButton

        .ObjectType = MaxBtn

        .ParentHeight = frmMain.Window.Height

        .ParentWidth = frmMain.Window.Width

        .ParentX = frmMain.Window.X

        .ParentY = frmMain.Window.Y

        .ObjectSurface = objDD.CreateSurfaceFromFile(App.Path & "\maximize.bmp", ddsdSurf4)

        .WindowName = "MaxBtn"

    End With

    frmMain.Window.AddChild frmMain.MaximizeButton

   

    With frmMain.RestoreButton

        .ObjectType = RestoreBtn

        .ParentHeight = frmMain.Window.Height

        .ParentWidth = frmMain.Window.Width

        .ParentX = frmMain.Window.X

        .ParentY = frmMain.Window.Y

        .ObjectSurface = objDD.CreateSurfaceFromFile(App.Path & "\restore.bmp", ddsdSurf4)

        .WindowName = "RestoreBtn"

    End With

    frmMain.Window.AddChild frmMain.RestoreButton

 

This is code that used to be in the InitDD function, but has been moved out for a good reason, as you抣l see soon. It allows us to recreate the base window object and all children whenever we want. Notice also that we抳e changed the code to use the With匛ndWIth statements. It抯 saves our poor little fingers from having to type as much and speeds up the code a bit (not that it抣l be noticeable unless you timed it.

 

If you compare this chunk of code with the code to create the OK button, you抣l notice that we抮e not setting any X and Y or ObjectState properties for the buttons. That抯 because you can抰. The buttons only go in one place, the standard position on the window they抮e attached to. The properties are set in the ObjectSurface Property Set method:

 

        Case MinBtn

            iHeight = ddsd.lHeight / 2

            iX = iParentWidth + iParentX - iWidth - 40

            iY = iParentY + 7

            iObjectState = iEnabled

        Case MaxBtn

            iHeight = ddsd.lHeight / 2

            iX = iParentWidth + iParentX - iWidth - 24

            iY = iParentY + 7

            iObjectState = iEnabled

        Case CloseBtn

            iHeight = ddsd.lHeight / 2

            iX = iParentWidth + iParentX - iWidth - 6

            iY = iParentY + 7

            iObjectState = iEnabled

        Case RestoreBtn

            iHeight = ddsd.lHeight / 2

            iX = iParentWidth + iParentX - iWidth - 24

            iY = iParentY + 7

            iObjectState = iEnabled

 

The DrawObject function is also modified to handle drawing the new controls:

 

        Case MinBtn, MaxBtn, CloseBtn, RestoreBtn

       

            rectObject.Left = 0

            rectObject.Right = iWidth

           

            Select Case iObjectState

             

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

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