How to Close Running all Crystal Reports.



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.
hoysalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shane Russell2nd Line Desktop SupportCommented:
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
Shane Russell2nd Line Desktop SupportCommented:
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
hoysalaAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Shane Russell2nd Line Desktop SupportCommented:
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
hoysalaAuthor Commented:
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
Shane Russell2nd Line Desktop SupportCommented:
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
hoysalaAuthor Commented:
I got the solution. i can list all the reports and close them. Thank for valuable suggestions
0
Shane Russell2nd Line Desktop SupportCommented:
Just out of curiousty, how did you solve the problem ? If you could please show the solution , if that is ok :)
0
hoysalaAuthor Commented:
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
Shane Russell2nd Line Desktop SupportCommented:
Your welcome for the valuable suggestions , Just glad I could help you out ! :)
0
Shane Russell2nd Line Desktop SupportCommented:
btw - what are you going to do with this question, just out of curiousty ? :)
0
hoysalaAuthor Commented:
i would like to close the Question
0
Shane Russell2nd Line Desktop SupportCommented:
I was just curious since I gave you valuable suggestions on how to achieve this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shane Russell2nd Line Desktop SupportCommented:
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
hoysalaAuthor Commented:
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
Shane Russell2nd Line Desktop SupportCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.