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 All,

I want to write a screensaver in assembly. A screensaver is like a normal program, the only difference is, that the ending is .scr instead of .exe.
I want to use mci, so that the program can be used by everyone with a windows operating system. The user need not to have directX.

I tried to start a procedure from the main program like in Iczelions Turorial part 14:
http://win32assembly.programminghorizon.com/tut14.html


The called procedure is a short program, that consists in starting the playing of the video.


include     \masm32\include\winmm.inc
includelib  \masm32\lib\Winmm.lib

.data
MsgOrder        db "play video.wmv fullscreen repeat"

.code
start:
      invoke mciSendString, addr MsgOrder,  NULL, 0, 0


But when the video ist playing, how can I stop it? The main program, that contains the message loop is not active.

How can I make it, that the main program can receive messages from windows?

Key is pressed or mouse is moved-> stop the process!

Regards, Guenther

dedndave


Gunther

Good link, Dave. Thank you.  :t

Gunther
You have to know the facts before you can distort them.

dedndave

i seem to recall some examples on the old forum
never wanted to write one, so i don't have one handy

Tedd

There is a little bit more to screensavers than just renaming to .scr -- there are various things you need to respond to, particularly when there was user activity.
More info: http://www.wischik.com/scr/howtoscr.html

As for controlling your video playback, you'll have to create your own MCI window, so you have a handle to direct messages at - then you can tell it when to play and stop, but that's obviously a bit more involved than a one-liner. Start with MCIWndCreate.
Potato2

TWell

Thank's Tedd for that link. :t
BTW: create thread for video and stop it, if user move mouse or hit key.

dedndave

i think you can use mciSendCommand to terminate any video or audio that's playing

jj2007

Quote from: TWell on November 01, 2013, 02:26:02 AM
BTW: create thread for video and stop it, if user move mouse or hit key.

How would you stop it? TerminateThread?

Guenther78

Thanks for the replies and the links!


@ dedndave: You are right, in the old forum are some information:

http://www.masmforum.com/board/index.php?PHPSESSID=143b067e31fa6d7971f9bd4a87780197&action=search2

And I can stop the Video with the following Code:

mciSendString(TEXT("Close"),  NULL, 0, 0);


@ jj2007:

I think I have to terminate the Video. If start a thread, then I have to get the focus back from the called thread to the calling program. Here are some possibilities:

http://www.masmforum.com/board/index.php?topic=2415.0


Now I will have a closer look to the two links. I will post the code when I am ready.

Regards, Guenther

Guenther78

Hello,

I was not able to implement it like in the links from Dedndave and Tedd. The linker can not find "DefScreenSaverProc". I looked in the internet and found the following side:

http://www.asmcommunity.net/forums/topic/?id=21139

Here they build a screensaver with Masm. The also use a definition file (like in the link from Dedndave), but I have no idea, how to work with it.

So, I wrote a screensaver two or three months ago in C#. I was able to play a video file with mci. I played it in a picture box, so that the main window has the input focus. It works sometimes. It had worked on my windows 7. Later I have installed the windows SDK. After that it doesn't work.
And on a windows 8 I got a shame error. Later I changed the framework and it runs after that.

But I want that the screensaver works on every windows and is independent which framework is used. This was the reason, to write it with using the win32 api.

So it must be possible to write it with the win32 api, too. The video is located in C:\Windows\Temp. I did the following steps:


  • Create a fullscreen window
  • Create a PictureBox in Win 32
  • Play the video in the Picture Box
  • Stop the program

Create a fullscreen window

To create a fullscreen window I need the size of the desktop. I get this with with the GetSystemmetrix funciton:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx

The background color should be black.

      invoke CreateSolidBrush,0
mov   wc.hbrBackground,eax



Create a PictureBox in Win 32

In the following links this is done:

http://stackoverflow.com/questions/1754037/how-to-add-picture-box-in-win32-api-using-visual-c
http://social.msdn.microsoft.com/Forums/en-US/fe6963e8-db6e-4e5e-b145-9cef74d49b57/picturebox-in-win32c?forum=vssmartdevicesnative

