|
-
Jan 8th, 2006, 02:20 AM
#1
Thread Starter
Frenzied Member
Can't Show Non-Modal Form...........!
In a WebBrowser project, I have given users the option to set their default browser to my browser i.e. whenever any HTML file is opened in Windows Explorer, the HTML file should open with my browser. The project also houses a CheckBox for the browser to check whether it is the default browser or not. If not, then when the browser is run on the first time, a MsgBox should come up asking the user if he would like to set my browser as the default browser in his machine. If Yes, then my browser will be set as the default browser in that machine else the existing default browser will remain the default browser. This is how I am checking whether my browser is the default browser or not (NOTE: This is not my code):
VB Code:
Private Sub Form_Load()
If (frmBrowserOptions.chkDefault.Value = vbChecked) Then
Call CheckDefault
End If
End Sub
Private Sub CheckDefault()
Dim success As Long
Dim sBrowser As String
'success is passed and filled in the routine
sBrowser = GetBrowserName(success)
'possible return values from the call returned in success
Select Case success
'the call succeeded
Case Is >= ERROR_FILE_SUCCESS
If (InStr(sBrowser, "MyBrowser.exe") = 0) Then
If (vbYes = MsgBox("MyBrowser not default browser! Set it as default?", vbYesNo + vbQuestion)) Then
Call frmBrowserOptions.cmdDefault_Click
End If
End If
Exit Sub
'other possible return values
Case ERROR_FILE_NO_ASSOCIATION
Case ERROR_FILE_NOT_FOUND
Case ERROR_PATH_NOT_FOUND
Case ERROR_BAD_FORMAT
Case Else
End Select
End Sub
Private Function GetBrowserName(dwFlagReturned As Long) As String
Dim hFile As Long
Dim sResult As String
Dim sTempFolder As String
'get the user's temp folder
sTempFolder = GetTempDir()
'create a dummy html file in the temp dir
hFile = FreeFile
Open sTempFolder & "dummy.html" For Output As #hFile
Close #hFile
'get the file path & name associated with the file
sResult = Space$(MAX_PATH)
dwFlagReturned = FindExecutable("dummy.html", sTempFolder, sResult)
'clean up
Kill sTempFolder & "dummy.html"
'return result
GetBrowserName = TrimNull(sResult)
End Function
Private Function TrimNull(Item As String)
Dim pos As Integer
pos = InStr(Item, Chr$(0))
If pos Then
TrimNull = Left$(Item, pos - 1)
Else
TrimNull = Item
End If
End Function
Public Function GetTempDir() As String
Dim nSize As Long
Dim tmp As String
tmp = Space$(MAX_PATH)
nSize = Len(tmp)
Call GetTempPath(nSize, tmp)
GetTempDir = TrimNull(tmp)
End Function
'this is the [i]cmdDefault_Click[/i] event function in another Form named [i]frmBrowserOptions[/i]
Sub cmdDefault_Click()
......................
......................
......................
End Sub
Assume that my browser is not the default browser. Now when I run the browser from the IDE, the MsgBox asking the user whether he would like to set my browser as the default browser or not comes up as expected but when I compile the project into an EXE & then open my browser (again assuming that my browser isn't the default browser), though the MsgBox comes up but immediately after that, VB generates the Can't show non-modal form when modal form is displayed.
Next irrespective of whether I click Yes or No in the MsgBox, the following error gets generated:
An exception 'Unhandled Win32 Exception' has occured in MyBrowser.exe.
However, no debuggers are registered that can debug this exception. Unable to JIT debug.
After this, the browser closes. Now how do I avoid these 2 errors when I run the EXE? Please note that these 2 errors don't get generated when I run the project from the VB IDE.
Last edited by arpan_de; Jan 8th, 2006 at 12:56 PM.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|