MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

Obrigado

Administração do MaximoAccess

Dicas Ms Access, Exemplos Ms Access, Codigos VBA Ms Access, SQL Ms Access


    [Resolvido]Reativar Acces no tray do sistema

    avatar
    silvasantos
    Intermediário
    Intermediário

    Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 51
    Registrado : 29/01/2012

    [Resolvido]Reativar Acces no tray do sistema Empty Reativar Acces no tray do sistema

    Mensagem  silvasantos em 31/1/2012, 02:08


    Olá novamente á todos do Fórum, estou aqui com mais uma dúvida...
    Alguém saberia como retomar o access do tray do sistema depois de algum tempo, ex.:
    Uso o seguinte módulo:

    *********************************
    Option Compare Database
    Option Explicit


    ' API: Subclassing form for SysTray functionality

    Private Const conDefaultIconPath = "C:\ico.ico"

    'Window style flags
    Private Const GWL_STYLE = (-16)
    Private Const WS_MAXIMIZE = &H1000000
    Private Const WS_MINIMIZE = &H20000000

    'LoadImage flags
    Private Const WM_GETICON = &H7F 'message is sent to a window to retrieve a handle
    ' to the large or small icon associated with a window
    Private Const WM_SETICON = &H80 'message to associate a new large or small icon with a window
    Private Const IMAGE_BITMAP = 0 'Loads a bitmap.
    Private Const IMAGE_ICON = 1 'Loads an icon.
    Private Const IMAGE_CURSOR = 2 'Loads a cursor.
    Private Const LR_LOADFROMFILE = &H10 'Loads the image from the file specified by
    ' the lpszName parameter. If this flag is not
    ' specified, lpszName is the name of the resource.
    Private Const ICON_SMALL = 0& 'Retrieve the small icon for the window.
    Private Const ICON_BIG = 1& 'Retrieve the large icon for the window.


    'loads an icon, cursor, or bitmap.
    Private 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

    'Send a message to a window via its handle
    Private 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

    'SHGetFileInfo flags
    Private Const SHGFI_ICON = &H100 'get icon
    Private Const SHGFI_DISPLAYNAME = &H200 'get display name
    Private Const SHGFI_TYPENAME = &H400 'get type name
    Private Const SHGFI_ATTRIBUTES = &H800 'get attributes
    Private Const SHGFI_ICONLOCATION = &H1000 'get icon location
    Private Const SHGFI_EXETYPE = &H2000 'return exe type
    Private Const SHGFI_SYSICONINDEX = &H4000 'get system icon index
    Private Const SHGFI_LINKOVERLAY = &H8000 'put a link overlay on icon
    Private Const SHGFI_SELECTED = &H10000 'show icon in selected state
    Private Const SHGFI_ATTR_SPECIFIED = &H20000 'get only specified attributes
    Private Const SHGFI_LARGEICON = &H0 'get large icon
    Private Const SHGFI_SMALLICON = &H1 'get small icon
    Private Const SHGFI_OPENICON = &H2 'get open icon
    Private Const SHGFI_SHELLICONSIZE = &H4 'get shell size icon
    Private Const SHGFI_PIDL = &H8 'pszPath is a pidl
    Private Const SHGFI_USEFILEATTRIBUTES = &H10 'use passed dwFileAttribute

    Private Const FILE_ATTRIBUTE_NORMAL = &H80
    Private Const MAX_PATH = 260

    Private Type SHFILEINFO
    hIcon As Long 'Handle to the icon that represents the file.
    iIcon As Long 'Index of the icon image within the system image list.
    dwAttributes As Long 'Array of values that indicates the attributes of the file object.
    szDisplayName As String * MAX_PATH 'String that contains the name of the file as it appears in the Windows shell
    szTypeName As String * 80 'String that describes the type of file.
    End Type

    'Retrieves information about an object in the file system,
    'such as a file, a folder, a directory, or a drive root.
    Private 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

    Private Declare Function apiDestroyIcon Lib "user32" _
    Alias "DestroyIcon" _
    (ByVal hIcon As Long) _
    As Long

    'Declared here so we can use DestroyIcon afterwards
    Private psfi As SHFILEINFO

    'ShowWindow flags
    Private Const SW_HIDE = 0
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMINIMIZED = 2
    Private Const SW_SHOWMAXIMIZED = 3
    Private Const SW_MINIMIZE = 6
    Private Const SW_RESTORE = 9

    'sets the specified window's show state.
    Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" _
    (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) _
    As Long

    'Shell_NotifyIcon Flags
    Private Const NIM_ADD As Long = &H0 'Add an icon to the status area.
    Private Const NIM_MODIFY As Long = &H1 'Modify an icon in the status area.
    Private Const NIM_DELETE As Long = &H2 'Delete an icon from the status area.

    'NOTIFYICONDATA flags
    Private Const NIF_TIP As Long = &H4 'The szTip member is valid.
    Private Const NIF_MESSAGE As Long = &H1 'The uCallbackMessage member is valid.
    Private Const NIF_ICON As Long = &H2 'The hIcon member is valid.

    'Messages
    Private Const WM_MOUSEMOVE = &H200 'posted to a window when the cursor moves.
    Private Const WM_LBUTTONDBLCLK = &H203 'Left Double-click
    Private Const WM_LBUTTONDOWN = &H201 'Left Button down
    Private Const WM_LBUTTONUP = &H202 'Left Button up
    Private Const WM_RBUTTONDBLCLK = &H206 'Right Double-click
    Private Const WM_RBUTTONDOWN = &H204 'Right Button down
    Private Const WM_RBUTTONUP = &H205 'Right Button up

    Private Type NOTIFYICONDATA
    cbSize As Long 'Size of this structure, in bytes.
    hwnd As Long 'Handle to the window that will receive
    ' notification messages associated with an
    ' icon in the taskbar status area
    uID As Long 'Application-defined identifier of the taskbar icon.
    uFlags As Long 'Array of flags that indicate which of
    ' the other members contain valid data.
    uCallbackMessage As Long 'Application-defined message identifier.
    hIcon As Long 'Handle to the icon to be added, modified, or deleted
    szTip As String * 64 'Pointer to a NULL-terminated string
    ' with the text for a standard tooltip.
    End Type

    'Sends a message to the taskbar's status area.
    Private Declare Function apiShellNotifyIcon Lib "shell32.dll" _
    Alias "Shell_NotifyIconA" _
    (ByVal dwMessage As Long, _
    lpData As NOTIFYICONDATA) _
    As Long

    'passes message information to the specified window procedure.
    Private 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

    'changes an attribute of the specified window.
    Private Declare Function apiSetWindowLong Lib "user32" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal wNewWord As Long) _
    As Long

    'Brings a window to the foreground and sets the focus to it.
    Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

    Private Declare Function GetWindowLong Lib "user32" Alias _
    "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
    As Long

    Private nID As NOTIFYICONDATA
    Private lpPrevWndProc As Long
    Private mblnCustomIcon As Boolean
    Private lngWindowState As Long

    Private Const GWL_WNDPROC As Long = (-4) 'Sets a new address for the window procedure.


    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.

    'Handles events for clicking on the icon in the SysTray - SG

    On Error Resume Next

    Select Case lParam
    Case WM_LBUTTONUP: 'Left Button Up
    'Do something here if you want to recognize this mouse action

    Case WM_LBUTTONDBLCLK: 'Left Button Double click
    ' modified to handle main Access window instead of just form
    ' and do SysTray cleanup at the same time - SG
    sUnhookTrayIcon hwnd 'Remove icon from SysTray
    ToggleTaskbarButton hwnd 'Restore application button on Taskbar
    Call apiShowWindow(hwnd, lngWindowState) 'Restore the window to its previous state
    SetForegroundWindow hwnd 'Bring window to foreground and set focus

    Case WM_LBUTTONDOWN: 'Left Button down
    'Do something here if you want to recognize this mouse action

    Case WM_RBUTTONDBLCLK: 'Right Double-click
    'Do something here if you want to recognize this mouse action

    Case WM_RBUTTONDOWN: 'Right Button down
    'Do something here if you want to recognize this mouse action

    Case WM_RBUTTONUP: 'Right Button Up
    'Do something here if you want to recognize this mouse action
    End Select

    'return the messages back
    fWndProcTray = apiCallWindowProc(ByVal lpPrevWndProc, ByVal hwnd, ByVal uMessage, ByVal wParam, ByVal lParam)
    End Function

    Sub sHookTrayIcon(hwnd As Long, Optional strTipText As String, Optional strIconPath As String)
    'Modified to receive a window handle directly instead of a form. - SG
    Dim lngStyle As Long

    'Initialize the tray icon first
    If fInitTrayIcon(hwnd, strTipText, strIconPath) Then
    lngStyle = GetWindowLong(hwnd, GWL_STYLE) 'Get current window style
    'Remember current window state so we can restore to that state later - SG
    If lngStyle And WS_MAXIMIZE Then
    lngWindowState = SW_SHOWMAXIMIZED
    ElseIf lngStyle And WS_MINIMIZE Then
    lngWindowState = SW_SHOWMINIMIZED
    Else
    lngWindowState = SW_SHOWNORMAL
    End If
    apiShowWindow hwnd, SW_MINIMIZE 'minimize the window - we'll need this elsewhere -SG
    apiShowWindow hwnd, SW_HIDE 'hide the window
    'remove the button from the taskbar for the specified window (main Access window) - SG
    ToggleTaskbarButton hwnd

    'Set new address for window's message handler
    lpPrevWndProc = apiSetWindowLong(hwnd, GWL_WNDPROC, AddressOf fWndProcTray)
    End If
    End Sub

    Sub sUnhookTrayIcon(hwnd As Long)
    'Modified to receive a window handle directly instead of a form. - SG

    'Restore the original message handler
    Call apiSetWindowLong(hwnd, GWL_WNDPROC, lpPrevWndProc)
    'Remove the icon in the SysTray
    Call apiShellNotifyIcon(NIM_DELETE, nID)

    'If a custom icon was used, reset the form's icon
    If mblnCustomIcon Then
    Call fRestoreIcon(hwnd)
    End If
    'Destroy the icon
    Call apiDestroyIcon(psfi.hIcon)




    End Sub

    Private Function fExtractIcon() As Long
    On Error GoTo ErrHandler
    Dim hIcon As Long

    'Modified to extract the application icon from msaccess.exe. The path is
    ' specified above for easier future modification. - SG
    hIcon = apiSHGetFileInfo(conDefaultIconPath, 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 fRestoreIcon(hwnd As Long)
    'Load the default form icon and assign it to the window
    Call apiSendMessageLong(hwnd, WM_SETICON, 0&, fExtractIcon())
    End Function

    Private Function fSetIcon(hwnd As Long, strIconPath As String) As Long
    'Modified to receive a window handle directly instead of a form. - SG
    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(hwnd, 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(hwnd As Long, strTipText As String, strIconPath As String) As Boolean
    'Modified to receive a window handle directly instead of a form. - SG

    Dim hIcon As Long

    'If the user didn't specify the tip text, use a default value
    If strTipText = vbNullString Then strTipText = "Sistema"

    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(hwnd, 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 = hwnd
    .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
    '************** Code End *************

    Num botão eu coloquei via vba No evento ao clicar:

    Call sHookTrayIcon(Application.hWndAccessApp)

    E ao clicar no mesmo o sistema minimiza que é uma beleza,

    Mas gostaria que em determinado tempo o Form voltasse sozinho...Já tentei diversos comandos e nada de funcionar...Se alguém puder ajudar , fico imensamente grato!
    avatar
    Convidad
    Convidado

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  Convidad em 31/1/2012, 11:10

    Não testei aqui,mas..
    Que tal se colocar no evento Timer do formulário essa função?


    'tira o icone do sistray
    Call sUnhookTrayIcon(Application.hWndAccessApp)

    'maximiza a aplicação
    docmd.RunCommand aApplication.hWndAccessApp

    Quanto ao tempo do timer, você decide.

    Abraços
    avatar
    silvasantos
    Intermediário
    Intermediário

    Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 51
    Registrado : 29/01/2012

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  silvasantos em 31/1/2012, 11:41

    Olá, e muito obrigado pela atenção, mas já havia feito assim e não surtiu o efeito desejado, creio que falta algum comando que eu desconheço.
    Quanto a funcionalidade, coloquei no timer do form principal mesmo.
    Caso saiba mais alguma solução eu agradeço.
    avatar
    Convidad
    Convidado

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  Convidad em 31/1/2012, 11:51

    Como não sei detalhes, fica dificil
    O form está escondido(invisível) ?
    Se sim, tente me.visible = True

    Outra tentativa caso não de certo:
    docmd.openform me

    eu tentei rodar teu exemplo,mas dá erro aqui:
    ToggleTaskbarButton hwnd
    porque não tenho esse botão, provavelmente.

    Acredito que esteja usando o access minimizado, aparecendo somente o formulário,
    então use comandos para fazer com que o formulário reapareça.
    Em alguns casos um comando deve vir antes de outro para que a coisa funcione.
    Tente primeiro, recuperar o formulário,para depois tirar o icone da sistray.
    abraços
    avatar
    silvasantos
    Intermediário
    Intermediário

    Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 51
    Registrado : 29/01/2012

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  silvasantos em 31/1/2012, 12:09

    Olá e obrigado novamente, desculpe mas esqueci de colocar esse módulo:

    *****************************

    Option Compare Database
    Option Explicit

    'Code modifed where indicated with comments and my initials.

    Private Const WS_EX_APPWINDOW = &H40000
    Public Const SW_HIDE = 0
    Public Const SW_SHOW = 5
    Private Const GWL_EXSTYLE = (-20)

    Private Declare Function ShowWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

    Private Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" (ByVal hwnd As Long, _
    ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Private Declare Function GetWindowLong Lib "user32" Alias _
    "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
    As Long

    Private Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Long) As Long

    Public Sub ToggleTaskbarButton(hwnd As Long)
    Dim lCurrent As Long
    Dim lAppWin As Long
    Dim lngMin As Long

    lCurrent = GetWindowLong(hwnd, GWL_EXSTYLE) 'Get current style flags
    lngMin = IsIconic(hwnd) 'Get minimized state (true or false)

    If lCurrent And WS_EX_APPWINDOW Then 'If this is an application window
    lAppWin = lCurrent And (Not WS_EX_APPWINDOW) 'Remove the flag
    Else
    lAppWin = lCurrent Or WS_EX_APPWINDOW 'Add the flag
    End If

    'If the application is running, we need to hide it to change its style settings
    ' and then make it visible again. We can't test whether or not a window is
    ' hidden, but we can test if it is minimized. For the purposes of this task,
    ' if the application is minimized, then it will also be already hidden so we
    ' don't need to hide it again, and we certainly don't want it to show again. - SG

    If lngMin = 0 Then ShowWindow hwnd, SW_HIDE 'Hide the window if necessary
    SetWindowLong hwnd, GWL_EXSTYLE, lAppWin 'Set the style flags
    If lngMin = 0 Then ShowWindow hwnd, SW_SHOW 'Show the window again if necessary

    End Sub
    ****************************
    E para facilitar, enviarei o bd para que possa dar uma olhada, obrigado.
    Anexos
    [Resolvido]Reativar Acces no tray do sistema Attachmenttray.zip
    Você não tem permissão para fazer download dos arquivos anexados.
    (351 Kb) Baixado 19 vez(es)
    avatar
    Convidad
    Convidado

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  Convidad em 31/1/2012, 13:28

    Tai
    Talvez tenha que melhorar o código.

    Abraços

    Anexos
    [Resolvido]Reativar Acces no tray do sistema AttachmenttrayEB.zip
    (58 Kb) Baixado 53 vez(es)
    avatar
    silvasantos
    Intermediário
    Intermediário

    Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 51
    Registrado : 29/01/2012

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  silvasantos em 31/1/2012, 13:56

    Muito Obrigado pela ajuda, adaptei ao meu exmplo e deu certo, valeu.

    Conteúdo patrocinado

    [Resolvido]Reativar Acces no tray do sistema Empty Re: [Resolvido]Reativar Acces no tray do sistema

    Mensagem  Conteúdo patrocinado


      Data/hora atual: 16/12/2019, 10:58