View Single Post

  #10 (permalink)  
Old 12-12-2006
Paul Larson Paul Larson is offline
Senior Member
Green Belt
 
Join Date: Sep 2005
Location: Marshall, Michigan
Posts: 122
Re: An API to Control MapPoint 2006 GPS Features - Part I of II

Greetings!

Since I've had numerous requests for the code to automatically dismiss the "Safety Warning" dialog when calling my ToggleGuidance() method, I'm posting the code here for public use.

Simply replace the entire routine for ToggleGuidance() with the entire code below. (In module mpGPS.vb)

Note: By using this code you assume full responsibility and risk, and agree not to hold Paul Larson nor Paul Larson, LLC liable for damages.


'---BEGIN CODE---
Public Sub ToggleGuidance()
If lGPS_UseDrivingGuidance = False Then Dim myDismisser As New DismissSafetyWarning
SendMessage(hwProvideDrivingGuidance, BM_CLICK, 0, 0)
lGPS_UseDrivingGuidance = Not lGPS_UseDrivingGuidance
End Sub

Private Class DismissSafetyWarning
Private IsDismissed As Boolean = False
Public Sub New()
Dim myThread As System.Threading.Thread
myThread = New System.Threading.Thread(AddressOf DismissWarningThread)
myThread.Start()
End Sub
Private Sub DismissWarningThread()
Dim Retries As Integer
Dim hwWarning As Integer
Dim hwAgree As Integer
For Retries = 1 To 10
'wait 1/8 of a second
System.Threading.Thread.Sleep(125)
hwWarning = FindWindowEx(GetDesktopWindow, 0, vbNullString, "Safety Warning")
If hwWarning <> 0 Then
hwAgree = FindWindowEx(hwWarning, 0, "Button", "I &Agree")
If hwAgree <> 0 Then
SendMessage(hwAgree, BM_CLICK, 0, 0)
IsDismissed = True
End If
End If
Next
End Sub
End Class
'---END CODE---


Best Regards,
Paul Larson
Reply With Quote