troubleshooting Question

msword application.ontime runs immediately

Avatar of talonsblade
talonsblade asked on
ProgrammingVisual Basic ClassicMicrosoft Word
2 Comments1 Solution354 ViewsLast Modified:
i have a launcher program in word i am working on for my company.  they log into the launcher program, it tells them what programs they have access to, when they click on one it automatically logs them into it.  i have made it so that it minimizes down into the task pane and has a popup menu that activates on rightclick of the icon.

on the pupup menu i have "exit" however this locks up the program i believe because it tries to close the program while it is still in the trackpopupmenu hook.  

the way i am trying to get around this is by closing the program 30 seconds after i finish the hood by setting the application.ontime event in the trackpopupmenu hook.  it doesnt work though because even if i add like 3 minutes the function specified in the ontime event triggers immediately.

here is my code, i have deleted some comments so i hope i didnt mess up the syntax
Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim ctl As clsImageControl
    Dim menuSelection As Integer
    Dim curLoc As POINTAPI
    'Dim appopen As Boolean
    If Msg = TRAY_CALLBACK Then
        GetCursorPos curLoc
        
        If lParam = WM_LBUTTONDBLCLK Then
            ShowWindow hwnd, SW_SHOWNORMAL
            Application.Activate
            SetWindowPos hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
            Exit Function
        End If
        If lParam = WM_RBUTTONUP Then
            SetForegroundWindow hwnd
            menuSelection = TrackPopupMenu(hMenu, TPM_LEFTALIGN Or TPM_RETURNCMD,  _ curLoc.x, curLoc.Y, 0, hwnd, ByVal 0&)
            Select Case menuSelection
 
                Case 1:
 
                    ShowWindow hwnd, SW_SHOWNORMAL
                    Application.Activate
                    SetWindowPos hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE 
               Case 2:
                    Application.OnTime Date + TimeValue(DateAdd("n", 3, Now)), runExit
               Case Is >= 5
                    For Each ctl In myApps
                        If ctl.menuVal = menuSelection Then
                                If showTasks(ctl.AppPName) = False Then
                                ctl.RunApp
                                End If
                            Exit Function
                       End If
                  Next
            End Select
           Exit Function
        End If
      
    End If
Finished:
    NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros