Embed animated gif in dialog/window

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Embed animated gif in dialog/window

Post by JRL » Mon Oct 11, 2010 4:51 am

Code: Select all

/*
Back in January of 2009,  Marcus demonstrated on the forum how to use 
Microsoft's SetParent API function. http://www.mjtnet.com/usergroup/viewtopic.php?t=5225

SetParent can make any window the child window of any other window.
This sample script displays an animated GIF in an mshta window.  SetParent is then
used to make the mshta window a child of a Macro Scheduler dialog. This allows
the Macro Scheduler dialog to contain an animated GIF

Remember that this is just one example of using SetParent, there are lots of possibilities.
The script is commented to help explain what is going on.
Any questions or comments welcomed.
*/



/*
This script, as written, requires Macro Scheduler version 12 or greater partially
because of the dialog structure used.  The script also uses the new LabelToVar>
function only available in version 12 or later.

The concept requires version 7.3.10 or greater to be able to use
the LibFunc> function to run Microsoft's SetParent API.
*/

//Set the time out for the image to display
Let>TimeOut=3

/*
Delete these files if they already exist.  The script
writes them each time that it's run.
The first is the animated GIF file.
*/
IfFileExists>%temp_dir%SPINNER3-BLUEY.GIF
  DeleteFile>%temp_dir%SPINNER3-BLUEY.GIF
EndIf

//The second is the HTA file that displays the GIF
IfFileExists>%temp_dir%Animated-GIF.HTA
  DeleteFile>%temp_dir%Animated-GIF.HTA
EndIf

//Use ExportData to write the animated GIF file
ExportData>SPINNER3-BLUEY.GIF_DATA,%temp_dir%SPINNER3-BLUEY.GIF

//Use LabelToVar and WriteLn to create the HTA file
LabelToVar>Animated-GIF.HTA_DATA,HTA_DATA
WriteLn>%temp_dir%Animated-GIF.HTA,wres,HTA_DATA

/*
A dialog that does stuff.

The goal is to display in the dialog, an animated GIF
at a time when the user would normally be waiting and no
other activity is visible on the screen.
The animated GIF is intended to let the user know that
something is happening.  We didn't just go into a
tailspin and crash the computer.
*/
Dialog>Dialog1
object Dialog1: TForm
  Left = 329
  Top = 205
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Waiting...'
  ClientHeight = 140
  ClientWidth = 325
  Color = clWhite
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 10
    Top = 16
    Width = 232
    Height = 24
    Caption = 'Displaying an Animated GIF'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
  end
  object Label2: TLabel
    Left = 40
    Top = 48
    Width = 139
    Height = 24
    Caption = 'Now you see it...'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
  end
  object MSButton1: tMSButton
    Left = 128
    Top = 98
    Width = 75
    Height = 25
    Caption = '&Close'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

/*
Dialog handlers to close the dialog.
Notice that even though the dialog closes
the script continues to run
until the wait> has finished.
*/
AddDialogHandler>Dialog1,,OnClose,Quit
AddDialogHandler>Dialog1,msButton1,OnClick,Quit

//Run the subroutine that displays the animated GIF
GoSub>ShowSpinner

//Show the dialog
Show>dialog1

//This script doesn't actually do anything.  It just loops through
//opening and closing the animated GIF as a demonstration.
Label>Loop

  //Wait %timeout% seconds then close the animated GIF window
  Wait>%timeout%
  //Closing the window also kills the parent mshta.exe process.
  CloseWindow>AniGif
  
  //Change dialog text to tell the user what is going on.
  SetDialogProperty>Dialog1,label2,Caption,Now you don't
  SetDialogProperty>Dialog1,,Caption,Off for %timeout% seconds
  
  //Wait %timeout% seconds and restart the animated GIF
  Wait>%timeout%
  GoSub>ShowSpinner

  //Change dialog text to tell the user what is going on.
  SetDialogProperty>Dialog1,label2,Caption,Now you see it...
  SetDialogProperty>Dialog1,,Caption,On for %timeout% seconds
