DX: Full Screen GUI Development 2

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

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sonicdater

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值