frmMain.frm
上传用户:newera
上传日期:2013-10-07
资源大小:381k
文件大小:13k
源码类别:

驱动编程

开发平台:

Visual C++

  1. VERSION 5.00
  2. Object = "{82D70786-7968-46EA-836D-203AEBCA4481}#1.0#0"; "SynCtrl.dll"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  5. Begin VB.Form frmMain 
  6.    BackColor       =   &H80000005&
  7.    BorderStyle     =   0  'None
  8.    Caption         =   "cPadDraw"
  9.    ClientHeight    =   4995
  10.    ClientLeft      =   150
  11.    ClientTop       =   720
  12.    ClientWidth     =   4530
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   4995
  15.    ScaleWidth      =   4530
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin SYNCTRLLibCtl.SynDisplayCtrl SynDisplayCtrl1 
  19.       Left            =   120
  20.       OleObjectBlob   =   "frmMain.frx":0000
  21.       Top             =   3720
  22.    End
  23.    Begin SYNCTRLLibCtl.SynAPICtrl SynAPICtrl1 
  24.       Left            =   120
  25.       OleObjectBlob   =   "frmMain.frx":0024
  26.       Top             =   2760
  27.    End
  28.    Begin SYNCTRLLibCtl.SynDeviceCtrl SynDeviceCtrl1 
  29.       Left            =   120
  30.       OleObjectBlob   =   "frmMain.frx":0048
  31.       Top             =   1800
  32.    End
  33.    Begin MSComctlLib.StatusBar sbStatusBar 
  34.       Align           =   2  'Align Bottom
  35.       Height          =   270
  36.       Left            =   0
  37.       TabIndex        =   0
  38.       Top             =   4725
  39.       Width           =   4530
  40.       _ExtentX        =   7990
  41.       _ExtentY        =   476
  42.       _Version        =   393216
  43.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  44.          NumPanels       =   3
  45.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  46.             AutoSize        =   1
  47.             Object.Width           =   2805
  48.             Text            =   "Status"
  49.             TextSave        =   "Status"
  50.          EndProperty
  51.          BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  52.             Style           =   6
  53.             AutoSize        =   2
  54.             TextSave        =   "3/31/2003"
  55.          EndProperty
  56.          BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  57.             Style           =   5
  58.             AutoSize        =   2
  59.             TextSave        =   "5:35 PM"
  60.          EndProperty
  61.       EndProperty
  62.    End
  63.    Begin MSComDlg.CommonDialog dlgCommonDialog 
  64.       Left            =   3840
  65.       Top             =   720
  66.       _ExtentX        =   847
  67.       _ExtentY        =   847
  68.       _Version        =   393216
  69.    End
  70.    Begin MSComctlLib.ImageList imlToolbarIcons 
  71.       Left            =   3720
  72.       Top             =   3000
  73.       _ExtentX        =   1005
  74.       _ExtentY        =   1005
  75.       BackColor       =   -2147483643
  76.       ImageWidth      =   16
  77.       ImageHeight     =   16
  78.       MaskColor       =   12632256
  79.       _Version        =   393216
  80.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  81.          NumListImages   =   3
  82.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  83.             Picture         =   "frmMain.frx":006C
  84.             Key             =   "Pencil"
  85.             Object.Tag             =   "Pencil"
  86.          EndProperty
  87.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  88.             Picture         =   "frmMain.frx":017E
  89.             Key             =   "Eraser"
  90.             Object.Tag             =   "Eraser"
  91.          EndProperty
  92.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  93.             Picture         =   "frmMain.frx":0290
  94.             Key             =   "Stop"
  95.             Object.Tag             =   "Stop"
  96.          EndProperty
  97.       EndProperty
  98.    End
  99.    Begin MSComctlLib.Toolbar tbToolBar 
  100.       Align           =   1  'Align Top
  101.       Height          =   420
  102.       Left            =   0
  103.       TabIndex        =   1
  104.       Top             =   0
  105.       Width           =   4530
  106.       _ExtentX        =   7990
  107.       _ExtentY        =   741
  108.       ButtonWidth     =   609
  109.       ButtonHeight    =   582
  110.       Appearance      =   1
  111.       ImageList       =   "imlToolbarIcons"
  112.       _Version        =   393216
  113.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  114.          NumButtons      =   3
  115.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  116.             Key             =   "Pencil"
  117.             ImageKey        =   "Pencil"
  118.             Style           =   2
  119.          EndProperty
  120.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  121.             Key             =   "Eraser"
  122.             ImageKey        =   "Eraser"
  123.             Style           =   2
  124.          EndProperty
  125.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  126.             Key             =   "None"
  127.             ImageKey        =   "Stop"
  128.             Style           =   2
  129.          EndProperty
  130.       EndProperty
  131.    End
  132.    Begin VB.PictureBox Picture1 
  133.       AutoRedraw      =   -1  'True
  134.       AutoSize        =   -1  'True
  135.       BackColor       =   &H80000005&
  136.       BorderStyle     =   0  'None
  137.       Height          =   975
  138.       Left            =   2760
  139.       ScaleHeight     =   975
  140.       ScaleWidth      =   1455
  141.       TabIndex        =   2
  142.       Top             =   1680
  143.       Width           =   1455
  144.    End
  145.    Begin SYNCTRLLibCtl.SynPacketCtrl SynPacketCtrl1 
  146.       Left            =   120
  147.       OleObjectBlob   =   "frmMain.frx":03A2
  148.       Top             =   840
  149.    End
  150.    Begin VB.Menu mnuFile 
  151.       Caption         =   "&File"
  152.       Begin VB.Menu mnuFileNew 
  153.          Caption         =   "&New"
  154.          Shortcut        =   ^N
  155.       End
  156.       Begin VB.Menu mnuFileOpen 
  157.          Caption         =   "&Open..."
  158.          Shortcut        =   ^O
  159.       End
  160.       Begin VB.Menu mnuFileSave 
  161.          Caption         =   "&Save"
  162.          Shortcut        =   ^S
  163.       End
  164.       Begin VB.Menu mnuFileSaveAs 
  165.          Caption         =   "Save &As..."
  166.       End
  167.       Begin VB.Menu Sep 
  168.          Caption         =   "-"
  169.       End
  170.       Begin VB.Menu mnuFileExit 
  171.          Caption         =   "E&xit"
  172.       End
  173.    End
  174.    Begin VB.Menu mnuTools 
  175.       Caption         =   "&Tools"
  176.       Begin VB.Menu mnuToolsOptions 
  177.          Caption         =   "&Options..."
  178.       End
  179.    End
  180.    Begin VB.Menu mnuHelp 
  181.       Caption         =   "&Help"
  182.       Begin VB.Menu mnuHelpAbout 
  183.          Caption         =   "&About..."
  184.       End
  185.    End
  186. End
  187. Attribute VB_Name = "frmMain"
  188. Attribute VB_GlobalNameSpace = False
  189. Attribute VB_Creatable = False
  190. Attribute VB_PredeclaredId = True
  191. Attribute VB_Exposed = False
  192. Public XMin As Integer
  193. Public XMax As Integer
  194. Public YMin As Integer
  195. Public YMax As Integer
  196. Public ZTouchThreshold As Integer
  197. Public ExtentType As Integer
  198. Public UsePencil As Integer
  199. Public Utensil As Integer
  200. Const eNone As Integer = 0
  201. Const ePencil As Integer = 1
  202. Const eEraser As Integer = 2
  203. Private Sub Form_Load()
  204.   Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
  205.   Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
  206.   Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 3690)
  207.   Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 3750)
  208.   
  209.   sbStatusBar.Panels(1).MinWidth = 2100
  210.   
  211.   Me.KeyPreview = True
  212.   dlgCommonDialog.DefaultExt = "bmp"
  213.   dlgCommonDialog.Filter = "Pictures (*.bmp)|*.bmp"
  214.   SynAPICtrl1.Initialize
  215.   SynAPICtrl1.Activate ' Activate to receive device notifications
  216.   DeviceHandle = SynAPICtrl1.FindDevice(SE_ConnectionAny, SE_DevicecPad, -1)
  217.   If DeviceHandle = -1 Then
  218.     MsgBox "Unable to find a Synaptics cPad"
  219.     End
  220.   End If
  221.         
  222.   SynDeviceCtrl1.Select (DeviceHandle)
  223.   SynDeviceCtrl1.Activate 'Activate to receive pointing packets
  224.    
  225.   SynDisplayCtrl1.Select (DeviceHandle)
  226.   SynDisplayCtrl1.Activate
  227.   SynDisplayCtrl1.Acquire (SE_AcquireCooperative) 'Acquire display access
  228.     
  229.   ZTouchThreshold = SynDeviceCtrl1.GetLongProperty(SP_ZTouchThreshold)
  230.     
  231.   XMin = SynDeviceCtrl1.GetLongProperty(SP_XLoSensor)
  232.   XMax = SynDeviceCtrl1.GetLongProperty(SP_XHiSensor)
  233.   YMin = SynDeviceCtrl1.GetLongProperty(SP_YLoSensor)
  234.   YMax = SynDeviceCtrl1.GetLongProperty(SP_YHiSensor)
  235.   ExtentType = 5 'Use display mapping for device coordinates
  236.   
  237.   Picture1.Left = 0
  238.   'The toolbar height changes by 3/2 when run, so compensate the picture location by 2/3.
  239.   Picture1.Top = 2 * Me.tbToolBar.Height / 3
  240.   ' Size the picture to the same number of pixels as the Synaptics display.
  241.   ' Make sure the picturebox border attribute is "none". If it isn't,
  242.   ' the size of the image property of the picturebox will be that of the interior
  243.   ' of the picture box.
  244.   Picture1.Width = Picture1.ScaleX(SynDisplayCtrl1.GetLongProperty(SP_DisplayColumns), vbPixels, vbTwips)
  245.   Picture1.Height = Picture1.ScaleY(SynDisplayCtrl1.GetLongProperty(SP_DisplayRows), vbPixels, vbTwips)
  246.     
  247.   Utensil = eNone
  248. End Sub
  249. Private Sub Form_Unload(Cancel As Integer)
  250.   Dim i As Integer
  251.   'Make sure to free up the device and display.
  252.   SynDeviceCtrl1.Unacquire
  253.   SynDisplayCtrl1.Unacquire
  254.   
  255.   'close all sub forms
  256.   For i = Forms.Count - 1 To 1 Step -1
  257.     Unload Forms(i)
  258.   Next
  259.   
  260.   If Me.WindowState <> vbMinimized Then
  261.     SaveSetting App.Title, "Settings", "MainLeft", Me.Left
  262.     SaveSetting App.Title, "Settings", "MainTop", Me.Top
  263.     SaveSetting App.Title, "Settings", "MainWidth", Me.Width
  264.     SaveSetting App.Title, "Settings", "MainHeight", Me.Height
  265.   End If
  266. End Sub
  267. Public Sub Form_KeyPress(KeyAscii As Integer)
  268.   If KeyAscii = vbKeyEscape Then
  269.     tbToolBar_ButtonClick tbToolBar.Buttons("None")
  270.   End If
  271. End Sub
  272. Public Sub Form_Paint()
  273.   'Send a picture to the display staging area.
  274.   SynDisplayCtrl1.SendPicture Picture1.Image
  275.   'Flush it to the actual display but don't wait for completion.
  276.   SynDisplayCtrl1.Flush (SE_FlushAsynchronous)
  277. End Sub
  278. Private Sub SynAPICtrl1_OnNotify(ByVal eReason As SYNCTRLLibCtl.SynNotificationReason)
  279.   Select Case eReason
  280.     Case SE_Configuration_Changed
  281.       sbStatusBar.Panels(1).Text = "Configuration Change"
  282.     Case SE_DeviceRemoved
  283.       sbStatusBar.Panels(1).Text = "Device Removed"
  284.     Case SE_DeviceAdded
  285.       sbStatusBar.Panels(1).Text = "Device Added"
  286.   End Select
  287. End Sub
  288. Private Sub SynDeviceCtrl1_OnPacket()
  289.   Static LastX, LastY, LastFinger As Integer
  290.   Dim X, Y, Finger As Integer
  291.   Dim Color As Long
  292.   
  293.   'Load a packet object with device data
  294.   SynDeviceCtrl1.LoadPacket SynPacketCtrl1
  295.   
  296.   If ExtentType = 5 Then
  297.     X = SynDisplayCtrl1.PixelX(SynPacketCtrl1.X) * Picture1.Width / SynDisplayCtrl1.GetLongProperty(SP_DisplayColumns)
  298.     Y = SynDisplayCtrl1.PixelY(SynPacketCtrl1.Y) * Picture1.Height / SynDisplayCtrl1.GetLongProperty(SP_DisplayRows)
  299.   Else
  300.     X = (SynPacketCtrl1.X - XMin) * Picture1.Width / (XMax - XMin)
  301.     Y = (YMax - SynPacketCtrl1.Y) * Picture1.Height / (YMax - YMin)
  302.   End If
  303.   Finger = SynPacketCtrl1.FingerState And SF_FingerPresent
  304.   
  305.   If Finger And LastFinger And Utensil <> eNone Then
  306.     If SynPacketCtrl1.Z > ZTouchThreshold Then
  307.       Picture1.DrawWidth = mapZ(SynPacketCtrl1.Z)
  308.     Else
  309.       Picture1.DrawWidth = 1
  310.     End If
  311.     
  312.     Color = IIf(Utensil = ePencil, Picture1.ForeColor, Picture1.BackColor)
  313.     Picture1.Line (LastX, LastY)-(X, Y), Color
  314.     
  315.     Me.Refresh
  316.   End If
  317.     
  318.   LastX = X
  319.   LastY = Y
  320.   LastFinger = Finger
  321. End Sub
  322. Private Sub SynDisplayCtrl1_OnMessage(ByVal eMessage As SYNCTRLLibCtl.SynDisplayMessage)
  323.   'This is what is done by default if no display message handler is defined.
  324.   SynDisplayCtrl1.Flush (SE_FlushAsynchronous)
  325. End Sub
  326. Private Function mapZ(ByVal Zin As Integer) As Long
  327.   mapZ = Zin - ZTouchThreshold
  328.   mapZ = mapZ * mapZ / 100
  329.   mapZ = IIf(mapZ < 1, 1, mapZ)
  330. End Function
  331. Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
  332.   On Error Resume Next
  333.   Select Case Button.Key
  334.     Case "Pencil"
  335.       Utensil = ePencil
  336.       SynDeviceCtrl1.Acquire (0)
  337.     Case "Eraser"
  338.       Utensil = eEraser
  339.       SynDeviceCtrl1.Acquire (0)
  340.     Case "None"
  341.       Utensil = eNone
  342.       SynDeviceCtrl1.Unacquire
  343.       Button.Value = tbrUnpressed
  344.       tbToolBar.Buttons("Pencil").Value = tbrUnpressed
  345.       tbToolBar.Buttons("Eraser").Value = tbrUnpressed
  346.   End Select
  347. End Sub
  348. Private Sub mnuHelpAbout_Click()
  349.   frmAbout.Show vbModal, Me
  350. End Sub
  351. Private Sub mnuFileNew_Click()
  352.   Picture1.Cls
  353.   Picture1.Picture = Nothing
  354.   Me.Refresh
  355. End Sub
  356. Private Sub mnuFileOpen_Click()
  357.   On Error Resume Next
  358.   dlgCommonDialog.ShowOpen
  359.   If Err <> 32755 Then    ' User chose Cancel.
  360.     Picture1.Picture = LoadPicture(dlgCommonDialog.FileName)
  361.   End If
  362.   Me.Refresh
  363. End Sub
  364. Private Sub mnuFileSave_Click()
  365.   If dlgCommonDialog.FileName <> "" Then
  366.     SavePicture Picture1.Image, dlgCommonDialog.FileName
  367.   Else
  368.     mnuFileSaveAs_Click
  369.   End If
  370. End Sub
  371. Private Sub mnuFileSaveAs_Click()
  372.   On Error Resume Next
  373.   dlgCommonDialog.ShowSave
  374.   If Err <> 32755 Then    ' User chose Cancel.
  375.     SavePicture Picture1.Image, dlgCommonDialog.FileName
  376.   End If
  377. End Sub
  378. Private Sub mnuToolsOptions_Click()
  379.   frmOptions.Show vbModal, Me
  380. End Sub
  381. Private Sub mnuFileExit_Click()
  382.   Unload Me
  383. End Sub