Goto>Loop


//Subroutine to exit from the script when the dialog is closed
SRT>Quit
  Exit>0
END>Quit


//The HTA is contained in a label block
/*
Animated-GIF.HTA_DATA:
<script>window.resizeTo(70, 80);window.moveTo(-32768, -32768);</script>
<title>AniGif</title>
<HTA:application
applicationname="HTA GIF"
border="none"
scroll="no"
innerborder="no"/>
<body border=0>
<div class=Section1>
<span><img src="%temp_dir%SPINNER3-BLUEY.GIF"></span>
</div>
</body>
*/

//The GIF is contained in a label block
/*
SPINNER3-BLUEY.GIF_DATA:
47494638396124002400E64000D2DBEEE0E6F3BFC6E3C7D0E88FA1D1E9EDF6A5B6DDCFD4EAD5DCEEBCC8E5C0CCE87F8CC6EFF2F9E7ECF6F1F3F9DFE2F1E3E7F4F7F9FC9FA9D4ABB8DD5777BFEFF1F8D0D9EE1028954053AAF4F6FB2D4FAA8AA0D4DDE4F27992CCA1B3DDC8D3EB5772BB8F9ACD738AC6D8DFF1B9C4E2B1C0E2B
0BFE120379C3B5BAF6070B99DACD7C7D2EAAFB7DC92A7D78FA5D54966B56280C46E89C89AADDA3045A3849BD05062B1657EC1A9BADFB9C6E5707FC08196CC9BAED9001A8E1F43A44C6EBB829AD1FFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000021FF0B4E45545343415045322E30030100000021F90409000040002C00000000240024000007FF804082838485868788898A8B8C8A1101010C8D9384161B3F3F1B16949311979898929C8B16A0A01FA384073518182C8223A698A84001371E37018D073CBDBDAF0CB23F92B1A6BA8B35BE
BD3382A5A09B401EB2378C18CABD830C1F1FA240C23F8CC9CA278AD2A61E8C02D7AF89C5A0238D2C333C33EC8A23323F32F0A9FD890F12423CF0572081890287245CF0252155021F107D24285461A1B281940A448C887090BA6B21383DDC2891D047650B44922C39A8E2358C933492EC38482143871B271A022890A0890434F
D091D44E2458F172418AD88E123C68A46037A48959A34D10A924F17D9982A158522A61B3B3002C155EA20082A544018B41206A3AD5C47BD0299C07582A00E2469304250362984B23DD65EDD08A011021B204054A55B56852000343AD028EC8F0460C7430B39D050766DE6421338F7D060F7B3210703063830CDBAB5A2400021
F90409000040002C00000000240024000007FF804082838485868788898A8B8C89150202158D938412173C3C170294930F979899929C8B21A0A02C83160A0A0CA384A5A63C1282323FB61B0D8D07339835920FB13C0F401FB6C62D8C9EA61882B098B3401EC6C68CCEA00782070B0BC38225D3B68C0BC19B8801E01E8C12C1A
2880AC61E118DBCA0398C1101B99315211835A89C187CF8D0CA15230BD32C1C7230600004570CC06D90470881861E18278C7A072E40A18B18313EA454AC23A101214312082891A22094297BACE484F09642420E40864400D1C208978426A49C695011041504787202E0A283890C94200C70C028818FAB3E6234720042A5A20C
14B05E4DC048444C12890088BD6A8051CC1E3655061530618083A0026B7DB45DF4168420AB58C902E920964201462862AE2C1056ACDD0C847DC058D1C862C81754D5AEDD6B1002010213A802D12CD644514460D71E3E7D0840630A82591FCA00000054D9B8734F0A040021F90409000040002C00000000240024000007FF804
082838485868788898A8B8C89070F8D918507273C3C18079291151796962793909A85219E9E02822C9D9799A3820BA696A80FB1339208030E8202B13C90B0B1AD8A0E2F3D3D1A138229A639AFBDA88B20C6D30382122929D0402CBD158B08D3D3048ACB9E128C03E1C6E38A120B0BDA8B1AEAC9920D0A1F118913E1369A253F
026E689008020102F5225908C8B085AB45381832246868C00008AE224AFC4171100214D312460AB0D161A162E1AA69D2F863602170EAD86962102080BE97EA7AE878A8086438918C02E0639008C13C6322FE491C51500501129A164ADC1089830103091629D8F82300A3043EC2FA70A168EBC68E883250101B16C02000574DD
D022129510623006CC31A1004562C5920527FB4408B88435E1F7B0B1C964BD36B2418790B00C19B77EF430E907D50C83AF9B0099E8238C81D94392C05C9A00F6136BD22B522D1AE63CB9614080021F90409000040002C00000000240024000007FF804082838485868788898A8B8C8D8E8F10223D28040E8F8E0E283D9B3D20
842118181297852A9C9C0882183CAC3C29A48304A79B03402CADAD07B04013B33D10400BB8AC028E0803B5400E2FA7228212C33CC58C929B2F960E222F2004831527B8278DA6A7368A07AB3C180F8D20BEA4120B121588EEB38F1533AD33F486E49C9E1CA518F6CA90037B9380394AD7EA4222120426587AC49095C35D8984E
12A6888038002BB6AB4C2D08F50860E3E52BAD8754080AE432E52CA348031110599293B900AF0A141229C391F3168F1A36809443480EE78E4A1A8D30F870ADC4C1923C323A74E3D20CA60C24002AB57B1FED0CAA840521F34C0226A8A152AA3183850631052E0C1838208401A1035DA6805501F000495C02A435084110A7C36
32F0976603B13F2CECE2F097039000901560442953675EC892319AE8D0C10421B6455BE0AD7928C2E01F3718B09E4DBBB6ED400021F90409000040002C00000000240024000007FF804082838485868788898A8B8C8D8E8F13363A038603948F87223D9B3D2A8308289B1A089884249C9C10400E1AA81A0EA58204A89B94A7B
413B140B3B49413B43D04BA10AD9C2F8210C0A48D0526061C8224A13D20CBBBA8228E09143EDD2E9FAA85030404970F210B028819DCDDDD008F2C173CF4298700EEEE068F27F4FE1286F0E5F3B1AFD1017FFE161C6AE70E9A4184F4141AE2C03001A61910D51DCA000040815207FAD10BA1AB9100010F1415E85892D10E7731
3E627A7032D18A811D3085F077E1C02117037D3C1200F1C4211A411F2D80C8C367A10403612865AAB110D06E141C9A8478C1A6011332032850D0C01003068352F0ACBAA8C48FB73F502C0C6AE0E16D8BB2400E2C0891B25100B87023086A017883E0580A00BF0D00E4AFE20FBA3E28FEC1D8316005BA1828DE2048B362C6BA2
C6CB08B17080EC0255A0A0A009A50801225E4AA9E4DBB76ED400021F90409000040002C00000000240024000007FF804082838485868788898A8B8C8D8E8E19000086032222138F8709143E3E301C833A3DA33D229984059C9D3E14194010A4A403A78226ABAB9303B1A304B44006B79DB9BB3D2ABE00C13E058228B11A0EBE
402EB70983082FA328088203042A108A2B0626CB40000606A08510E08222A41A24881DAB14EA8D24BB1A87B6B7308F0488CD2A442359394601776D2B342D98AB46BA62A13884EC56874C13E02D34B463558C878F200C18002D510149D1523E1220E081A2080102303875E0048F9B391035D8F0A3A7854C366FDE14708867CF9
E0D1C1D102A7481A100478F2A50CAF4A6D34250A3FE98EA28A850098622183D1A60E505A129108D188B635083998558042C584014C88310741531F8A0202990112D7ACAF00B2404D3B4BE18689521E841551E077C29D0FAA3AC84C7574F4DD65A96C563B0B446509E59E1ACD00B15A29588FA6150CD9B1722A7B4500247D9B8
7555EADECD7B77200021F90409000040002C00000000240024000007FF804082838485868788898A8B8C8D8E8F86192E143E34059086061D1D0684313EA03E3019988334A13E1D8200A8A009A5401CAD3E1C40ACAD9DA526B39DB2ADAFA52BB32B822EA831820E2404088F9FA1C8839A9CA408283DD8228E19A795A48920D8E
22A88111F0A161190E2E220870D1B3FF232EA8EECD8EE8637F2FC258FE1ECC819E2C7CFC32308D7B2218A47D020A4012A9A212A41F08702588A2278E0870316820103143508C0A094031BED1C604C44E09E364423148CA8E708A0380D8734F26B51B2E63D9C863E5474D84884CB431B2B3E72F042DC0B95869212C43481C084
444209DE507400030F1E181E38A2384F5D851418302C1854E1C4D7AF27441E8D0C20A8C28CB73C52086281F7AB005812FAF238006481E0BFA50CF7FD2B4030E15281FB3EF6FA562FACB67831100A9156C24A200F6A5C3891A3C2E7D3A853AB3614080021F90409000040002C00000000240024000007FF80408283848586878
8898A8B8C8D1C008D91851C303E3E142B92880D0185959697059A840D323F3F1B168200A0A026A383A6A7A70C40ACAD3E06B0400DB3B30A4005B83E90C100C58C01BEA7C04009AD2E82CF96301C8C111BCB238300060699B6B8308D16BE258A06C3D68C0D0A0ADBE8C3C8850C1FEF9AD3A0148823D9A7E7925CB40267A8C532
5592BA191075A8D7B266BB0E3158F603A2240803063838246B56274D3A7A88D480C0500383A7104A1A20B2250A440102D41A45A065CB92110FD5B4D903A7A1070B1648D03481E7CB43127828E5914293889624115D58AA74A8240404546C3C2480AAD2058B26E82030A0D103AF3CC0267ADA7242230C5E550508929022058B4
12478F6D8AAA8C20CA517ACA6A09A43D04E9B651B1D105041100BB40F801CBEB96B015AB91078BE8818E2B22012284482F039AAC2D4A5270A21809053D081134A311C68ADE84164DAB873C30A040021F90405000040002C00000000240024000007FF804082838485868788898A8B8C8B1101010C8D93840D1B3F9816949311
979898929B840C0A0A161182019F9F1FA283969F32A8AAAB3F0AAE822DB5B79DB50D40191D3E3E30008DB53F1E8216ABB740C2C33E14058CC837830C1F0ABF4005D1D1068C25B5238900DFC3E18E1E9FCE8914E809930C01A88B09DF318A0F210B07A2005C7430912191041E08792CC0A5A8C2858408FF892A902041C142022
0225CB809DF300AF20865D4C87192B76F142E0E7A08F1C12603E87C18237480250F09A260A29B49A88200012E27A24BC93091C761210F550881A1068B89264C504B3403620E460E0620987450630545047A887DE180D1028D3C04241A20B62D08462156D04A444080C0564122DAB665F4C0260F0C8226E89D2008845EB18D0E
9C4088E12B84C33D200051711805C3B087090379D156C35D5782330F9A50573243081AF46A285BF41089D43D3490689D28EB00D6B473EBA61408003B
*/

