Imports System.DrawingPublic Class Form1    Public Structure StaticValue
        Public Value As Integer
        Public CurrentTime As String
    End Structure    'Public Structure CPUStatics
    '    Public MinY As Integer
    '    Public MaxY As Integer
    Public CriticalLine As Integer
    Public StaticValues As new ArrayList
    Public RefreshRate As Integer    'End Structure    ' Private CPUStatic As CPUStatics
    Public Const UNITDISTANCE = 10
    Public Const UNITPOINTS = 4
    Public CPUBitmap As Bitmap
    Public g As Drawing.Graphics
    Public rdm As New Random()    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CriticalLine = 90
        RefreshRate = 1000
        Timer1.Interval = RefreshRate
        Timer1.Enabled = True
        DrawCurve()
    End Sub    Sub DrawCurve()
        Dim CPUPoints() As PointF
        If StaticValues.Count <= 0 Then Exit Sub        ReDim CPUPoints(StaticValues.Count - 1)
        Dim TotalLength As Integer = PictureBox1.Width / UNITPOINTS        If TotalLength > CPUPoints.Length Then
            For i As Integer = TotalLength - CPUPoints.Length To TotalLength - 1
                CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * i
                CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100
            Next
        Else
            For i As Integer = 0 To TotalLength - 1
                CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * i
                CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100
            Next
        End If        g.Clear(Color.Black)
        g.DrawLine(Pens.LightGreen, 0, PictureBox1.Height Mod UNITDISTANCE, _
                         PictureBox1.Width, PictureBox1.Height Mod UNITDISTANCE)
        For i As Integer = PictureBox1.Height Mod UNITDISTANCE To PictureBox1.Height Step UNITDISTANCE
            g.DrawLine(Pens.DarkGreen, 0, i, PictureBox1.Width, i)
        Next        For i As Integer = UNITDISTANCE To PictureBox1.Width Step UNITDISTANCE
            g.DrawLine(Pens.DarkGreen, i, 0, i, PictureBox1.Height)
        Next        'draw critical line using RED color
        Dim CriticalY As Integer = PictureBox1.Height - PictureBox1.Height * CriticalLine / 100
        g.DrawLine(New Pen(Color.Crimson, 2.0), 0, CriticalY, PictureBox1.Width, CriticalY)        If Not CPUPoints Is Nothing Then
            If CPUPoints.Length > 1 Then
                g.DrawCurve(Pens.LightYellow, CPUPoints)
            End If
        End If        PictureBox1.Refresh()    End Sub    Sub AddCPUVaue(ByVal CPUValue As StaticValue)
        Dim tempValue As New StaticValue
        tempValue = CPUValue
        StaticValues.Add(tempValue)
        '假设每秒产生一次数据,一天最多产生86400个
        '这里只保存一天的数据
        If StaticValues.Count > 86400 Then
            StaticValues.RemoveAt(0)
        End If
    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim CPUValue As StaticValue
        CPUValue.Value = rdm.Next(50, 100)
        CPUValue.CurrentTime = "1"
        AddCPUVaue(CPUValue)
        'Debug.Print(CPUValue.Value)
        DrawCurve()    End Sub    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Not CPUBitmap Is Nothing Then CPUBitmap.Dispose()
        CPUBitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        g = Drawing.Graphics.FromImage(CPUBitmap)
        PictureBox1.Image = CPUBitmap
        PictureBox1.Refresh()    End Sub
End Class

