Showing results 1 to 9 of 9

Thread: [Help] AnimateWindow

  1. #1
    Join Date
    03.04.2012
    Location
    Italy
    Posts
    6

    Default [Help] AnimateWindow

    Good morning to all.
    A question for experts...
    Is possible to use the Windows API function type: (AnimateWindow) at the opening or closing of the zenon template (screen's)?
    Thanks in advance.

  2. #2

    Default Re: [Help] AnimateWindow

    Hi Albatrox,

    Welcome to the forum!
    I must say, that I don't know the answer to this.
    Have you tried and it did not work?

    Have you tried with the border type "thin border" and using a title, in the frame settings?
    Or with the option "modal dialog" setting at the screen?

    On the MSDN page for this user32.dll API function I read a comment that this does not work properly on Windows 7 / Vista with the Aero theme.

    Best regards,
    Mark

  3. #3
    Join Date
    03.04.2012
    Location
    Italy
    Posts
    6

    Default Re: [Help] AnimateWindow

    Welcome to the forum!
    I must say, that I don't know the answer to this.
    Have you tried and it did not work?
    I tried but without success.

    Have you tried with the border type "thin border" and using a title, in the frame settings?
    Or with the option "modal dialog" setting at the screen?
    I do not think that these features do animate the window ..
    I was thinking more just to understand something like:
    AnimateWindow (MainScreen.handle , 1000 , Aw_Blend + Aw_Center);
    MainScreen := DoubleBuffered;

    On the MSDN page for this user32.dll API function I read a comment that this does not work properly on Windows 7 / Vista with the Aero theme.
    I have years use it in Delphi, never had problems, perhaps in the basic language microsoft ?
    Thanks for reply.

  4. #4
    martins Gast

    Default Re: [Help] AnimateWindow

    hi,

    can you post the code (or at least some sample code) so we can have a look at this?

    Thanks in advance,
    best regards,
    Martin

  5. #5
    Join Date
    03.04.2012
    Location
    Italy
    Posts
    6

    Default Re: [Help] AnimateWindow

    Quote Originally Posted by martins View Post
    hi,

    can you post the code (or at least some sample code) so we can have a look at this?

    Thanks in advance,
    best regards,
    Martin
    What code are you speaking?
    To my knowledge, zenon is not so advanced that you can use the code in OnCreate event of template,True?
    If you do not know, animation is called in this event if you want to get the desired results.
    Was wondering if you could, but what I have seen the templates are already pre-loaded at the beginning of the runtime.
    My vote from 1 to 10 for this development environment is 2, for nothing intuitive, loss of time.
    I'm sorry.

  6. #6
    martins Gast

    Default Re: [Help] AnimateWindow

    hi,

    I went back to work to try out what you are speaking of - I did not succeed so far, but maybe you can help me out.

    First, I would like to know what you want to achieve with the AnimateWindow call? As far as I found out by reading the MSDN, the AnimateWindow call produces special effects when showing or hiding windows.

    I produced some code so far, but I have one problem with it - I can't get the window handle for the popup. I know it is there because I can find it in Spy++ but with calling FindWindowA, I wasn't able to get it. I simply went through all window handles that I found in Windows and wrote them into a text file, but there it can't be found.

    So here is what I did:

    I created a template in the editor and set it to "bold border" so it really has a title bar and also set it to have Min./Max. buttons. I made a button that opens the screen in this smaller template (I called the screen "Popup") and it opens up similar like a message box.

    For the code:

    For the usage of the WinAPI calls, I had to create a seperate module - here's the code for that:

    Private Declare Function FindWindow Lib "user32" _
      Alias "FindWindowA" ( _
      ByVal lpClassName As String, _
      ByVal lpWindowName As String) As Long
     
    Private Declare Function GetWindowTextLength Lib "user32" _
      Alias "GetWindowTextLengthA" ( _
      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 GetWindow Lib "user32" ( _
      ByVal hwnd As Long, _
      ByVal wCmd As Long) As Long
     
    Private Const GW_HWNDNEXT = 2
    
    Const AW_HOR_POSITIVE = &H1 'Animates the window from left to right. This flag can be used with roll or slide animation.
    Const AW_HOR_NEGATIVE = &H2 'Animates the window from right to left. This flag can be used with roll or slide animation.
    Const AW_VER_POSITIVE = &H4 'Animates the window from top to bottom. This flag can be used with roll or slide animation.
    Const AW_VER_NEGATIVE = &H8 'Animates the window from bottom to top. This flag can be used with roll or slide animation.
    Const AW_CENTER = &H10 'Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
    Const AW_HIDE = &H10000 'Hides the window. By default, the window is shown.
    Const AW_ACTIVATE = &H20000 'Activates the window.
    Const AW_SLIDE = &H40000 'Uses slide animation. By default, roll animation is used.
    Const AW_BLEND = &H80000 'Uses a fade effect. This flag can be used only if hwnd is a top-level window.
    
    Public Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Boolean
    
    Public Function FindWindowHandle(ByVal sTitle As String) As Long
      Dim lngHWnd As Long
      Dim sText As String
      
          
      Dim iFileNo As Integer
      iFileNo = FreeFile
          
      Open "C:\Test.txt" For Output As #iFileNo
     
      ' run through all open windows
      lngHWnd = FindWindow(vbNullString, vbNullString)
      Do While lngHWnd <> 0
     
        ' get window title
        sText = GetWindowTitle(lngHWnd)
        
        Print #iFileNo, sText
        
        If Len(sText) > 0 And LCase$(sText) Like LCase$(sTitle) Then
          FindWindowHandle = lngHWnd: Exit Do
        End If
     
        lngHWnd = GetWindow(lngHWnd, GW_HWNDNEXT)
      Loop
      
      Close #iFileNo
      
    End Function
    
    Public Function GetWindowTitle(ByVal hwnd As Long) As String
      Dim lResult As Long
      Dim sTemp As String
     
      lResult = GetWindowTextLength(hwnd) + 1
      sTemp = Space(lResult)
      lResult = GetWindowText(hwnd, sTemp, lResult)
      GetWindowTitle = Left(sTemp, Len(sTemp) - 1)
    End Function


    The next one is my thisProject module for the runtime itself.

    I am not sure if the DynPicture.Open event is triggered before or after the window handle is created, so I simply took the DynPicture.Timer event for this. As the Timer event is triggered cyclic, I had to create a boolean that I set to True for first call and that I set back to false when closing the screen again. This way my function gets executed only once and not every timer cycle.

    Dim WithEvents zScreen As DynPicture
    Dim bIsOpen As Boolean
    
    Private Sub Project_Active()
    
        Set zScreen = thisProject.DynPictures.Item("Popup")
        bIsOpen = False
    
    End Sub
    
    Private Sub zScreen_Close()
    
        bIsOpen = False
        
    End Sub
    
    Private Sub zScreen_Timer()
        
        Dim hwnd As Long
        
        If bIsOpen = True Then Exit Sub
        
        bIsOpen = True
        
        'this is the window handle I found out via Spy++
        hwnd = 4789068
        'this doesn't work for me, it won't find the window handle this way (FindWindowA)
        'hwnd = FindWindowHandle("Popup")
        
        HelperModule.AnimateWindow hwnd, 200, AW_VER_POSITIVE Or AW_HOR_NEGATIVE Or AW_HIDE
    
    End Sub

    So maybe this can help you anyhow, I will try it myself tomorrow if I can find out what the mistake is - I don't know yet.

    Was wondering if you could, but what I have seen the templates are already pre-loaded at the beginning of the runtime.
    I don't know what you mean with this. Do you mean templates/frames or pictures/screens?

    To clarify this (as there is maybe a misunderstanding there) - our screens were named "pictures" and "frames" were called "templates" in prior versions - in the object model, they still have their old names (DynPictures and Templates) because if we had changed the naming there, a lot of projects that use VBA would be rendered useless by this - we wanted to keep downwards compatibility.

    I suppose you are talking about screens. Can you please explain what you mean with preloaded? At runtime start, the runtime itself only loads the screens it needs for the start screen and/or every screen that is called with a screen switch function - nothing more.

    My vote from 1 to 10 for this development environment is 2, for nothing intuitive, loss of time.
    I'm sorry.
    Well, it is a different approach like WinCC or Intouch - that is definately true. But this is similar to using Linux or MacOS if you are used to Windows. Once you get used to the differences and learn to use the advantages, you won't regret it. I mean, I am a software developer in my heart of hearts that loves to solve things by writing code - but a lot of things that require a lot of coding in other SCADA solutions simply work out of the box in zenon - and this is a lot more convenient than writing a lot of lines of code. Even I have to admit that
    But in the end, it's also a matter of taste and I don't want to start a flamewar here.

    Hope I could help you,
    best regards,
    Martin

  7. #7
    Join Date
    29.07.2007
    Location
    Parma (Italy)
    Posts
    12

    Default Re: [Help] AnimateWindow

    Quote Originally Posted by albatros View Post
    What code are you speaking?
    To my knowledge, zenon is not so advanced that you can use the code in OnCreate event of template,True?
    If you do not know, animation is called in this event if you want to get the desired results.
    Was wondering if you could, but what I have seen the templates are already pre-loaded at the beginning of the runtime.
    My vote from 1 to 10 for this development environment is 2, for nothing intuitive, loss of time.
    I'm sorry.
    Ciao Albatros, ti spiace chiamarmi in ufficio??

    Grazie

    Danilo Montini - SIDEL HMI Coordination

  8. #8
    Join Date
    03.04.2012
    Location
    Italy
    Posts
    6

    Default Re: [Help] AnimateWindow

    Dear martins ,
    first of all thank you for reply.
    The second question is that maybe I have not explained well, so I have attached an executable to see what kind of animations I would incorporate in the zenon project.
    My problem is not the code in vba, but management or integration of the code in zenon!
    One question, the pages are created at the time of the event (for example when you press the button recall page) or at the start of the runtime?
    Thanks for your help!
    Best Regards.
    Blendi.

    P.S:d_Montini,
    I'm out of office for a few days.
    Sono fuori ufficio per qualche giorno.
    Attached Files Attached Files

  9. #9

    Default Re: [Help] AnimateWindow

    Hi to all,

    I want to add the code to retrive the Handle of a zenon Picture.
    Because the window are a Tree structure (See the Spy++ printscreen in attachment) :
    First of all we need to start to find the zenon Runtime Handle
    After that we will search the fixed Key "MDIClient"
    In the "MDIClient" Node are listed all the Picture opened and we need to search our Picture and retrive our Handle using FindWindowEx recursively

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Sub FindMyPictureHandle()
      Dim lHwnd As Long
     'Retrive the Handle of zenon Runtime WIndow
      lHwnd = FindWindowEx(0&, 0&, vbNullString, thisProject.Parent.Parent.Name)
     'Retrive the Handle of the Node "MDIClient"
      lHwnd = FindWindowEx(lHwnd, 0&, "MDIClient", vbNullString)
    'FInally retrive the Handle of the Picture
      lHwnd = FindWindowEx(lHwnd, 0&, vbNullString, "NameOfMyPicture")
    End Sub
    Attached Thumbnails Attached Thumbnails ScreenShot202.jpg  

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •