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