Results 1 to 9 of 9

Thread: [RESOLVED] I want task manager waveform graphic on my Form

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Resolved [RESOLVED] I want task manager waveform graphic on my Form

    All,

    How can I achieve this? I have serached the forums and been digging around for quite some time on this issue.

    Has anyone been able to do this? A little green box like the one you see in the systray would be acceptable, but the green waveform is preferred (like the supplied pic)

    Ideally, I would also like to store the values in a file as time goes on.

    Thanks!
    Attached Images Attached Images  
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I want task manager waveform graphic on my Form

    This will give you a start. I found this piece of code on a web page that isn't there any longer (at least the link I saved no longer works). I thought it was kind of cool, so I popped it in my Code Library in case I ever needed anything like it. Right now it just draws an ever scrolling wave type graph, but I'm sure you can tweak it so that it is graphing based on an actual something. Anyway, play around with this. It uses a Picturebox and a Timer control.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    4. Private Const PS_SOLID = 0
    5.  
    6. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    7.  
    8. Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
    9. (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    10.  
    11. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
    12. ByVal hObject As Long) As Long
    13.  
    14. Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, _
    15. ByVal nWidth As Long, ByVal crColor As Long) As Long
    16.  
    17. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
    18. ByVal y As Long) As Long
    19.  
    20. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, _
    21. ByVal x As Long, ByVal y As Long, ByVal lpPoint As Long) As Long
    22.  
    23. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
    24. ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
    25. ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
    26. ByVal dwRop As Long) As Long
    27.  
    28. Private Const pWidth = 250    ' Width of picture box in pixels.
    29. Private Const pHeight = 150   ' Height of picture box in pixels.
    30. Private Const pGrid = 25      ' Distance between grid lines.
    31. Private Const tInterval = 100 ' Interval between timer samplings
    32.                               ' in milliseconds.
    33. Private Const pHeightHalf = pHeight \ 2
    34. Private counter As Long  ' Number of data points logged so far. Used to
    35.                      ' sync grid.
    36. Private oldY As Long     ' Contains the previous y coordinate.
    37. Private hDCh As Long, hPenB As Long, hPenC As Long
    38.  
    39. Private Sub Form_Load()
    40. Dim hBmp As Long
    41.     Dim i As Integer
    42.     Me.Show
    43.     Picture1.ScaleMode = 3
    44.     Picture1.Left = 0
    45.     Picture1.Top = 0
    46.     Form1.ScaleMode = 3
    47.     Picture1.Height = 155
    48.     Picture1.Width = 255
    49.     counter = 0
    50.     hDCh = CreateCompatibleDC(Picture1.hdc)
    51.     hBmp = CreateCompatibleBitmap(Picture1.hdc, pWidth, pHeight)
    52.     Call SelectObject(hDCh, hBmp)
    53.     hPenB = CreatePen(PS_SOLID, 0, vbBlack)
    54.     hPenC = CreatePen(PS_SOLID, 0, vbRed)
    55.     Call SelectObject(hDCh, hPenB)
    56.  
    57. ' Plot horizontal grid lines.
    58.     For i = pGrid To pHeight - 1 Step pGrid
    59.         Picture1.Line (0, i)-(pWidth, i)
    60.     Next
    61.  
    62. ' Plot vertical grid lines.
    63.     For i = pGrid - (counter Mod pGrid) To pWidth - 1 Step pGrid
    64.         Picture1.Line (i, 0)-(i, pHeight)
    65.     Next
    66.  
    67.     Call BitBlt(hDCh, 0, 0, pWidth, pHeight, Picture1.hdc, 0, 0, SRCCOPY)
    68.     Timer1.Interval = 100
    69.     Timer1.Enabled = True
    70.     oldY = pHeightHalf
    71. End Sub
    72.  
    73. Private Sub Timer1_Timer()
    74. Dim i As Integer
    75. Call BitBlt(hDCh, 0, 0, pWidth - 1, pHeight, hDCh, 1, 0, SRCCOPY)
    76.  
    77.     If counter Mod pGrid = 0 Then
    78.         Call MoveToEx(hDCh, pWidth - 2, 0, 0)
    79.         Call LineTo(hDCh, pWidth - 2, pHeight)
    80.     End If
    81.  
    82.     i = Sin(0.1 * counter) * (pHeightHalf - 1) + pHeightHalf
    83.  
    84.     Call SelectObject(hDCh, hPenC)
    85.     Call MoveToEx(hDCh, pWidth - 3, oldY, 0)
    86.     Call LineTo(hDCh, pWidth - 2, i)
    87.     Call SelectObject(hDCh, hPenB)
    88.     Call BitBlt(Picture1.hdc, 0, 0, pWidth, pHeight, hDCh, 0, 0, SRCCOPY)
    89.     counter = counter + 1
    90.     oldY = i
    91. End Sub

  3. #3

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: I want task manager waveform graphic on my Form

    Yes that is a great start! I believe I might be able to dig up some APIs for accessing the system resource usage..?... Once I do, I should be able to plug those results directly into this graph. Cool!
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I want task manager waveform graphic on my Form

    When you get something that you like that is based on actual data (regardless of the source), post a sample project in the CodeBank.

    I think others could benefit from something like this as well.

  5. #5

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: I want task manager waveform graphic on my Form

    I will - my plan is to create a stand-alone OCX that is self-aware of it's source - in this case the Task Manager, but I have other uses for it as well.

    The only banana-peel I can see is they set the scale-mode of the sample form to 3... Not sure how that will affect my normal Forms which always use the default scale-mode...
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: I want task manager waveform graphic on my Form

    Using the class from this thread:
    http://www.vbforums.com/showthread.php?t=324335

    I made this:

    [Edit] See my next post
    Last edited by CVMichael; Mar 21st, 2006 at 02:15 PM.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I want task manager waveform graphic on my Form

    Quote Originally Posted by CVMichael
    Using the class from this thread:
    http://www.vbforums.com/showthread.php?t=324335

    I made this:
    Put your project in the CodeBank.

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: I want task manager waveform graphic on my Form

    Quote Originally Posted by Hack
    Put your project in the CodeBank.
    OK..
    Done:
    VB - Showing the CPU graph like in Windows Task Manager

    (I'll delete the attachment in the previous post, since now it's in the CodeBank)

  9. #9

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: I want task manager waveform graphic on my Form

    So cool CVMichael! I hope you don't mind I adapted your creation and posted it under your CodeBank post. So cool...

    Here is a quick pic of the SmartControls.TaskMonitor as I just dropped it on a blank form and resized it and pressed F5!
    Attached Images Attached Images  
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width