Author Topic: A program very simple and funny.  (Read 287 times)

felipe

  • Member
  • ***
  • Posts: 279
  • I love assembly language programming.
A program very simple and funny.
« on: April 29, 2017, 05:06:37 AM »
Here is a simple program that change the desktop wallpaper to an image of your choice. It's very simple because you should write in the code the path of the image of your choice (if you want to give it a try of course). I will try to improve it (maybe) later to have a menu or something like that to choose the path in runtime.  :P

Code: [Select]
            title   wallpaper.asm               For change the desktop wallpaper.

                    include c:\masm32\include\masm32rt.inc

                    .data
new_wallpaper       byte    'c:\Users\Administrador\Desktop\Programacion\window00\nuevo.bmp',0      ; You can put here whatever path for an image.

                    .code
start:

main                proc
                    call    GetDesktopWindow        ; Windows give us a handle for the desktop wallpaper.
                    push    eax                     ; Not necessary i guess.
                    call    change_wallpaper        ; Puts a new wallpaper in the desktop.
                    call    ExitProcess             
main                endp

change_wallpaper    proc                            ; Puts a new wallpaper.
                    push    SPIF_UPDATEINIFILE     ; Updates your user profile.
                    push    offset new_wallpaper    ; Pointer to the path of the image.   
                    push    0                       ; Must be null (not used).
                    push    SPI_SETDESKWALLPAPER    ; To change the desktop wallpaper.   
                    call    SystemParametersInfo    ; Windows will do just that.   
                    ret
change_wallpaper    endp

                    end     start
                   
Felipe.

Vortex

  • Member
  • *****
  • Posts: 1703
Re: A program very simple and funny.
« Reply #1 on: April 29, 2017, 05:58:31 AM »
Hi felipe,

To avoid hardcoded filenames, you can use the command line to specify the wallpaper :

Code: [Select]
ChgWallPaper.exe wallpaper.bmp
Code: [Select]
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\msvcrt.lib

.data

bWildCard   dd 0

.data?

argc        dd ?
argv        dd ?
pEnv        dd ?
StartInfo   STARTUPINFO <?>

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC

    invoke  crt___getmainargs,ADDR argc,ADDR argv,\
            ADDR pEnv,bWildCard,ADDR StartInfo

    cmp     argc,2
    je      @f

    ret
@@:
    mov     eax,argv
    invoke  SystemParametersInfo,SPI_SETDESKWALLPAPER,\
            0,DWORD PTR [eax+4],SPIF_UPDATEINIFILE
    ret

main ENDP   

END start

felipe

  • Member
  • ***
  • Posts: 279
  • I love assembly language programming.
Re: A program very simple and funny.
« Reply #2 on: April 29, 2017, 07:03:08 AM »
Vortex: great job! Works very good.
You are right of course, i was just been studying and practising.  :icon14:
Felipe.

TWell

  • Member
  • ****
  • Posts: 748
Re: A program very simple and funny.
« Reply #3 on: April 29, 2017, 05:20:30 PM »
Quote
_StartInfo
Other information to be passed to the CRT DLL.
that StartInfo can be DWORD with value 0 if nothing passed to CRT DLL ? WindowsXP needs that?


Vortex

  • Member
  • *****
  • Posts: 1703
Re: A program very simple and funny.
« Reply #4 on: April 29, 2017, 06:12:06 PM »
Hi TWell,

The purpose is to conform with the MS specification. A small safety measure.