Results 1 to 3 of 3

Thread: Whats wrong with this code?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Whats wrong with this code?

    This is the code in my form to make the form visible again once the system tray icon is double clicked... but it doesn't even fire when I put the mouse over the systray icon.. When I added the systray icon. i set NOTIFYICONDATA valiable .hWnd property = frmMain.hWnd which I assume is how it binds the icon in the tray to the form.

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'Event occurs when the mouse pointer is within the rectangular
        'boundaries of the icon in the taskbar status area.
        Dim Msg As Long
        Dim sFilter As String
        Msg = X / Screen.TwipsPerPixelX
        Select Case Msg
            Case WM_RBUTTONDOWN
            Case WM_RBUTTONUP
            Case WM_LBUTTONDBLCLK
                Me.Visible = True
                Me.WindowState = vbNormal
            Case Else
                'DO NOTHING
        End Select
    End Sub

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    I don't know if any of this might help, but you could look it over:


    ' System Tray code:
    Private OldWindowProc As Long
    Private frmMain As Form
    Private TheMenu As Menu

    Private Declare Function CallWindowProc 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
    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 Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

    Private Const WM_USER = &H400
    Private Const WM_LBUTTONUP = &H202
    Private Const WM_MBUTTONUP = &H208
    Private Const WM_RBUTTONUP = &H205
    Private Const TRAY_CALLBACK = (WM_USER + 1001&)
    Private Const GWL_WNDPROC = (-4)
    Private Const GWL_USERDATA = (-21)
    Private Const NIF_ICON = &H2
    Private Const NIF_TIP = &H4
    Private Const NIM_ADD = &H0
    Private Const NIF_MESSAGE = &H1
    Private Const NIM_MODIFY = &H1
    Private Const NIM_DELETE = &H2

    Private 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

    Private TheData As NOTIFYICONDATA

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const WM_SYSCOMMAND = &H112
    Public Const SC_RESTORE = &HF120&
    Public Const SC_MINIMIZE = &HF020&
    Public Const SC_MAXIMIZE = &HF030&


    ' Look for system tray messages.
    Public Function TrayWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Const WM_SYSCOMMAND = &H112

    If Msg = TRAY_CALLBACK Then
    ' The user clicked on the tray icon.
    ' Look for click events.
    If lParam = WM_LBUTTONUP Then
    ' On left click, show the form.
    frmMain.Show
    SendMessage hwnd, WM_SYSCOMMAND, _
    SC_RESTORE, 0&
    frmMain.SetFocus
    Exit Function
    End If

    If lParam = WM_RBUTTONUP Then
    ' On right click, show the popup menu.
    frmMain.PopupMenu TheMenu
    Exit Function
    End If
    End If

    ' Handle the minimize and restore commands.
    If Msg = WM_SYSCOMMAND Then
    If wParam = SC_MINIMIZE Then
    frmMain.Hide
    frmMain.SetTrayMenuItems vbMinimized
    Exit Function
    ElseIf wParam = SC_RESTORE Then
    If Not frmMain.Visible Then
    frmMain.Show
    frmMain.SetTrayMenuItems vbNormal
    End If
    End If
    End If

    ' Send other messages to the original
    ' window proc.
    TrayWindowProc = CallWindowProc( _
    OldWindowProc, hwnd, Msg, _
    wParam, lParam)

    End Function


    ' Add the form's icon to the system tray.
    Public Sub AddToTray(frm As Form, mnu As Menu)

    ' Save references to the form and menu for later.
    Set frmMain = frm
    Set TheMenu = mnu

    ' Install the new WindowProc.
    OldWindowProc = SetWindowLong(frm.hwnd, _
    GWL_WNDPROC, AddressOf TrayWindowProc)

    ' Install the form's icon in the tray.
    With TheData
    .uID = 0
    .hwnd = frm.hwnd
    .cbSize = Len(TheData)
    .hIcon = frm.Icon.Handle
    .uFlags = NIF_ICON
    .uCallbackMessage = TRAY_CALLBACK
    .uFlags = .uFlags Or NIF_MESSAGE
    .cbSize = Len(TheData)
    End With
    Shell_NotifyIcon NIM_ADD, TheData

    End Sub


    ' Remove the icon from the system tray.
    Public Sub RemoveFromTray()

    ' Remove the icon from the tray.
    With TheData
    .uFlags = 0
    End With
    Shell_NotifyIcon NIM_DELETE, TheData

    ' Restore the original window proc.
    ' SetWindowLong frmMain.hwnd, GWL_WNDPROC, _
    OldWindowProc

    End Sub

  3. #3
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    http://www.piqsoftware.com/downloads...der/remind.zip


    Fully functional code (free as well).

    HTH?
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

Posting Permissions

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



Click Here to Expand Forum to Full Width