解决方案 »

  1.   

    HWND hwnd=0;
    hwnd = FindWindow(NULL, "C:\\WINDOWS\\system32\\cmd.exe");
    if (hwnd) 

    CWnd::FromHandle(hwnd)->SetForegroundWindow(); 
    //PostMessage(hwnd, WM_CHAR, WPARAM('a'), 0);
    //PostMessage(hwnd, WM_CHAR, WPARAM(32), 0);
    //PostMessage(hwnd, WM_CHAR, WPARAM('a'), 0);
    SendMessage(hwnd,WM_CHAR,WPARAM('d'),0);
    SendMessage(hwnd,WM_CHAR,WPARAM('i'),0);
    SendMessage(hwnd,WM_CHAR,WPARAM('r'),0);PostMessage(hwnd, WM_CHAR, WPARAM(13), 0);
    AfxMessageBox("find the target console window.");

    else 
    AfxMessageBox("Can't find the target console window.");
      

  2.   

     Private Sub BackgroundWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
            Dim strIP As String = m_BWIP
            Dim strUser As String = m_BWUser
            Dim strPwd As String = m_BWPwd
            Dim bRet As Boolean = IsCanConnNE(strIP, strUser, strPwd)
            Dim tc As TreeNodeCollection = Me.NEIdenTree.Nodes
            If bRet Then
                SetNodeStatus(tc, strIP, 1)
            Else
                SetNodeStatus(tc, strIP, 2)
            End If
            e.Cancel = True
        End Sub    Private Sub DealWithBWork(ByVal status As Object)
            Try
                Dim iIndex As Integer = 0
                Dim iCount As Integer = g_NEDataList.Count
                Dim tc As TreeNodeCollection = Me.NEIdenTree.Nodes            For iIndex = 0 To iCount - 1
                    Dim TempBWork As New BackgroundWorker()
                    m_BWIP = g_NEDataList.Item(iIndex).strIP
                    m_BWUser = g_NEDataList.Item(iIndex).strUser
                    m_BWPwd = g_NEDataList.Item(iIndex).strPwd                AddHandler TempBWork.DoWork, AddressOf BackgroundWorker_DoWork
                    TempBWork.RunWorkerAsync()
                    Thread.Sleep(1000)
                    'TempBWork.CancelAsync()
                    TempBWork.Dispose()
                Next
            Catch ex As Exception
                'MessageBox.Show(ex.Message, "Dynamic Updata Network Card Data Faied!", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
      

  3.   

     Private Sub LoadXmlFile()
            Try
                Dim strCurrentPath As String = CurDir()
                Dim strCurrentfile As String = strCurrentPath + "\config.xml"
                If File.Exists(strCurrentfile) = False Then
                    Exit Sub
                End If
                Dim xmlfile As New XmlDocument
                xmlfile.Load(strCurrentfile)
                
                Dim DelayNode As XmlNode = xmlfile.DocumentElement.SelectSingleNode("FMCPU/element[@name=""DelayTime""]")
                If DelayNode Is Nothing Then
                    Exit Sub
                End If
                TSCB_CPUDelayTime.Text = DelayNode.Attributes(1).Value            Dim PecentNode As XmlNode = xmlfile.DocumentElement.SelectSingleNode("FMCPU/element[@name=""CPUPecent""]")
                If PecentNode Is Nothing Then
                    Exit Sub
                End If
                TSCB_CPUPecent.Text = PecentNode.Attributes(1).Value
                           CriticalLine = ValveTrackBar.Value
            Catch ex As Exception        End Try
        End Sub
        Private Sub SaveXmlFile()
            Try
                Dim strCurrentPath As String = CurDir()
                Dim strCurrentfile As String = strCurrentPath + "\config.xml"
                If File.Exists(strCurrentfile) = False Then
                    Exit Sub
                End If
                Dim xmlfile As New XmlDocument
                xmlfile.Load(strCurrentfile)
                Dim DelayNode As XmlNode = xmlfile.DocumentElement.SelectSingleNode("FMCPU/element[@name=""DelayTime""]")
                If DelayNode Is Nothing Then
                    Exit Sub
                End If
                DelayNode.Attributes(1).Value = TSCB_CPUDelayTime.Text            Dim PecentNode As XmlNode = xmlfile.DocumentElement.SelectSingleNode("FMCPU/element[@name=""CPUPecent""]")
                If PecentNode Is Nothing Then
                    Exit Sub
                End If
                PecentNode.Attributes(1).Value = TSCB_CPUPecent.Text
                            xmlfile.Save(strCurrentfile)
            Catch ex As Exception        End Try
            
        End Sub