News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Video as a screensaver

Started by Guenther78, October 31, 2013, 06:16:17 AM

Previous topic - Next topic

Guenther78

Hello,

@vogelsang:
Thanks for this interesting link.

@dedndave:
I was not able to make the screensaver run with your solution.

The best way is to play the video in fullscreen. The video is big and there is now task bar. The only problem is, that it does not react on messages like WM_KEYDOWN and WM_MOUSEMOUVE.
I found another solution!!!!
I use the timer, on every WM_TIMER message the program gets the position of the cursor and compare it with its position it had during WM_CREATE!
The only problem is, that it does not stop at keyboard pressing or mouse clicks...
But it stops if the user moves the mouse!

Best Regards, Guenther

jj2007

Quote from: Guenther78 on December 22, 2013, 01:18:06 AM
I found another solution!!!!
I use the timer, on every WM_TIMER message the program gets the position of the cursor and compare it with its position it had during WM_CREATE!

Günther,

That will work in most cases but notebooks in particular may show slowly "creeping" mouse cursors. Perhaps you could compare the distance between two WM_TIMER messages, and ignore those with a one pixel value.

Cheers,
Jochen

Farabi

Hi Guenter,
Im sorry I havent had any advice yet about playing a movie on windows, I only know how to use camera using capCreateWindows. Maybe capCreateWindows can open a movie file too but I havent tried it yet.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Guenther78

Hello!

@ jj2007
Good idea, I will implement it.

@ Farabi
playing a movie on windows works with mci, in my first example the program plays the movie in a picture box:

.data
Order0                  db "open C:\\windows\\temp\\video.wmv Type mpegvideo alias MyVideo1",0
Order1                  db "window MyVideo1 handle ",0
Order2                  db "seek MyVideo1 to 0",0
Order3                  db "play MyVideo1 repeat",0
...
.code
...
             invoke mciSendString,ADDR Order0,0,0,0
             invoke ltoa,hwndPictureBox,ADDR buffer                             
             invoke szCatStr,ADDR Order1,ADDR buffer
             invoke mciSendString,ADDR Order1,0,0,0
             invoke mciSendString,ADDR Order2,0,0,0
             invoke mciSendString,ADDR Order3,0,0,0
...


And in my second example the program plays the movie in fullscreen:

.data
Order4                  db "play C:\\windows\\temp\\video.wmv fullscreen repeat",0
...
.code
...
            invoke mciSendString, ADDR Order4,0,0,0
...


But the function capCreateCaptureWindow may help me in my next projects.

Best regards,

Günther

Guenther78

Hello!

Now I am trying to ignore differences of cursor positions with one pixel difference. Here is the code:


            ; Get current position
           invoke GetCursorPos, ADDR pt

            ; Has the cursor moved more than one pixel?
            mov eax,pt.x
            sub eax,x_cursor
            .IF eax > 1
                .IF eax < -1
                    invoke PostQuitMessage,NULL
                .ENDIF
            .ENDIF
            mov eax,pt.y
            sub eax,y_cursor
            .IF eax > 1
                .IF eax < -1
                    invoke PostQuitMessage,NULL
                .ENDIF
            .ENDIF

            ; Save current cusor position
            mov eax,pt.x
            mov x_cursor,eax
            mov eax,pt.y
            mov y_cursor,eax


Is this all right? Do you have better ideas?

I chose 500ms for the timer. Is that to long?

Best regards,

Günther

jj2007

            .IF eax > 1
                .IF eax < -1


See Tips, Tricks and_Traps, "The .if eax<0 trap"

Otherwise it looks convincing ;-)

Guenther78

Thanks, I will replace ".if eax<0" by ".if sdword ptr eax<0".

Günther

Guenther78

Hello,

the screensaver works. But I want that it plays a special Video:

http://www.youtube.com/watch?v=e2nMHAI1dU4