SRT>ShowSpinner
  //Execute the HTA file
  Exe>%temp_dir%Animated-GIF.HTA

  //Wait for the HTA window to open
  WaitWindowOpen>AniGif

  //Get the handle of the HTA window
  GetWindowHandle>AniGif,hwnd

  //Use the SetParent API to hijack the HTA
  //and make it a part of the Macro Scheduler dialog
  LibFunc>user32,SetParent,SPres,hwnd,DIALOG1.HANDLE

  //Move the HTA window to the desired position in the dialog
  MoveWindow>AniGif,240,15

  //Set focus to the dialog since the previous
  //MoveWindow line sets focus to the HTA window
  Let>WIN_USEHANDLE=1
  SetFocus>Dialog1.handle
  Let>WIN_USEHANDLE=0
END>ShowSpinner

sarver311
Pro Scripter
Posts: 84
Joined: Tue Jun 17, 2008 6:37 pm

Post by sarver311 » Thu Oct 14, 2010 8:36 pm

Awesome contribution JRL! I always enjoy these cool examples you come up with. Thank you for sharing yet another creative way to spice up our dialogs!

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Re: Embed animated gif in dialog/window

Post by obfusc88 » Wed Mar 17, 2021 10:44 pm

Can't believe I am asking about a forum posting that is 15 years old.

