扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图 1:使用高尔夫球场外观查看星期三各项
图 2:使用自然风光查看相同的项
现在,我们来看看该应用程序的局限性。所显示的项是硬编码的,它与该应用程序运行的 Pocket PC 无关,您要完成的是同样的项目。在这个示例中,它们是我的项目,但是如果有人真的完成了这些项目的任何部分,请通知我,我可以从工作表中将它们划掉。
这里重点展示如何将外观集成到应用程序界面,而不是如何访问和显示 Pocket Outlook? 中的任务。我会在将来的专栏中讨论这个问题。
处理 eMbedded Visual Basic 的局限性
可以这样讲,eMbedded Visual Basic 开发就是处理局限性的练习。如果要将外观添加到应用程序中,有几个问题需要注意:
第一个问题,本来我想简单地将外观图像放到表单的 Picture 属性中,就象我处理 Visual Basic 应用程序一样,但问题是 eMbedded Visual Basic 表单并没有 Picture 属性。
第二个选择是使用 Image 控件控制外观,并调整 Image 控件的大小来适应表单的大小。这可用于显示外观效果;但是,Image 控件并不支持任何类型的单击事件,也就是说我永远也不能处理按钮。
第三个选择是 Picture Box 控件,它允许插入外观,也响应单击 - 看起来很完美。然而,只是接近完美。eMbedded Visual Basic Picture Box 控件与其相应的 Visual Basic 控件在处理上稍有不同:Visual Basic 的控件用作容器,也就是说,拖到 Picture Box 顶部的其他控件保留在 Picture Box 顶部;eMbedded Visual Basic 的控件并不这样处理,拖到 eMbedded Visual Basic Picture Box 顶部的控件显示在它后面。要修正这一点,需要设置每个控件的 ZOrder 属性,使它们显示在 Picture Box 的前面。
设计外观
结构问题解决了,我们可以将注意力转到目前的任务 - 实现外观上。我采用的方法涉及两个文件:外观图像和配置文件。外观图像是显示给用户的;配置文件定义了按钮在外观上的位置、显示文本的位置以及显示文本时使用的颜色。 下面是我使用的配置文件设计示例。您可以看出它并不复杂,并且我已经在文件中嵌入了注释,这种方法使文件易于处理和修改。
注意:按钮坐标定义了每个按钮的左上角和右下角。
' Heading location. 400 1000 ' Item location. 600 1200 ' Button 1. 1200 15 1500 180 ' Button 2. 1550 15 1850 180 ' Button 3. 1900 15 2200 180 ' Button 4. 2250 15 2550 180 ' Button 5. 2600 15 2900 180 ' Button 6 2950 15 3250 180 ' Button 7 3300 15 3600 180 ' Heading color. 65535 ' Item color. 16777215 |
Private Sub Form_Load() ' Configure the menu. ConfigureMenu ' Position and size the background. picSkin.Left = 0 picSkin.Top = 0 picSkin.Width = frmSkinDemo.ScaleWidth picSkin.Height = frmSkinDemo.ScaleHeight ' Set the default skin. strCurrentSkin = "golf" picSkin.Picture = App.Path & "\" & strCurrentSkin & ".bmp" ' Load the coordinates for the skin. LoadCoordinates ' Hard code a set of dates. datWeek(1) = CDate("11-25-2001") datWeek(2) = CDate("11-26-2001") datWeek(3) = CDate("11-27-2001") datWeek(4) = CDate("11-28-2001") datWeek(5) = CDate("11-29-2001") datWeek(6) = CDate("11-30-2001") datWeek(7) = CDate("12-01-2001") ' Set the starting date. datCurrent = datWeek(2) ' Display today's appointments. DisplayAppointments End Sub |
Sub ConfigureMenu() ' This routine builds the Skins menu based upon the skins that are present on the device. Dim mnuSkins As MenuBarMenu Dim strDir As String Dim strSkin As String ' Create the Skins menu. Set mnuSkins = ceMenuBar.Controls.AddMenu("Skins", "skins") ' Use the File System control to get a list of the available skins. ' Start with the first skin. strDir = ceFileSystem.Dir(App.Path & "\*.bmp") ' Grab the rest of the skins. Do While strDir <> "" strSkin = Mid(strDir, 1, Len(strDir) - 4) mnuSkins.Items.Add , strSkin, strSkin strDir = ceFileSystem.Dir Loop End Sub |
Sub LoadCoordinates() Dim intDay As Integer Dim intLocs As Integer Dim strJunk As String ' Open the configuration file for the current skin. ceFile.Open App.Path & "\" & strCurrentSkin & ".cfg", fsModeInput, fsAccessRead ' Load the heading location. strJunk = ceFile.LineInputString intDateLocX = ceFile.LineInputString intDateLocY = ceFile.LineInputString ' Load the item location. strJunk = ceFile.LineInputString intAppointmentLocX = ceFile.LineInputString intAppointmentLocY = ceFile.LineInputString ' Load the button locations. For intDay = 1 To 7 strJunk = ceFile.LineInputString For intLocs = 1 To 4 intButtons(intDay, intLocs) = CInt(ceFile.LineInputString) Next intLocs Next intDay ' Load text colors. strJunk = ceFile.LineInputString lngTitleColor = ceFile.LineInputString strJunk = ceFile.LineInputString lngItemColor = ceFile.LineInputString ' Clean up. ceFile.Close End Sub |
Sub DisplayAppointments() ' This routine displays the appointments for the selected date. Dim strDayOfWeek As String ' Clear off previous appointment information. picSkin.Cls ' Display the present date. picSkin.FontBold = True picSkin.ForeColor = lngTitleColor Select Case DatePart("w", datCurrent) Case 1: strDayOfWeek = "Sunday" Case 2: strDayOfWeek = "Monday" Case 3: strDayOfWeek = "Tuesday" Case 4: strDayOfWeek = "Wednesday" Case 5: strDayOfWeek = "Thursday" Case 6: strDayOfWeek = "Friday" Case 7: strDayOfWeek = "Saturday" End Select picSkin.DrawText strDayOfWeek & ", " & MonthName(Month(datCurrent)) & " " & _ Day(datCurrent) & " " & Year(datCurrent), intDateLocX, intDateLocY ' Display the appointments for this date. ' NOTE: These are hard-coded just for the purpose of this demo. picSkin.FontBold = False picSkin.ForeColor = lngItemColor Select Case strDayOfWeek Case "Sunday" picSkin.DrawText "no appointments today", intAppointmentLocX, intAppointmentLocY Case "Monday" picSkin.DrawText "08:00 drop car off", intAppointmentLocX, intAppointmentLocY Case "Tuesday" picSkin.DrawText "10:00 status meeting", intAppointmentLocX, intAppointmentLocY picSkin.DrawText "13:00 presentation to management", _ intAppointmentLocX, intAppointmentLocY + 200 Case "Wednesday" picSkin.DrawText "09:30 conference call", intAppointmentLocX, intAppointmentLocY picSkin.DrawText "11:00 interview", intAppointmentLocX, intAppointmentLocY + 200 picSkin.DrawText "14:00 product meeting", intAppointmentLocX, intAppointmentLocY + 400 picSkin.DrawText "15:30 doctor appointment", intAppointmentLocX,_ intAppointmentLocY + 600 Case "Thursday" picSkin.DrawText "10:00 project meeting", intAppointmentLocX, intAppointmentLocY picSkin.DrawText "14:00 presentation to management", _ intAppointmentLocX, intAppointmentLocY + 200 Case "Friday" picSkin.DrawText "12:00 lunch with Lauren", intAppointmentLocX, intAppointmentLocY Case "Saturday" picSkin.DrawText "10:00 soccer game", intAppointmentLocX, intAppointmentLocY End Select End Sub |
Private Sub ceMenuBar_MenuClick(ByVal Item As MenuBarLib.Item) ' Change the skin. strCurrentSkin = Item.Caption picSkin.Picture = App.Path & "\" & strCurrentSkin & ".bmp" LoadCoordinates DisplayAppointments End Sub |
Private Sub picSkin_MouseDown(ByVal Button As Long, ByVal Shift As Long, _ ByVal x As Double, ByVal y As Double) Dim intCounter As Integer ' Uncomment this line to help debug your button locations. ' MsgBox "X:" & x & " Y:" & y ' Check to see if the user tapped a button. For intCounter = 1 To 7 If (x >= intButtons(intCounter, 1)) Then If (y >= intButtons(intCounter, 2)) Then If (x <= intButtons(intCounter, 3)) Then If (y <= intButtons(intCounter, 4)) Then datCurrent = datWeek(intCounter) DisplayAppointments End If End If End If End If Next intCounter End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者