 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 1:01 pm Post subject: Add an AVI to your AHK Gui - CreateWindow_AVI.ahk [LIB] |
|
|
Edit: In the meantime, PhiLho provided a library: CreateWindow_AVI.ahk for ease of use, check it out.
With this code, you can add an animated AVI to your AHK Gui. It loads the AVI's from resource into a SysAnimate32 control, in this example I used the built-in Shell32.dll.
This script was tested on Windows XP SP2.
| Code: | ; Add an animation control to your AHK Gui
;
; http://windowssdk.msdn.microsoft.com/en-us/library/ms673600.aspx
AniList =
(LTrim Join|
150 - Search flashlight
151 - Search documents
152 - Search computer
160 - Move files
161 - Copy files
162 - Delete files
163 - Empty trash
164 - Empty folder
165 - Check files
166 - Search internet
167 - Move files
168 - Copy files
169 - Empty folder
170 - Download files
)
Gui, 1: Add, GroupBox, x10 y10 w160 h230, Available avi's:
Gui, 1: Add, ListBox, x20 y30 w140 h200 vAniChoiceVar gAniChoice Choose1 AltSubmit, %AniList%
Gui, 1: Add, GroupBox, x180 y10 w410 h230, Preview:
Gui, 1: Add, Button, x190 y210 w120 gStartAni, Start animation
Gui, 1: Add, Button, x340 y210 w120 gStopAni, Stop animation
Gui, 1: Show, w600 h250, Add built-in AVI Animation to AHK GUI - Windows XP - shell32.dll avi's
WinGet, mainGuiHandle, ID, A
; Load shell32.dll
aniInstance := GuiAddResAniInit("Shell32.dll")
autoRun = 1
GoSub, AniChoice
Return
StartAni:
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_play.asp
; wParam: Number of times to replay the AVI clip. A value of -1 means replay the clip indefinitely.
; lParam: MAKELONG(wFrom, wTo)
; wFrom: Zero-based index of the frame where playing begins. The value must be less than 65,536.
; A value of zero means begin with the first frame in the AVI clip.
; wTo: Zero-based index of the frame where playing ends.
; The value must be less than 65,536. A value of -1 means end with the last frame in the AVI clip.
PostMessage, %ACM_PLAY%, -1, -1, , ahk_id %aniCtlHandle%
Return
StopAni:
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_stop.asp
PostMessage, %ACM_STOP%, 0, 0, , ahk_id %aniCtlHandle%
Return
; Animation selected
AniChoice:
If (A_GuiControlEvent = "Normal" or autoRun = 1 )
{
Gui, Submit, NoHide
; Get aniNr - thanks PhiLho
Loop Parse, AniList, |
{
If (A_Index = AniChoiceVar)
StringLeft aniNr, A_LoopField, 3
}
; Autorun
If aniNr =
{
aniNr = 150
autoRun = 0
}
; Remove existing
If aniCtlHandle !=
DLLCall("DestroyWindow", uint, aniCtlHandle)
; Add control
posx = 220
posy = 60
posw = 300
posh = 80
GuiAddResAni(mainGuiHandle, aniInstance, aniNr, posx, posy, posw, posh)
}
Return
GuiAddResAniInit(pathToDLL)
{
Return DLLCall("LoadLibrary", str, pathToDLL)
}
GuiAddResAni(mainGuiHandle, aniInstance, aniNr, posx, posy, posw, posh)
{
global aniCtlHandle, ACM_PLAY, ACM_STOP
NULL =
WS_CHILD = 0x40000000
WS_VISIBLE = 0x10000000
ACS_AUTOPLAY = 0x0004
ACS_TRANSPARENT = 0x0002
ACS_CENTER = 0x0001
ACM_OPEN := 0x400 + 100
ACM_PLAY := 0x400 + 101
ACM_STOP := 0x400 + 102
aniCtlHandle := DLLCall("CreateWindowEx"
, uint, 0 ; Style
, str, "SysAnimate32" ; Class Name
, str, NULL ; Window name
, uint, WS_CHILD|WS_VISIBLE|ACS_TRANSPARENT|ACS_CENTER|ACS_AUTOPLAY ; window style
, int, posx ; Left
, int, posy ; Top
, int, posw ; Right
, int, posh ; Bottom
, uint, mainGuiHandle ; Handle of parent
, int, NULL ; Menu
, uint, aniInstance ; hInstance
, string, NULL) ; User defined style
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_open.asp
; wParam: Instance handle to the module from which the resource should be loaded.
; Note that if the window is created by a DLL, the default value for hinst is the HINSTANCE value of the DLL, not of the application that calls the DLL.
; lParam: Pointer to a buffer that contains the path of the AVI file or the name of an AVI resource.
; Alternatively, this parameter can consist of the AVI resource identifier in the low-order word and zero in the high-order word.
PostMessage, %ACM_OPEN%, %aniInstance%, %aniNr%, , ahk_id %aniCtlHandle%
}
GuiAddResAniRemove()
{
DllCall("FreeLibrary", "uint", aniInstance)
}
GuiClose:
GuiEscape:
GuiAddResAniRemove()
ExitApp
|
Edit: In the meantime, PhiLho provided a library: CreateWindow_AVI.ahk for ease of use, check it out.
Edit: Added link to CreateWindow_AVI.ahk library by PhiLho
Edit: Updated code: Added AutoRun, and single click ListView selection. Replaced if-tree with PhiLho's parsing loop, thanks!
Edit: Updated code with PhiLho's corrected PostMessages _________________ (sorry, homesite offline atm)
Last edited by daonlyfreez on Tue Nov 14, 2006 1:30 pm; edited 6 times in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5009 Location: imaginationland
|
Posted: Tue Oct 24, 2006 1:04 pm Post subject: |
|
|
When I tried it I saw no animation
The screenshot looks impressive though. _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 1:05 pm Post subject: |
|
|
Did you doubleclick on a resource in the ListView?  _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5009 Location: imaginationland
|
Posted: Tue Oct 24, 2006 1:12 pm Post subject: |
|
|
Oh right, the start/stop buttons are actually pause/play then. Great script! _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 1:13 pm Post subject: |
|
|
Yes, Start/Stop will control the current animation.
Thanks  _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 1:15 pm Post subject: |
|
|
FYI: I used Resource Hacker to get the resource numbers. _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5595
|
Posted: Tue Oct 24, 2006 1:35 pm Post subject: |
|
|
Fantastic demonstration! .. I tried it in Windows 2000 - SP4!
FYI, I get no animation for the last four items 167,168,169,170
Regards,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 2:32 pm Post subject: |
|
|
Funny, these days I was pondering if CreateWindow could work on an AutoHotkey GUI, since lot of people are asking for controls not yet implemented.
You demonstrated it wonderfully! Thanks for saving me some time.
I wondered why you did a LoadLibrary, but it is to get an instance, clever!
Interface isn't really intuitive, but well, that's mostly a demo, no problem. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 2:51 pm Post subject: |
|
|
Yes, only to show the principle (maybe I should have done an auto-load on open).
And I didn't add proper error-handling, and neither did I create a full-blown functions library, but I think that would be overkill.
| Quote: | | I wondered why you did a LoadLibrary, but it is to get an instance, clever! |
Thanks, but this was no 'cleverness', I do not know how to get the instance otherwise. Do you know an other way?
| Quote: | | since lot of people are asking for controls not yet implemented. |
There is information on more controls in the Windows SDK documentation
RichEdit would be a nice add-on, I tried adding a RichEdit control with this method, but haven't succeeded yet.
Edit: Err, it needs structures and whatever... Not me  _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 3:48 pm Post subject: |
|
|
| daonlyfreez wrote: | | Thanks, but this was no 'cleverness', I do not know how to get the instance otherwise. Do you know an other way? | Mm, no, perhaps that's because it is provided in WinMain, they didn't found useful to provide an API for that... Or I just can't remember it.
I found a message where Chris wrote he would create a A_hInstance variable if needed, perhaps that's the opportunity...
A little improvement of your double-click handler:
| Code: | AniChoice:
If A_GuiControlEvent = DoubleClick
{
Loop Parse, AniList, |
{
If (A_Index = A_EventInfo)
StringLeft aniNr, A_LoopField, 3
}
| You give the code in the listbox, let's get it back...  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5595
|
Posted: Tue Oct 24, 2006 3:57 pm Post subject: |
|
|
@PhiLho:
| PhiLho wrote: | | Funny, these days I was pondering if CreateWindow could work on an AutoHotkey GUI, since lot of people are asking for controls not yet implemented. |
| Chris wrote: | | daonlyfreez wrote: | (RichEdit and InternetExplorerContainerWindow too please ) | Those would be good additions. In case you want to use them right away, I don't think there's anything that would prevent you from using DllCall("CreateWindow"...) to create any control of your choice inside a parent GUI window. After creation, you could send the control some messages to set it up and get things back out of it. |
Do not ask me how I dug it up : http://www.autohotkey.com/forum/viewtopic.php?p=25809#25809
 _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 4:36 pm Post subject: |
|
|
Edited code, see first post. Thanks PhiLho!
@Goyyah: I had no idea how to do that then, and not much more now either  _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5595
|
Posted: Tue Oct 24, 2006 4:41 pm Post subject: |
|
|
| daonlyfreez wrote: | I had no idea how to do that then, and not much more now either  |
I do not believe it.. Please come up with more good stuff like these!  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 740 Location: Berlin
|
Posted: Tue Oct 24, 2006 4:53 pm Post subject: |
|
|
Well, more is on the way (someday... )
Tip: If you want to play your own AVI in a Gui, you can use this method too, you'll have to pack the AVI into a DLL, use Resource Hacker for that.
Not yet a video player, but close
Related: does anybody know how to use resourced bitmaps in an AHK Gui? For example user32.dll has some interesting ones. _________________ (sorry, homesite offline atm)
Last edited by daonlyfreez on Tue Oct 24, 2006 5:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 5:00 pm Post subject: |
|
|
daonlyfreez, you did a copy/paste of the PostMessages, but they are incorrect for ACM_PLAY and ACM_STOP, no need for aniInstance.
Likewise, the hInstance of CreateWindowEx can be null. At best, it should be the hInstance of the GUI/script, not of the DLL. You need aniInstance only for ACM_OPEN, to extract resources from this DLL.
| Code: | ; Load shell32.dll, resource from where we get the AVI animations.
aniInstance := GuiAddResAniInit("Shell32.dll")
Return
StartAni:
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_play.asp
; wParam: Number of times to replay the AVI clip. A value of -1 means replay the clip indefinitely.
; lParam: MAKELONG(wFrom, wTo)
; wFrom: Zero-based index of the frame where playing begins. The value must be less than 65,536.
; A value of zero means begin with the first frame in the AVI clip.
; wTo: Zero-based index of the frame where playing ends.
; The value must be less than 65,536. A value of -1 means end with the last frame in the AVI clip.
PostMessage, %ACM_PLAY%, -1, -1, , ahk_id %aniCtlHandle%
Return
StopAni:
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_stop.asp
PostMessage, %ACM_STOP%, 0, 0, , ahk_id %aniCtlHandle%
Return
; Animation selected
AniChoice:
If A_GuiControlEvent = DoubleClick
{
Loop Parse, AniList, |
{
If (A_Index = A_EventInfo)
StringLeft aniNr, A_LoopField, 3
}
; Remove existing
GuiAddResRemoveAni()
; Add control
posx = 220
posy = 60
posw = 300
posh = 80
GuiAddResAni(mainGuiHandle, aniInstance, aniNr, posx, posy, posw, posh)
}
Return
GuiAddResAniInit(pathToDLL)
{
Return DLLCall("LoadLibrary", str, pathToDLL)
}
GuiAddResAni(mainGuiHandle, aniInstance, aniNr, posx, posy, posw, posh)
{
global aniCtlHandle, ACM_PLAY, ACM_STOP
NULL =
WS_CHILD = 0x40000000
WS_VISIBLE = 0x10000000
ACS_AUTOPLAY = 0x0004
ACS_TRANSPARENT = 0x0002
ACS_CENTER = 0x0001
ACM_OPEN := 0x400 + 100
ACM_PLAY := 0x400 + 101
ACM_STOP := 0x400 + 102
aniCtlHandle := DLLCall("CreateWindowEx"
, uint, 0 ; Style
, str, "SysAnimate32" ; Class Name
, str, NULL ; Window name
, uint, WS_CHILD|WS_VISIBLE|ACS_TRANSPARENT|ACS_CENTER|ACS_AUTOPLAY ; window style
, int, posx ; Left
, int, posy ; Top
, int, posw ; Right
, int, posh ; Bottom
, uint, mainGuiHandle ; Handle of parent
, int, NULL ; Menu
, uint, 0 ; hInstance
, string, NULL) ; User defined style
; http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/animation/messages/acm_open.asp
; wParam: Instance handle to the module from which the resource should be loaded.
; Note that if the window is created by a DLL, the default value for hinst is the HINSTANCE value of the DLL, not of the application that calls the DLL.
; lParam: Pointer to a buffer that contains the path of the AVI file or the name of an AVI resource.
; Alternatively, this parameter can consist of the AVI resource identifier in the low-order word and zero in the high-order word.
PostMessage, %ACM_OPEN%, %aniInstance%, %aniNr%, , ahk_id %aniCtlHandle%
}
GuiAddResRemoveAni()
{
If aniCtlHandle !=
DLLCall("DestroyWindow", uint, aniCtlHandle)
}
GuiAddResAniRemove()
{
DllCall("FreeLibrary", "uint", aniInstance)
}
GuiClose:
GuiEscape:
GuiAddResRemoveAni()
GuiAddResAniRemove()
ExitApp
|
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|