I have been trying to call up an animation to show progress during a long file opening process.
I tried using the Progress Bar in Dialogs, but could not make sense of the parameters, and how to stop the dialog when the file loading was done. I should have asked for help then, but decided there might be an easier way.

Why use Dialog? Why not just open the GIF file? Well, opening the file displays it in the File editor, I just wanted the image, so that was not good.

So, I checked the forum and was sure I found the answer here in this posting. Seemed like it was going to work, but when trying to do my own version, I found I needed the "image data" of the GIF file. Could not find a way to get that, the script did not extract it, it was already imbedded into the script.

Next, I could not find a method to get that data using Google searches, but found a second posting from jpuziano that was a spinoff from this one. Spent some on that, and again found I needed the "image data" from the GIF file.

So, I am still looking for a method to use an animation during a system process. I think I see three or four options,but need help on all of them.
1. Use the Progress Bar in dialog, but I need a real example of the coding to do that during a File Opening.
2. I can use the method here from JRL, but need to know how to get "image data" from an image file.
3. I can use the method from jpuziano, but again, need to know how to get "image data" from an image.
4. In the two posts from JRL and jpuziano, Marcus joined in and it sounded like it might not be a tough thing to make a Clipboard function to extract the data from a screen image. But I checked the current Clipboard functions, and do not see anything that looks like that. Did that ever happen, and am I just no looking hard enough?

