I have a program that is minimized to the tray. Left click on the tray icon pops up the program. Right click pops up a menu and you can select pop up the main form or terminate the program.
It works on every computer except one client machine. On that machine it appears the tray icon does not receive any mouse messages except it does display a tool tip when you hover over the icon.
I am using the exact same code on another program and it does work on that machine. Both built with FF3 and compiled with PB9.
Here is the code to create the form and process the mouse messages from the tray icon:
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ ' optional user defined Long value
) As Long
Dim sIP As String
Dim sPO As String
Dim ip As Long
Dim p As Byte Ptr
Dim wk As String
Dim i As Long
Dim dwIP As Dword
Dim hDBF_CFG As Long
Local lngSystemMenu As Long 'Handle to System Menu in titlebar
Local mi As MENUITEMINFO
Local tempsz As Asciiz * 10
Local ver As String
Dim UName As Asciiz * 30
SendMessage HWND_FORMRECEIVETAB_RICHEDIT1, %EM_SETTARGETDEVICE, 0, 0 'Set the RTF control to have word wrap on
GetUserName(UName,20)
mi.cbSize=SizeOf(mi)
mi.fMask= %MIIM_TYPE Or %MIIM_STATE Or %MIIM_ID
mi.fType= %MF_STRING
mi.wID= %WM_SYSHIDE
tempsz= "&Hide"
mi.dwTypeData= VarPtr(tempsz)
lngSystemMenu = GetSystemMenu(HWND_FORM1, 0)
RemoveMenu lngSystemMenu, %SC_SIZE, %MF_BYCOMMAND 'no resize
RemoveMenu lngSystemMenu, %SC_RESTORE, %MF_BYCOMMAND 'no restore
RemoveMenu lngSystemMenu, %SC_MINIMIZE, %MF_BYCOMMAND 'no minimize
RemoveMenu lngSystemMenu, %SC_MAXIMIZE, %MF_BYCOMMAND 'no maximize
InsertMenuItem(lngSystemMenu, 0, %TRUE, mi)
ti.cbSize = SizeOf(ti)
ti.hWnd = HWND_FORM1
ti.uID = App.hInstance
ti.uFlags = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
ti.uCallbackMessage = %WM_TRAYICON
ti.hIcon = LoadImage(App.hInstance, "TRAYICON", %IMAGE_ICON, 16, 16, %LR_SHARED)
ti.szTip = "Click to pop-up ApotheSoft Messages"
Shell_NotifyIcon %NIM_ADD, ti
'Add items to Tray Menu
trayMenu= CreatePopupMenu()
'I just reuse the mi structure from above
'mi.wID= %WM_MENURESTORE
mi.wID = 1
mi.fState= %MFS_DEFAULT
tempsz= "&Quit"
InsertMenuItem(trayMenu, &HFFFFFFFF, %TRUE, mi)
'mi.wID= %WM_MENUABOUT
mi.wID = 2
mi.fState= %MF_ENABLED
tempsz= "&Hide"
InsertMenuItem(trayMenu, &HFFFFFFFF, %TRUE, mi)
. . . . . more here but not important . . . . .
End Function
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Dim Pt As PointApi 'Mouse location for tray menu
Dim prevWindow As Dword
Select Case wMsg
Case %WM_TRAYICON
Select Case LoWrd(lParam)
Case %WM_LBUTTONUP
If IsWindowVisible(HWND_FORM1)= 0 Then
ShowWindow HWND_FORM1, %SW_SHOW
End If
SetForegroundWindow(HWND_FORM1)
Case %WM_RBUTTONUP
GetCursorPos Pt
prevWindow= GetNextWindow(HWND_FORM1, %GW_HWNDNEXT)
SetForegroundWindow(HWND_FORM1)
SetWindowPos(HWND_FORM1, prevWindow, 0, 0, 0, 0, %SWP_NOSIZE Or %SWP_NOMOVE Or %SWP_NOACTIVATE)
SetFocus(0) 'Block Keystrokes to Window
TrackPopupMenu(trayMenu, %TPM_RIGHTALIGN Or %TPM_LEFTBUTTON Or %TPM_RIGHTBUTTON, Pt.x, Pt.y, 0, HWND_FORM1, ByVal 0)
'POSTMESSAGE(HWND_FORM1, %WM_NULL, 0, 0)
End Select
Function= %TRUE
Case %WM_SYSCOMMAND
If (wParam And &HFFF0)= %WM_SYSHIDE Then
ShowWindow HWND_FORM1, %SW_HIDE 'hide app so it doesn't appear in the task bar.
Function= %FALSE
End If
Case %WM_NCRBUTTONUP ' Right Click Close Button
If wParam= %HTCLOSE Then
ShowWindow HWND_FORM1, %SW_HIDE 'hide app so it doesn't appear in the task bar.
Function = %TRUE
End If
End Select
End Function
The problem machine is XP Pro SP3. It works on at least 6 other machines that are XP, Vista, and XP running in VMWare.
Any thoughts why this does not work?
Any thoughts on how to debug this problem?
Quote
It works on at least 6 other machines that are XP
But also SP3 or SP2? I ask this because many SP3 users have had problems not experienced by SP2 or Vista users.
Jose'
I have been working with Mark testing and one of the machines I have tested on is an XP-Home SP3. It works fine on that one.
The computer in question (actually two computers) were custom build more or less identical computers. And, the program behaves the same way on both.
We are going to run a debug version of the program that will display mouse clicks windows return codes mostly 512,513,514,515,516,517 We'll see if the codes are getting reported differently than expected.