I used "static" as a class name and "SS_BITMAP" as one of the window styles. As size I used the size of the video. The value of the upper left corner of the picture box is calculated with the video size and the desktop size.


Play the video in the Picture Box

Here I found a way how to play a video in a picture box:

http://social.msdn.microsoft.com/Forums/vstudio/de-DE/8d9d3dec-368a-491b-b628-c314d2751f57/how-to-play-video-in-c2008?forum=csharpgeneral

In the .data section I declared some orders:

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


The handle of the picture box I got from the CreateWindowEx function in the step ago, I only have to convert this handle to a string and to cat this string to Order1.
  invoke ltoa,hwndPictureBox,ADDR buffer                             
            invoke szCatStr,ADDR Order1,ADDR buffer



Stop the program

The program should stop, when it receives messages like WM_KEYDOWN or WM_MOUSEMOVE. So the parent window should have the input focus.

invoke SetFocus, hWnd


The program should react on the Message WM_MOUSEMOVE, but it doesn't if the cursor is inside the picture box. So I set the cursor out of it.

invoke SetCursorPos, x_cursor, y_cursor


The problem is, that the program receives this message although the mouse is not moved. I had to get the cursor position and compare it to the coordinates i had set the cursor to.

            invoke GetCursorPos, ADDR pt
            mov eax,pt.x
            .IF eax!=x_cursor
               invoke PostQuitMessage,NULL
            .ENDIF
            mov eax,pt.y
            .IF eax!=y_cursor
                invoke PostQuitMessage,NULL
            .ENDIF


The function GetCursorPos gives the coordinates back in a Point Structure.

POINT STRUCT
x DWORD ?
y DWORD ?
POINT ENDS
pt POINT <>


My problem is, that there is still a thin grey border around it, I can still see the cursor and, the biggest problem, I still can see the task bar. In the old forum there is a solution, I will try it in the near future.

http://www.masmforum.com/board/index.php?PHPSESSID=d52d81140238854679a6a365274e53d4&topic=17221.msg144070#msg144070

I attached the source code. If You try it, please add a file "video.wmv" in the temp dictionary.

This is my first big project in MASM32. If You have comments or ideas, what I could make better, please tell me.


Regards, Guenther

dedndave

to activate a screensaver, the system sends WM_SYSCOMMAND (check the docs)

i see there is an issue with DefScreenSaverProc, however
in the masm32 version 10 package, there was a scrnsave.inc and scrnsave.lib that had DefScreenSaverProc
but, i see it's not present in the version 11 package scrnsave.inc/lib files   :redface:

you might be able to make one of these work:
1) use LoadLibrary and GetProcAddress, PROTO, TYPEDEF
2) use the old versions of scrnsave.inc/lib
3) create a new scrnsave.inc/lib by updating the ones in masm32 version 11

anunitu

I remember from a while back a program that allowed a desktop wallpaper that was animated. I don't remember the name,but it might be dremples or something. I found it,I don't know if there is any source or an explanation of how it was done. It also mentions it can be a screen saver.

http://www.geisswerks.com/about_drempels.html

Just checked and there is source code you can DL,not sure what language it is in,but it might offer some insights.

http://www.geisswerks.com/drempels/index.html

Source is at the second link

Guenther78

Hello!

@Dedndave:
I took the example from http://www.asmcommunity.net/forums/topic/?id=21139 and added the new old scrnsave.lib. Now I have the unresolved external symbol __except_list. But I found _except_list in the library file (I opened it with the editor). But now the linker found the missed function DefScreenSaverProc.

@anunitu:
Thanks for the links, I will have a look at them later.

Regards, Guenther

Guenther78

Hello,

I saw that there is one underline more in the error message (_except_list) than in the lib-file (_except_list). I added a "_" it in the .lib-file. Now comes the linker error LNK1102 (out of memory). "Not enough memory for tool to run" says msdn.

Regards, Günther

vogelsang

"How beautiful this world ruled by dibs, not a gun!"
...