News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Guess what: Another simple program!

Started by felipe, May 17, 2017, 02:45:10 AM

Previous topic - Next topic

felipe

The program would check if the beep in your machine is turned off or on. Then you can decide if to turn off, turn on or do no change. So, run the program as necessary  to configure the beep and to check for your self if the configuration was applied.   8)


.386
.model  flat,stdcall
option  casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\user32.inc

includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib

.data?
on_OR_off       dword   ?

.data
title_program   byte    'BEEP CHECKER',0
content_welcome byte    'This program would let you',0ah,0dh
                byte    'check if the beep in your machine is on or off.',0ah,0dh
                byte    'Then you can change this setting as you wish.',0
content_off_?   byte    'The beep is turned on.',0ah,0dh
                byte    'Do you wish to turn off the beep?',0
content_on_?    byte    'The beep is off.',0ah,0dh
                byte    'Do you wish to turn the beep on?',0   
         
.code
start:
        push    MB_OK                           ; Welcome message.
        push    offset title_program
        push    offset content_welcome
        push    0
        call    MessageBox
       

        push    SPIF_UPDATEINIFILE              ; Test for beep if is on or off.
        push    offset on_OR_off
        push    0
        push    SPI_GETBEEP
        call    SystemParametersInfo


        cmp     on_OR_off,TRUE                     
        jne     not_active                      ; If is off we ask the user if he want to turn the beep on.

        push    1000                            ; Is on, so we make a beep showing the user that fact.
        push    580
        call    Beep

        push    MB_OKCANCEL                     ; Then we ask the user if he wants to turn the beep off.
        push    offset title_program
        push    offset content_off_?
        push    0
        call    MessageBox

        cmp     eax,IDOK                       
        je      turn_off
        jmp     the_end                         ; If he say no the program finish.

turn_off:
        push    SPIF_UPDATEINIFILE              ; We turn off the beep like the user wants.
        push    0
        push    FALSE
        push    SPI_SETBEEP
        call    SystemParametersInfo
        jmp     the_end
   
not_active:
        push    MB_OKCANCEL                     ; Is off so we ask the user if he want to turn on.
        push    offset title_program
        push    offset content_on_?
        push    0
        call    MessageBox

        cmp     eax,IDOK
        je      turn_on                         
        jmp     the_end                         ; If the user say no the program finish.

turn_on:
        push    SPIF_UPDATEINIFILE
        push    0
        push    TRUE
        push    SPI_SETBEEP
        call    SystemParametersInfo
       
the_end:
        push    0
        call    ExitProcess

        end     start

jj2007

Congrats, the parameter count seems correct this time :t

        cmp     eax,IDOK
        je      turn_on                         
        jmp     the_end                         ; If the user say no the program finish.

turn_on:


Better:        cmp     eax,IDOK
        jne     the_end                         ; If the user say no the program finish.

turn_on:

felipe

Thanks JJ! You are right about that optimization, thanks a lot!  :icon_mrgreen: