AutoHotkey Community

It is currently May 27th, 2012, 10:52 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 69 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
PostPosted: October 24th, 2006, 1:01 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
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.

Image

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

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Last edited by daonlyfreez on October 23rd, 2008, 2:05 pm, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:04 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
When I tried it I saw no animation :?
The screenshot looks impressive though.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:05 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Did you doubleclick on a resource in the ListView? :wink:

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:12 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Oh right, the start/stop buttons are actually pause/play then. Great script!

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:13 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Yes, Start/Stop will control the current animation.

Thanks 8)

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:15 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
FYI: I used Resource Hacker to get the resource numbers.

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 1:35 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Fantastic demonstration! :D .. I tried it in Windows 2000 - SP4!
FYI, I get no animation for the last four items 167,168,169,170

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 2:32 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 2:51 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
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 :roll:

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 3:48 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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... :-)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 3:57 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@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 :P )
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/viewtop ... 5809#25809

:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 4:36 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Edited code, see first post. Thanks PhiLho!

@Goyyah: :) I had no idea how to do that then, and not much more now either :P

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 4:41 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
daonlyfreez wrote:
I had no idea how to do that then, and not much more now either :P


I do not believe it.. Please come up with more good stuff like these! :D

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 4:53 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Well, more is on the way :wink: (someday... :roll: )

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 :P

Related: does anybody know how to use resourced bitmaps in an AHK Gui? For example user32.dll has some interesting ones.

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Last edited by daonlyfreez on October 24th, 2006, 5:01 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2006, 5:00 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 69 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 49 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group