So, any answer to the basic problem of displaying an animation would be great.
Second choice would be finding an existing Macro Scheduler function.
Third would be to learn how to grab the "image data". That would probably give me a broader range of tools for future problems.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Re: Embed animated gif in dialog/window

Post by Bob Hansen » Thu Mar 18, 2021 4:37 am

Have you tried using IrfanView?

I just took an animated GIF file and used IrfanView to make a slideshow. Was able to set many parameters, including no advance on time, hide text, position frame, size frame, etc. Only one file in the slideshow. Can be started and stopped with the command line switches.

So, you could start your process, start slideshow, look for flag that process is done, then close slideshow. So this was similar to just opening a GIF file, but had nothing outside the frame, you could not see it inside the IrfanView editor.

I also saved the slideshow as an EXE and as a SCR file. The saves were successful, no errors, but the animation did not carry into those files. So they are just static images. Not a Sensible Solution for you.

Link: https://www.irfanview.com/ Both 32 and 64 bit versions. FREE.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Embed animated gif in dialog/window

Post by JRL » Thu Mar 18, 2021 1:21 pm

obfusc88 wrote: ...need to know how to get "image data" from an image file.
1) Open a bright, shiny, new script in the editor.
2) Select the "Tools" menu item at the top of the script editor.
3) Second item down the list is "Import binary File". Select that.
4) At the bottom right of the file selection window is a file type combobox. Select "All Files (*.*)"
5) Browse to your GIF and import it.
6) The first line of the import is the data label. It ends with a colon (:), The label does not include the colon.
7) At the start of the script add in the ExportData> function. This will export the embedded gif file.

The rest should work like the original example.

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Re: Embed animated gif in dialog/window

Post by obfusc88 » Sun Mar 21, 2021 4:38 pm

I cannot believe that was so simple to make the code! Will have to look deeper in the Help guide to find out how I missed that. Will try this weekend, thank you.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts