Newsgroup: it.comp.appl.access
Titolo: Riaprire sa Sysytray

Salve ho scaricato questo codice che posizona il db di access nella systray
************* inizio **********
Option Compare Database
Option Explicit
Public Const WM_GETICON = &H7F
Public Const WM_SETICON = &H80
Public Const IMAGE_BITMAP = 0
Public Const IMAGE_ICON = 1
Public Const IMAGE_CURSOR = 2
Public Const LR_LOADFROMFILE = &H10
Public Const ICON_SMALL = 0&
Public Const ICON_BIG = 1&
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 5
Public Declare Function apiShowWindow Lib "user32" Alias "ShowWindow"
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function apiLoadImage Lib "user32" Alias "LoadImageA"
(ByVal hInst As Long, ByVal lpszName As String, ByVal uType As Long, ByVal
cxDesired As Long, ByVal cyDesired As Long, ByVal fuLoad As Long) As Long
Public Declare Function apiSendMessageLong Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, ByVal lParam As Long) As Long
Public Declare Function apiSHGetFileInfo Lib "shell32.dll" Alias
"SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long,
psfi As SHFILEINFO, ByVal cbSizeFileInfo As Long, ByVal uFlags As Long) As
Long
Public Declare Function apiDestroyIcon Lib "user32" Alias "DestroyIcon"
(ByVal hIcon As Long) As Long
Public Declare Function apiShellNotifyIcon Lib "shell32.dll" Alias
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As
Long
Public Declare Function apiCallWindowProc Lib "user32" Alias
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal
msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function apiSetWindowLong Lib "user32" Alias
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal wNewWord
As Long) As Long
'//SHGetFileInfo flags
Public Const SHGFI_ICON = &H100
Public Const SHGFI_DISPLAYNAME = &H200
Public Const SHGFI_TYPENAME = &H400
Public Const SHGFI_ATTRIBUTES = &H800
Public Const SHGFI_ICONLOCATION = &H1000
Public Const SHGFI_EXETYPE = &H2000
Public Const SHGFI_SYSICONINDEX = &H4000
Public Const SHGFI_LINKOVERLAY = &H8000
Public Const SHGFI_SELECTED = &H10000
Public Const SHGFI_ATTR_SPECIFIED = &H20000
Public Const SHGFI_LARGEICON = &H0
Public Const SHGFI_SMALLICON = &H1
Public Const SHGFI_OPENICON = &H2
Public Const SHGFI_SHELLICONSIZE = &H4
Public Const SHGFI_PIDL = &H8
Public Const SHGFI_USEFILEATTRIBUTES = &H10
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const MAX_PATH = 260
Public Type SHFILEINFO
   hIcon As Long
   iIcon As Long
 
   dwAttributes As Long
 
   szDisplayName As String * MAX_PATH
 
   szTypeName As String * 80
End Type
Public psfi As SHFILEINFO
'//Shell_NotifyIcon Flags
Public Const NIM_ADD As Long = &H0
Public Const NIM_MODIFY As Long = &H1
Public Const NIM_DELETE As Long = &H2
'//NOTIFYICONDATA flags
Public Const NIF_TIP As Long = &H4
Public Const NIF_MESSAGE As Long = &H1
Public Const NIF_ICON As Long = &H2
'//Messages
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
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 nID As NOTIFYICONDATA
Public lpPrevWndProc As Long
Private mblnCustomIcon As Boolean
Public Const GWL_WNDPROC  As Long = (-4)
Public Function ApplicationOff()
  Call sHookTrayIcon("fWndProcTray", "My Systray application")
End Function
Function fWndProcTray(ByVal hwnd As Long, _
                                       ByVal uMessage As Long, _
                                       ByVal wParam As Long, _
                                       ByVal lParam As Long) _
                                       As Long
'receives messages indirectly from the operating system
'but allows us to perform additional functions
'for some of those messages.
'
   On Error Resume Next
 
   Select Case lParam
      Case WM_LBUTTONUP:        'Left Button Up
 
      Case WM_LBUTTONDBLCLK:    'Left Button Double click
 
      Case WM_LBUTTONDOWN:      'Left Button down
         Call sUnhookTrayIcon
         Call apiShowWindow(hwnd, SW_SHOWMAXIMIZED)
 
 
      Case WM_RBUTTONDBLCLK:    'Right Double-click
 
      Case WM_RBUTTONDOWN:      'Right Button down
         Call sUnhookTrayIcon
         Call apiShowWindow(hwnd, SW_SHOWMAXIMIZED)
 
 
      Case WM_RBUTTONUP:        'Right Button Up
 
   End Select
 
   'return the messages back
   fWndProcTray = apiCallWindowProc( _
                                       ByVal lpPrevWndProc, _
                                       ByVal hwnd, _
                                       ByVal uMessage, _
                                       ByVal wParam, _
                                       ByVal lParam)