I have this video file with a better quality and a darker ambient.
So I tried to implement it as an embedded resource and created a file rsrc.rc:

#define ID_VIDEO 100
ID_VIDEO RCDATA "FetteKiste.wmv"



How to use embedded binary resources is explained here:

http://blog.kowalczyk.info/article/zy/Embedding-binary-resources-on-Windows.html


If the video can not be played cause it does not exist, I create the file new:


            ; Play the video in fullscreen           
            invoke mciSendString, ADDR Order4,0,0,0

            .IF eax != NULL
                invoke  FindResource,NULL,ID_VIDEO,RT_RCDATA
                mov     hwndVideo,eax

                invoke  LoadResource,NULL,hwndVideo
                mov     hwndVideoData,eax
   
                invoke  LockResource,hwndVideoData
                mov     firstByteVideo,eax

                invoke  SizeofResource,NULL,hwndVideo
                mov     sizeOfVideo,eax

                invoke CreateFile,ADDR videoname,\
                    GENERIC_READ or GENERIC_WRITE ,\
                    FILE_SHARE_READ or FILE_SHARE_WRITE,\
                    NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,\
                    NULL
                mov hFile,eax

                invoke WriteFile,hFile,firstByteVideo,sizeOfVideo,ADDR SizeReadWrite,NULL
                invoke CloseHandle,hFile

                ; Try again to play the video
                invoke mciSendString, ADDR Order4,0,0,0
            .ENDIF


I have the problem that Avira Antivir thinks that my program have the "TR/ATRAPS.Gen" trojan. I think it has to do with the RCDATA value. If I use RT_RCDATA like in the .asm file, then the program runs and Avira is not constraining it.

But if I remove the .wmv file, the file is not created. So I have to use RCDATA in the .rc file.

I think it will be the best, if the screensaver and the video file are in the same dictionary. I mean that other people can download a zip file with the two files in it. The video is not embedded in the screensaver.

I wanted that the video file is an embedded resource that will be saved under Windows/Temp. In this folder I have writing permissions without running a program as admin. If the video file is in the same folder like the screensaver, than it can not be in the Windows/System32 (where the default screensavers are) folder, because videos can not be played from this folder (I use Windows 7).

So, I think the best way is to make a zip file with both files in it, a screensaver and a video that is played. Or do anyone of you have an idea how I can embedded and save a file without being constrained by antivirus programs? I have attached the .rc and the .asm files that works with the video file as an embedded resource.

Best Regards, Guenther

Guenther78

Hello,

I tried to implement another Video:

http://www.youtube.com/watch?v=RQJRfJVHT-I

The solution with the video inside the folder with the screensaver does not run. The .exe and the .scr runs, but if I installed the saver, than a small black box in the upper left of the desktop appears, that means, that the saver does not find the video.

So I got back to implement the video in the program. The program writes it to Windows/Temp.
And that works. Also if Avira is activated (see my post before). Also the problem is not the code, it is the embedded resource!

I added another file in the previous screensaver as a resource. I thought, that Avira sees some bytes in the video, that are similar to this one in a trojan. And after adding another file in the .rc file, Avira makes no trouble.

I hope, that this project is done now. But if You have some ideas, please let me know.

Regards, Guenther

dedndave

you might try this routine
use RT_RCDATA as the resource type (in both the RC file and the function call)

;###################################################################################################

LoadFromRsrc PROTO :HINSTANCE,:LPSTR,:UINT

;###################################################################################################

        .CODE

;***************************************************************************************************

LoadFromRsrc PROC USES EBX ESI EDI hinstLfr:HINSTANCE,lpszLfr:LPSTR,uTypeLfr:UINT

