?
Solved

How to Close Running all Crystal Reports.

Posted on 2005-03-09
16
Medium Priority
?
302 Views
Last Modified: 2010-04-17


I will generate some reports, in between i will change the Database. Again if generate the reports i am getting old data itself. Because ODBC will still pointing to Databse only. so only was is to close the old reports and generate again.

Is there any to Close all running Crystal reports.
0
Comment
Question by:hoysala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
16 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13540799
You would have to use the FindWindow API and then close each instance of the report(s) it finds. Something like the example below :

http://www.vb-helper.com/howto_findwindow_min_max_restore.html

but closing each one instead of minimizing it, restoring it or maximizing it ?

Not sure if this helps much but might give you an idea ?

:)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13540812
There site has a couple of examples :

http://www.vb-helper.com/index_api.html

also if you go to :

www.allapi.net

www.codeguru.com

http:\\vbnet.mvps.org

www.pscode.com

I am sure some of them will have an example or two :)
0
 

Author Comment

by:hoysala
ID: 13550125
thanks for suggestions, but for all these exampbles , window name has to be provided. Is there any way so that get list of running Crystal reports and close
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13550140
I am not sure how you would specifically get a list of only crystal reports, but if you know the names to them then you can use that in the coding, not sure how much that helps ? You could just Search for the title of the application which I have never used so I am assuming it would be "Crystal" and any windows the FindWindow API finds with crystal in it , it will close ? or "Crystal Reports"
0
 

Author Comment

by:hoysala
ID: 13558989
ok, i know it is difficult to list only crystal reports. if we know the Titles of running reports is it possible to close them.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13560996
yes, you would need to find out how to send the Alt + F4 command to each window, which I know is possible because that is how it works when you log off. If you go to www.allapi.net and download there API program / database I am sure it will give you examples or you could research the SendKeys command and see if you could do it that way and have a for next loop to determine if the windows title matches the name of the report etc. I will post more info with regards to my findings or any code later on from my computer at home. This should give you something to go on until I get back. :)
0
 

Author Comment

by:hoysala
ID: 13578398
I got the solution. i can list all the reports and close them. Thank for valuable suggestions
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13578408
Just out of curiousty, how did you solve the problem ? If you could please show the solution , if that is ok :)
0
 

Author Comment

by:hoysala
ID: 13578513
ok, this the code to list all tasks and close them.

on click of button all the Running Tasks will be loaded to a Sherida Grid.

all the running reports classes will start with "Afx". on click of button filter Afx's only and close them.


Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = (-16)
Private Const GWL_HWNDPARENT = (-8)
Private Const WS_OVERLAPPED = &H0&
Private Const WS_BORDER = &H800000
Private Const WS_DLGFRAME = &H400000
Private Const WS_CAPTION = WS_BORDER Or WS_DLGFRAME
Private Const WS_SYSMENU = &H80000
Private Const WS_THICKFRAME = &H40000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)

Const WM_CLOSE = &H10
Const INFINITE = &HFFFFFFFF

Private Sub GetWindowInfo(ByVal app_hwnd As Long, ByRef app_parent As Long, ByRef app_owner As Long, ByRef app_visible As Boolean, ByRef app_style As Long, ByRef app_text As String, ByRef app_class As String)
Const MAX_LENGTH = 1024

Dim buf As String * MAX_LENGTH
Dim length As Long

    app_parent = GetParent(app_hwnd)
    app_owner = GetWindowLong(app_hwnd, GWL_HWNDPARENT)
    app_visible = IsWindowVisible(app_hwnd)
    app_style = GetWindowLong(app_hwnd, GWL_STYLE)

    length = GetWindowText(app_hwnd, buf, MAX_LENGTH)
    app_text = Left$(buf, length)

    length = GetClassName(app_hwnd, buf, MAX_LENGTH)
    app_class = Left$(buf, length)
End Sub

Private Sub Command1_Click()
Dim app_hwnd As Long
Dim app_parent As Long
Dim app_owner As Long
Dim app_visible As Boolean
Dim app_style As Long
Dim app_text As String
Dim app_class As String
Dim wid As Single
Dim c As Integer
'Dim Clases(10) As String
GetWindowInfo app_hwnd, app_parent, app_owner, app_visible, app_style, app_text, app_class
    app_hwnd = GetTopWindow(0)
    r = 1
    Do While app_hwnd <> 0
        ' Get information about this window.
    GetWindowInfo app_hwnd, app_parent, app_owner, app_visible, app_style, app_text, app_class
        ' See if this window is interesting.
        If app_visible And _
            app_parent = 0 And _
            app_owner = 0 And _
            Len(app_text) > 0 And _
            Left$(app_text, 8) <> "VBBubble" And _
            (Left$(app_class, 7) <> "Progman" Or _
                (app_style And WS_OVERLAPPEDWINDOW) <> 0) _
        Then
            ssgrdTaskList.AddItem app_hwnd & vbTab & app_text & vbTab & app_class
'            If Left(Trim(app_class), 3) = "Afx" Then
'                intCount = intCount + 1
'            End If
           
        End If
        app_hwnd = GetNextWindow(app_hwnd, GW_HWNDNEXT)
    Loop

End Sub

Public Sub ClearReports()
Dim hand As Long, lProc As Long
Dim WiName As String
Dim hWindow As Long
Dim lngResult As Long
Dim lngReturnValue As Long
ssgrdTaskList.MoveFirst
For c = 0 To ssgrdTaskList.Rows - 1
    If Left(Trim(ssgrdTaskList.Columns("Category").Value), 3) = "Afx" Then
        lProc = Val(ssgrdTaskList.Columns("Unit#").Value)
        WiName = ssgrdTaskList.Columns("Plan").Value
        hWindow = FindWindow(vbNullString, WiName)
        lngReturnValue = PostMessage(hWindow, WM_CLOSE, vbNull, vbNull)
        lngResult = WaitForSingleObject(hWindow, INFINITE)
        Call Sleep(100)
    End If
    ssgrdTaskList.MoveNext
Next c
End Sub
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13578740
Your welcome for the valuable suggestions , Just glad I could help you out ! :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13578741
btw - what are you going to do with this question, just out of curiousty ? :)
0
 

Author Comment

by:hoysala
ID: 13578825
i would like to close the Question
0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 1000 total points
ID: 13578833
I was just curious since I gave you valuable suggestions on how to achieve this.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13582306
I wasn't expecting points, As you did say you would like to close the question and you did solve it yourself for the most part. However I would really like to say thank you for the points and especially the grade ! I was just curious about it because I had never helped with a question and then had it closed, For the most part I usually just get an assist or the points with a C grade when I only point them in the right direction to a certain extent.
0
 

Author Comment

by:hoysala
ID: 13583417
actually this question is strange , i never expected that some one will help me. even though u coluldn't solve my problem, the links u mentioned helped me. also i was not confidant that i could solve this problem. that's why i gave A grade. anyhow once again thanks for u r suggestion
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13583467
your welcome, Just wish I had done more to help you come up with the solution :) I must admit you did really well figuring this problem out by yourself pretty much !
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question