End Function
Sub sHookTrayIcon(strFunction As String, Optional strTipText As String,
Optional strIconPath As String)
   'Initialize the tray icon first
   If fInitTrayIcon(strTipText, strIconPath) Then
      Call apiShowWindow(Application.hWndAccessApp, SW_HIDE)
 
      'Set new address for window's message handler
      lpPrevWndProc = apiSetWindowLong(Application.hWndAccessApp,
GWL_WNDPROC, AddressOf fWndProcTray)
  End If
 
End Sub
Sub sUnhookTrayIcon()
   'Restore the original message handler
   Call apiSetWindowLong(Application.hWndAccessApp, GWL_WNDPROC,
lpPrevWndProc)
 
   'Remove the icon in the SysTray
   Call apiShellNotifyIcon(NIM_DELETE, nID)
 
   'Destroy the icon
   Call apiDestroyIcon(psfi.hIcon)
 
End Sub
Public Function fExtractIcon() As Long
' Extracts the icon associated with an Access form
'
On Error GoTo ErrHandler
Dim hIcon As Long
   'Don't need the full file name as Access form shortcuts
   'have MAF extension.  The SHGFI_USEFILEATTRIBUTES
   'lets us pass an "invalid" file name to SHGetFileInfo
   hIcon = apiSHGetFileInfo(".MAF", FILE_ATTRIBUTE_NORMAL, _
                              psfi, LenB(psfi), _
                              SHGFI_USEFILEATTRIBUTES Or _
                              SHGFI_SMALLICON Or SHGFI_ICON)
   'Make sure there were no errors
   If Not hIcon = 0 Then fExtractIcon = psfi.hIcon
ExitHere:
   Exit Function
ErrHandler:
   fExtractIcon = False
   Resume ExitHere
End Function
Private Function fSetIcon(strIconPath As String) As Long
Dim hIcon As Long
   'Load the 16x16 icon from file
   hIcon = apiLoadImage(0&, strIconPath, IMAGE_ICON, 16&, 16&,
LR_LOADFROMFILE)
   If hIcon Then
      'First set the form's icon
      'Call apiSendMessageLong(frm.hwnd, WM_SETICON, 0&, hIcon&)
      Call apiSendMessageLong(Application.hWndAccessApp, WM_SETICON, 0&,
hIcon&)
      'This will tell us afterwards if we need to reset the form's icon
      mblnCustomIcon = True
      'Now return the hIcon
      fSetIcon = hIcon
   End If
End Function
Private Function fInitTrayIcon(strTipText As String, strIconPath As
String) As Boolean
Dim hIcon As Long
   'If the user didn't specify the tip text, use a default value
   If strTipText = vbNullString Then strTipText = "MSAccess Form"
   If (strIconPath = vbNullString) Or (Dir(strIconPath) = vbNullString)
Then
      'if there's no icon specified, use the form's default icon
      hIcon = fExtractIcon()
   Else
      'load and set the icon
      hIcon = fSetIcon(strIconPath)
   End If
 
   'If we were successful in previous step, then continue
   'to place the icon in the system tray
   If hIcon Then
      With nID
         .cbSize = LenB(nID)
         .hwnd = Application.hWndAccessApp
         .uID = vbNull
         .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
         .uCallbackMessage = WM_MOUSEMOVE
         .hIcon = hIcon
         .szTip = strTipText & vbNullChar
      End With
      Call apiShellNotifyIcon(NIM_ADD, nID)
      fInitTrayIcon = True
   End If
End Function
********** fine ****
il codice funziona il db vienne messo nella systray e per riaprirlo basta
clickrae sull'icona.
Io ho una maschera con "intervallo timer" impostato a 20 secondi
e' possibile sull'evento timer Riaprire il db (come quando cliccko con il
mouse sull'icona ) ????
Grazie
Ciao
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

[cut]
Il brutto del Copia incolla senza capire quello che si fà....!
Per fare quello che dici serve richiamare questa che è la funzione
richiamata dal Subclassing
su LeftClick:
    Call apiShowWindow(hwnd, SW_SHOWMAXIMIZED)
chiaramente devi anche aver capito quale Handle hai subclassato.... quindi
sarà così:
    Call apiShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
Il problema è che quello che vuoi fare mi sà tanto di voglia di mantenere in
primo piano l'applicativo... visto che
vuoi effettuare il RESTORE ogni 20 secondi.... boh... vedi tu...!
-- 
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.alessandrobaraldi.it
---------------------------------------------------------------------------

 Il brutto del Copia incolla senza capire quello che si fą....!
E io che pensavo di essere infame a volte! Alessą, questo č un BASTARD-Post 
:-D
-- 
---
Ciao
Pablitomf (Maurizio Facciuti)
Web Master 
www.accessgroup.it
 

 Pablitomf (Maurizio Facciuti)
Ma no... è la verità...
In ogni caso è Natale siccome siete tutti più buoni io sembro più
cattivo...!
;-)


 ;-)
Grande! Questa è bellissima!
Ciao, Carlo 

 Ciao, Carlo
;-)
