Results 1 to 7 of 7

Thread: Crystal Reportviewer in Modal Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    72

    Crystal Reportviewer in Modal Form

    Hello,
    I am trying to have the Crystal Reportviewer as a modal form.

    I have an application that has two forms. The main form that pulls all of the data together for the Crystal Report. This is where I have the crvReport.ShowDialog().

    The crvReport is the 2nd form that had the reportviewer.

    The showdialog() is not working the way that I thought it would. I was thinking that it would not allow you to access any other application on the PC until you closed this form. On the contrary, I am able to move around everything.

    How should I have handled this?

    Thanks for your input in advance!!
    Eddi Rae

  2. #2
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    Re: Crystal Reportviewer in Modal Form

    If I understand correctly, what you are saying is that the "modal" form displays, but you are still able to open/close/use other applications that are installed on your computer.

    If so, this is typical behavior. A modal form only stops you from navigating away from that window to other windows of your own application, but will never stop you from using or navigating to other applications. Even if you open (run) your application twice and the modal form is displayed on both instances, you can still navigate from one instance to the other (using Alt-Tab for example), but not to the main window that called the modal form. Regards, Sgarv
    Last edited by sgarv; Mar 26th, 2013 at 12:18 PM. Reason: add left out text, typo

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    72

    Re: Crystal Reportviewer in Modal Form

    That is okay to navigate from one to another.

    My program is executed from another 3rd party application. If my program was not closed and they ran my program a 2nd time, how could I close the prior instance of my program?

    This would solve my problem and the modal wouldn't matter.

    Thanks!!
    Eddi Rae

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Crystal Reportviewer in Modal Form

    Here's one way, try it:

    1.Create a new Visual Basic project.
    2.Add a Standard Module to the Project.
    3.Paste the following code into the module:
    Code:
          Option Explicit
    
          Public Const GW_HWNDPREV = 3
    
          Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
          Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
            (ByVal lpClassName As String, ByVal lpWindowName As String) _
             As Long
          Declare Function GetWindow Lib "user32" _
            (ByVal hwnd As Long, ByVal wCmd As Long) As Long
          Declare Function SetForegroundWindow Lib "user32" _
            (ByVal hwnd As Long) As Long
    4.Paste the following code into form code module
    Code:
          Private Sub Form_Load()
                If App.PrevInstance Then
                   ActivatePrevInstance
                End If
             End Sub
    
          Sub ActivatePrevInstance()
             Dim OldTitle As String
             Dim PrevHndl As Long
             Dim result As Long
    
             'Save the title of the application.
             OldTitle = App.Title
    
             'Rename the title of this application so FindWindow
             'will not find this application instance.
             App.Title = "unwanted instance"
    
             'Attempt to get window handle using VB4 class name.
             PrevHndl = FindWindow("ThunderRTMain", OldTitle)
    
             'Check for no success.
             If PrevHndl = 0 Then
                'Attempt to get window handle using VB5 class name.
                PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
             End If
    
             'Check if found
             If PrevHndl = 0 Then
             'Attempt to get window handle using VB6 class name
             PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
             End If
    
             'Check if found
             If PrevHndl = 0 Then
                'No previous instance found.
                Exit Sub
             End If
    
             'Get handle to previous window.
             PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
    
             'Restore the program.
             result = OpenIcon(PrevHndl)
    
             'Activate the application.
             result = SetForegroundWindow(PrevHndl)
    
             'End the application.
             Unload Me
          End Sub
    5.Compile the project into an EXE.
    6.Exit Visual Basic.
    7.Run the executable you created.
    8.Repeat step 7.

    RESULT: The first instance of the program is given focus and the second instance is closed. If the first instance of the application was minimized, it will be restored to a normal window automatically.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    72

    Re: Crystal Reportviewer in Modal Form

    Thanks for the input, jggtz.

    I am not able to compile. The Visual Studio 2008 is not showing the "App" as a value. Do I need to import anything to be able to use this?

  6. #6
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    Re: Crystal Reportviewer in Modal Form

    Here is another way:

    http://www.xtremevbtalk.com/archive/.../t-203255.html

    If using VB6 the App object has a PrevInstance property. I seem to recall that this method did not work for specific cases. You can try it. If it doe snot solve your problem then jggtz's method definitely will. Regards.

  7. #7
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Crystal Reportviewer in Modal Form

    Quote Originally Posted by EddiRae View Post
    Thanks for the input, jggtz.

    I am not able to compile. The Visual Studio 2008 is not showing the "App" as a value. Do I need to import anything to be able to use this?
    Sorry, I did think that You were using VB6

    Then you can try:
    Code:
    Public Sub CheckForExistingInstance()
            'Get number of processes of you program
            If Process.GetProcessesByName _
              (Process.GetCurrentProcess.ProcessName).Length > 1 Then
    
           MessageBox.Show _
            ("Another Instance of this process is already running", _
                "Multiple Instances Forbidden", _
                 MessageBoxButtons.OK, _
                MessageBoxIcon.Exclamation)
               Application.Exit()
            End If
        End Sub
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

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