;Load From Resource - DednDave, 9-2012
;
;Call With: hinstLfr:HINSTANCE = handle of module containing the resource (NULL = current process)
;           lpszLfr:LPSTR      = pointer to resource name string or integer resource ordinal
;           uTypeLfr:UINT      = integer type of resource
;
;  Returns: EAX = hgLfrData:HGLOBAL, global allocation handle or 0 if error
;           ECX = uLenLfrData:UINT , size of resource data or 0 if error
;           EDX = lpLfrData:LPVOID , pointer to resource data or 0 if error
;
;     Note: When done using the resource data, use GlobalUnlock and GlobalFree as follows:
;
;           INVOKE  GlobalUnlock,hgLfrData
;           INVOKE  GlobalFree,hgLfrData

;--------------------------------------------

    LOCAL   hrsrcLfr        :HRSRC
    LOCAL   hgLfr           :HGLOBAL
    LOCAL   uLenLfrData     :UINT
    LOCAL   lpLfrData       :LPVOID

;--------------------------------------------

    xor     ebx,ebx
    mov     uLenLfrData,ebx
    mov     lpLfrData,ebx
    INVOKE  FindResource,hinstLfr,lpszLfr,uTypeLfr
    .if eax
        mov     hrsrcLfr,eax
        INVOKE  LoadResource,hinstLfr,eax
        .if eax
            mov     hgLfr,eax
            INVOKE  LockResource,eax
            .if eax
                xchg    eax,esi
                INVOKE  SizeofResource,hinstLfr,hrsrcLfr
                .if eax
                    mov     uLenLfrData,eax
                    add     eax,31
                    and     al,-32
                    INVOKE  GlobalAlloc,GMEM_MOVEABLE,eax
                    .if eax
                        xchg    eax,ebx
                        INVOKE  GlobalLock,ebx
                        .if eax
                            mov     ecx,uLenLfrData
                            xchg    eax,edi
                            mov     edx,ecx
                            mov     lpLfrData,edi
                            shr     ecx,2
                            rep     movsd
                            and     edx,3
                            .if !ZERO?
                                mov     ecx,edx
                                rep     movsb
                            .endif
                        .else
                            xchg    eax,ebx
                            INVOKE  GlobalFree,eax
                            mov     uLenLfrData,ebx
                        .endif
                    .else
                        mov     uLenLfrData,eax
                    .endif
                .endif
            .endif
            INVOKE  FreeResource,hgLfr
        .endif
    .endif
    mov     edx,lpLfrData
    xchg    eax,ebx
    mov     ecx,uLenLfrData
    ret

LoadFromRsrc ENDP

;***************************************************************************************************

Guenther78

Hello,

thank You for this program, dedndave. I tried to implement it. I call the function after receiving WM_CREATE:

invoke LoadFromRsrc, NULL, ID_VIDEO, RT_RCDATA

But the eax register after the call is 0, I think, that is because the allocation failed.
And if I use RCDATA instead of RT_RCDATA in the .rc file, it works. But Avira makes trouble.
I have no idea, the solution with adding a second file in the .rc works, but that is no real solution.

Regards, Guenther

Guenther78

Hello,

I found the error in the rc file: the value of RT_RCDATA is unknown, because the rc compiler does not know it. I had a look to windows.inc and I see that the value is 10.


#define RT_RCDATA 10
#define ID_VIDEO 100
ID_VIDEO RT_RCDATA "FetteKiste.wmv"


But Avira still does not like it.

Rgards, Guenther

Guenther78

Hello,

the error must be in the video file. I converted it from wmv to mpg and it runs now. Avira makes no trouble!

I have attached both .rc and .asm file. Saving an embedded resource is done with the function from dedndave, in my old code I have done it without allocating memory.

Best Regards,

Guenther

Guenther78

Hello,

the screensavers are ready now:

http://klingdesign.de/html/bildsch_schoner.html

You can choose between two videos, please click on the preferred picture. After downloading the zip-folder, extract it, mark the .scr-file, press the right mouse button and choose "install". We have tested it on a Windows XP, a Windows 7 and a Windows 8 Computer. If there are any problems, please tell me.
Thanks for the help in writing this application!

Best Regards,

Guenther