[RESOLVED] Problem With systemtry icon-VBForums
Results 1 to 17 of 17

Thread: [RESOLVED] Problem With systemtry icon

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Resolved [RESOLVED] Problem With systemtry icon

    I have an app with an systemtry icon since ever, it worked ever, but since recent compilations, it stop working.

    The icon is placed, but when clicked don't trigger the FORM EVENT expected, at all.

    The code I am using

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    If x = 7725 Then
        ' Hizo doble click en el icono systry.
        Me.Show
        Call Shell_NotifyIcon(NIM_DELETE, Try)
    End If
    
    End Sub
    
    Private Sub LabelLusers_DblClick()
    
    ' Debe enviar el servidor al systry.
    Try.cbSize = Len(Try)
    Try.hwnd = Me.hwnd
    Try.uId = vbNull
    Try.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    Try.uCallBackMessage = WM_MOUSEMOVE
    Try.hIcon = Me.Icon
    Try.szTip = "FlulpyCreaŽ Server v" + Trim$(Str$(App.Major)) + "." + Trim$(Str$(App.Minor)) + "." + Trim$(Str$(App.Revision)) & vbNullChar
    
    Call Shell_NotifyIcon(NIM_ADD, Try)
    Call Shell_NotifyIcon(NIM_MODIFY, Try)
    
    Me.Visible = False
    
    End Sub

    and ...

    Code:
    ' Icono en el systry.
    Public Type NOTIFYICONDATA
         cbSize As Long
         hwnd As Long
         uId As Long
         uFlags As Long
         uCallBackMessage As Long
         hIcon As Long
         szTip As String * 64
    End Type
    
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const WM_MOUSEMOVE = &H200
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    
    Public Const WM_LBUTTONDBLCLK = &H203
    Public Const WM_LBUTTONDOWN = &H201
    Public Const WM_LBUTTONUP = &H202
    
    
    Public Const WM_RBUTTONDBLCLK = &H206
    Public Const WM_RBUTTONDOWN = &H204
    Public Const WM_RBUTTONUP = &H205
    
    Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, ptry As NOTIFYICONDATA) As Boolean
    
    Public Try As NOTIFYICONDATA


    Maybe it stopped working when migrating from VB5 to VB6, but unsure. As I didn't touched this code, I am very surprice.

    What is happening?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,639

    Re: Problem With systemtry icon

    Did you change the form's scalemode? Based on your posted code, Twips is expected and based on that value 7725, you are trapping a left button double click. That hard coded value will fail if your app is DPI-aware and DPI is other than 100%.

    FYI: 7725 / 15 = 515
    15 = twips per pixel at 96 DPI
    515 = WM_LButtonDblClick
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    Quote Originally Posted by LaVolpe View Post
    Did you change the form's scalemode? Based on your posted code, Twips is expected and based on that value 7725, you are trapping a left button double click. That hard coded value will fail if your app is DPI-aware and DPI is other than 100%.

    FYI: 7725 / 15 = 515
    15 = twips per pixel at 96 DPI
    515 = WM_LButtonDblClick
    regardless the code 7725, I trap the execution of MouseMove and it isn't called at all when double click in the system icom....

    but maybe I changed it to pixel scalemode.... I will check.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    But what means the code? why it is based on twips and that?

    never mind, you already told it.
    Last edited by flyguille; Sep 12th, 2017 at 09:54 AM.

  5. #5
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,552

    Re: Problem With systemtry icon

    Quote Originally Posted by flyguille View Post
    But what means the code? why it is based on twips and that?
    uCallBackMessage is used to tell the API to callback your form via whatever message you specify.

    you set it to WM_MOUSEMOVE, so you don't have to worry about subclassing the form.

    WM_MOUSEMOVE uses Pixels and the VB runtime auto scales the X and Y based on the forms ScaleMode, before passing them on to your Form_MouseMove. the lParam is what you are interested in, which ends up being scaled and put into X.
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    hmmm maybe I did the actual form larger like width=8190 twips, and that broke it? before it was less than 7725.....

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    I change back to twips mode, and it didn't fixed it.

  8. #8
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,552

    Re: Problem With systemtry icon

    Quote Originally Posted by flyguille View Post
    hmmm maybe I did the actual form larger like width=8190 twips, and that broke it? before it was less than 7725.....
    you could just use a separate hidden form for responding to the Tray event

    or subclass the form, and use a different message instead of colliding the mousemove.
    the code basically works by assuming you will almost never have the mouse at exactly 7725 twips
    a small price to pay for those afraid of subclassing.

    Also as LAvolpe mentioned if you have any sort of DPI Awareness in your manifest, all assumptions are off.
    I could see it failing even without DPI Awareness, if your DPI is not 100%
    Last edited by DEXWERX; Sep 12th, 2017 at 10:07 AM.
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    Quote Originally Posted by DEXWERX View Post
    you could just use a separate hidden form for responding to the Tray event

    or subclass the form, and use a different message instead of colliding the mousemove.
    the code basically works by assuming you will almost never have the mouse at exactly 7725 twips
    a small price to pay for those afraid of subclassing.

    Also as LAvolpe mentioned if you have any sort of DPI Awareness in your manifest, all assumptions are off.
    I could see it failing even without DPI Awareness, if your DPI is not 100%

    I already tried it, and it don't execute the MouseMove event at all, and I don't understand why...

    I tested it in IDE mode and compiled mode.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    Include I can test an old compilation that it is VB6 and it works, but, I changed it later to pixel scalemode, and it stop working, well, now it is back in twips mode, and it don't works , it is not matter about the number, it don't executes the mousemove at all.

    What other property in the form object can broke it?

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    I just tried the hidden default form fix, and IT WORKS!...

    WEIRD WEIRD WEIRD..

    thanks

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    which others numbers to test apart from 7725, lets said DPI is different , which is usual to find?

  13. #13
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,552

    Re: Problem With systemtry icon

    hopefully this makes it more clear whats going on.
    I tried to reverse the X and Y to original lParam.
    It may not be needed as the messages would really only be in the low order word anyway.

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Const WM_LBUTTONDBLCLK As Long = &H203
        Dim lParam As Long
    '    lParam = (X / TwipsPerPixelX) Or (Y / TwipsPerPixelY * &H10000) ' potential overflow
        lParam = X / TwipsPerPixelX
        Select Case lParam
            Case WM_LBUTTONDBLCLK
                Show
                Call Shell_NotifyIcon(NIM_DELETE, Try)
        End Select
    End Sub
    no more magic numbers
    Quote Originally Posted by Wikipedia
    The term magic number or magic constant also refers to the programming practice of using numbers directly in source code. This has been referred to as breaking one of the oldest rules of programming, dating back to the COBOL, FORTRAN and PL/1 manuals of the 1960s.[9] The use of unnamed magic numbers in code obscures the developers' intent in choosing that number,[10] increases opportunities for subtle errors (e.g. is every digit correct in 3.14159265358979323846 and is this equal to 3.14159?) and makes it more difficult for the program to be adapted and extended in the future.
    Last edited by DEXWERX; Sep 12th, 2017 at 11:23 AM. Reason: commenting on overflow
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    Quote Originally Posted by DEXWERX View Post
    hopefully this makes it more clear whats going on.
    I tried to reverse the X and Y to original lParam.
    It may not be needed as the messages would really only be in the low order word anyway.

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Const WM_LBUTTONDBLCLK As Long = &H203
        Dim lParam As Long
    '    lParam = (X / TwipsPerPixelX) Or (Y / TwipsPerPixelY * &H10000) ' potential overflow
        lParam = X / TwipsPerPixelX
        Select Case lParam
            Case WM_LBUTTONDBLCLK
                Show
                Call Shell_NotifyIcon(NIM_DELETE, Try)
        End Select
    End Sub
    no more magic numbers
    I feel culprit of using magic numbers in propietary binary protocols, and not using proper constants naming and using them instead the numbers. But I wrote separated TXTs enumerating all the codes , how to use them and what is expected in return.... is that bad anyway?

  15. #15
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,552

    Re: Problem With systemtry icon

    Quote Originally Posted by flyguille View Post
    I feel culprit of using magic numbers in propietary binary protocols, and not using proper constants naming and using them instead the numbers. But I wrote separated TXTs enumerating all the codes , how to use them and what is expected in return.... is that bad anyway?

    It just makes the code harder to read.
    if you're the only person maintaining the code, I guess it doesn't matter.

    This is just a perfect example of why not to use magic numbers.
    If it was written without magic numbers, you wouldn't have to ask how to adapt or extend the code to other events.

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X = 7725 Then
                Show
                Call Shell_NotifyIcon(NIM_DELETE, Try)
        End If
    End Sub
    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Const WM_LBUTTONDBLCLK As Long = &H203
        Select Case X / TwipsPerPixelX
            Case WM_LBUTTONDBLCLK
                Show
                Call Shell_NotifyIcon(NIM_DELETE, Try)
        End Select
    End Sub
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: Problem With systemtry icon

    Quote Originally Posted by dexwerx View Post
    it just makes the code harder to read.
    If you're the only person maintaining the code, i guess it doesn't matter.

    This is just a perfect example of why not to use magic numbers.
    If it was written without magic numbers, you wouldn't have to ask how to adapt or extend the code to other events.

    Code:
    private sub form_mousemove(button as integer, shift as integer, x as single, y as single)
        if x = 7725 then
                show
                call shell_notifyicon(nim_delete, try)
        end if
    end sub
    Code:
    private sub form_mousemove(button as integer, shift as integer, x as single, y as single)
        const wm_lbuttondblclk as long = &h203
        select case x / twipsperpixelx
            case wm_lbuttondblclk
                show
                call shell_notifyicon(nim_delete, try)
        end select
    end sub
    done! :d

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    529

    Re: [RESOLVED] Problem With systemtry icon

    the only thing, why the **** it didn't worked back when move back to TWIPs scalemode. It is sensitive to others properties?. Enabled was TRUE, the only other thing I can think of.
    Last edited by flyguille; Sep 12th, 2017 at 01:27 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.