-
Sep 11th, 2017, 09:25 PM
#1
Thread Starter
Fanatic Member
[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?
-
Sep 11th, 2017, 09:33 PM
#2
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
-
Sep 12th, 2017, 08:43 AM
#3
Thread Starter
Fanatic Member
Re: Problem With systemtry icon
Originally Posted by LaVolpe
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.
-
Sep 12th, 2017, 08:59 AM
#4
Thread Starter
Fanatic Member
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.....
-
Sep 12th, 2017, 09:01 AM
#5
Re: Problem With systemtry icon
Originally Posted by flyguille
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 09:07 AM.
-
Sep 12th, 2017, 09:18 AM
#6
Thread Starter
Fanatic Member
Re: Problem With systemtry icon
Originally Posted by DEXWERX
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.
-
Sep 12th, 2017, 09:00 AM
#7
Thread Starter
Fanatic Member
Re: Problem With systemtry icon
I change back to twips mode, and it didn't fixed it.
-
Sep 12th, 2017, 08:49 AM
#8
Thread Starter
Fanatic Member
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 08:54 AM.
-
Sep 12th, 2017, 08:57 AM
#9
Re: Problem With systemtry icon
Originally Posted by flyguille
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.
-
Sep 12th, 2017, 09:22 AM
#10
Thread Starter
Fanatic Member
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?
-
Sep 12th, 2017, 10:16 AM
#11
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
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 10:23 AM.
Reason: commenting on overflow
-
Sep 12th, 2017, 11:00 AM
#12
Thread Starter
Fanatic Member
Re: Problem With systemtry icon
Originally Posted by DEXWERX
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?
-
Sep 12th, 2017, 11:12 AM
#13
Re: Problem With systemtry icon
Originally Posted by flyguille
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
-
Sep 12th, 2017, 12:22 PM
#14
Thread Starter
Fanatic Member
Re: Problem With systemtry icon
Originally Posted by dexwerx
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
-
Sep 12th, 2017, 12:23 PM
#15
Thread Starter
Fanatic Member
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 12: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|