Results 1 to 13 of 13

Thread: variable txt in Tray

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    41

    Question variable txt in Tray

    Hi,

    I want to show a text in the tray. But I must create this text while the prog is running.

    I´ve tried to print text to a picturebox with "print" and get the "image" over the .picture method.. But it doesn´t work ...

    Greetings

    Byte

  2. #2

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: variable txt in Tray

    Or, a tooltip. I'm not sure how the weather programs display the temperature in the system tray.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: variable txt in Tray

    Or this..
    Add to your Form: 1 imagelist, 1 picturebox, 1 command button
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type NotifyIconData
    4.     Size              As Long
    5.     Handle            As Long
    6.     ID                As Long
    7.     Flags             As Long
    8.     CallBackMessage   As Long
    9.     Icon              As Long
    10.     Tip               As String * 64
    11. End Type
    12.  
    13. Private Declare Function Shell_NotifyIcon _
    14.     Lib "shell32" Alias "Shell_NotifyIconA" ( _
    15.     ByVal Message As Long, Data As NotifyIconData) As Boolean
    16.  
    17. Private Const AddIcon = &H0
    18. Private Const ModifyIcon = &H1
    19. Private Const DeleteIcon = &H2
    20. Private Const WM_MOUSEMOVE = &H200
    21. Private Const WM_LBUTTONDBLCLK = &H203
    22. Private Const MessageFlag = &H1
    23. Private Const IconFlag = &H2
    24. Private Const TipFlag = &H4
    25.  
    26. Private Data      As NotifyIconData
    27. Private mNumTray  As Long 'Just to add a number
    28.  
    29. Private Sub Command1_Click()
    30.     Randomize
    31.     Picture1.Cls
    32.     Picture1.BackColor = vbBlue * Rnd(10000)
    33.     Picture1.ForeColor = vbWhite * Rnd(10000)
    34.     mNumTray = mNumTray + 1
    35.     Picture1.Print CStr(mNumTray)
    36.     ImageList1.ListImages.Remove 1
    37.     ImageList1.ListImages.Add 1, , Picture1.Image
    38.     AddIconToTray (ModifyIcon)
    39. End Sub
    40.  
    41. Private Sub Form_Load()
    42.     mNumTray = 0
    43.     Picture1.ScaleMode = vbPixels
    44.     Picture1.AutoRedraw = True
    45.     Picture1.Width = 1200
    46.     Picture1.Height = 1200
    47.     Picture1.BackColor = vbBlue
    48.     Picture1.ForeColor = vbWhite
    49.     Picture1.Font.Size = 52
    50.     Picture1.CurrentX = 10
    51.     Picture1.CurrentY = 1
    52.     Picture1.Print CStr(mNumTray)
    53.     ImageList1.ListImages.Add 1, , Picture1.Image
    54.     AddIconToTray (AddIcon)
    55.     Visible = False
    56. End Sub
    57.  
    58. Private Sub Form_Terminate()
    59.     DeleteIconFromTray
    60. End Sub
    61.  
    62. Private Sub AddIconToTray(pEvent As Long)
    63.     Data.Size = Len(Data)
    64.     Data.Handle = hwnd
    65.     Data.ID = vbNull
    66.     Data.Flags = IconFlag Or TipFlag Or MessageFlag
    67.     Data.CallBackMessage = WM_MOUSEMOVE
    68.     Data.Icon = ImageList1.ListImages(1).ExtractIcon
    69.     Data.Tip = "Dynamic Systray Icon" & vbNullChar
    70.     Call Shell_NotifyIcon(pEvent, Data)
    71. End Sub
    72.  
    73. Private Sub DeleteIconFromTray()
    74.     Call Shell_NotifyIcon(DeleteIcon, Data)
    75. End Sub
    76.  
    77. Private Sub Form_MouseMove(Button As Integer, _
    78.         Shift As Integer, X As Single, Y As Single)
    79.    
    80.     Dim Message As Long
    81.     Message = X / Screen.TwipsPerPixelX
    82.    
    83.     Picture1.BackColor = ImageList1.MaskColor
    84.     Select Case Message
    85.         Case WM_LBUTTONDBLCLK
    86.             Visible = Not Visible
    87.             WindowState = Abs(Not Visible)
    88.     End Select
    89. End Sub
    The app will start minimized, so double click the tray icon to see the Form.
    change tray icon by clicking the button, it will generate different number to show, with different background color.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: variable txt in Tray

    Very cool. Sorry I have to spread some points out before I can rate you. That is worth a few points. I've saved it as a future sample. Thanks.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: variable txt in Tray

    No prob DG
    That's common system tray stuff, the only interesting add here is the "ExtractIcon" method of Imagelist, this is one of the few ( if not the only) way to create icons at runtime, and also works when wanting to change the Form icon at runtime.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: variable txt in Tray

    You should post that in the CodeBank. I don't recall ever seeing it before.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    41

    Re: variable txt in Tray

    Hi,

    thanks for the answers. I will try it!

    How can I rate someone ?

    greetings

    byte

  9. #9
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: variable txt in Tray

    Quote Originally Posted by dglienna
    You should post that in the CodeBank. I don't recall ever seeing it before.
    Ok, posted in the Codebank, with new stuff: Transparent background for Form Icons and Random colored background and text for Tray Icons.
    Here is the link: Icons at runtime

  10. #10
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: variable txt in Tray

    to rate someone, ByteChanger, find the member you wish to rate and then below all the info about that user there is a link called ' Rate this post' click on it and that is how it is done. make sense
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

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

    Re: variable txt in Tray

    Quote Originally Posted by dglienna
    Very cool. Sorry I have to spread some points out before I can rate you. That is worth a few points. I've saved it as a future sample. Thanks.
    Me too and me too.

    If you don't put this in the CodeBank, I will!

    In fact, in addition to the code, why don't you put together a sample project on how to use it.

  12. #12
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: variable txt in Tray

    Quote Originally Posted by Hack
    In fact, in addition to the code, why don't you put together a sample project on how to use it.
    I added the code in the CodeBank and a Project is attached to it as a sample (the code in the sample is the same that the code in that post).

  13. #13
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: variable txt in Tray

    Nice stuff jcis!!
    Show Appreciation. Rate Posts.

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