I already have the handling procedures for the hotkeys, and everything, it's just this part doesn't work. (By the way, I just found out, from trying it with this project, that you don't even need a window to receive WM_* messages.)
Here's the code, if it's needed:
;; winmm.dll is one of the DLLs that we'll have to import functions from. ;; Externs. extern RegisterHotKey extern UnregisterHotKey extern GetMessageA extern TranslateMessage extern ExitProcess extern OpenFile extern ReadFile extern CloseHandle extern waveOutSetVolume extern waveOutGetVolume extern MessageBoxA ;; Imports. import RegisterHotKey user32.dll import UnregisterHotKey user32.dll import GetMessageA user32.dll import TranslateMessage user32.dll import ExitProcess kernel32.dll import OpenFile kernel32.dll import ReadFile kernel32.dll import CloseHandle kernel32.dll import waveOutSetVolume winmm.dll import waveOutGetVolume winmm.dll import MessageBoxA user32.dll ;; Defines. %define MOD_ALT 0x0001 %define MOD_CONTROL 0x0002 %define MOD_NOREPEAT 0x4000 %define MOD_SHIFT 0x0004 %define MOD_WIN 0x0008 %define WM_HOTKEY 0x0312 %define IDOK 0x0001 ;; MY_* defines. %define MY_LOUD 0x0001 %define MY_MUTE 0x0002 %define MY_WAIT 0x0003 %define MY_EXIT 0x0004 %define MY_TIME 0x0005 %define MY_SYNC 0x0006 %define MY_PREV 0x0007 section .text use32 ..start: call main push eax call [ExitProcess] main: enter 28, 0 call InitVolumeControl call ReadConfig push dword 1 call RegisterKeys .MessageLoop: lea ebx, [ebp-28] push dword 0 push dword 0 push dword 0 push dword ebx call [GetMessageA] cmp eax, 0 jz .ExitMessageLoop push dword ebx call [TranslateMessage] cmp dword [ebx+4], WM_HOTKEY jnz .MessageLoop mov eax, dword [ebx+8] cmp eax, MY_LOUD jz .go_loud cmp eax, MY_MUTE jz .go_mute cmp eax, MY_WAIT jz .go_wait cmp eax, MY_EXIT jz .go_exit cmp eax, MY_SYNC jz .go_sync cmp eax, MY_PREV jz .go_prev jmp .MessageLoop .go_loud: call LoudVolume push dword 0 push dword ApplicationName push dword loud_msg push dword 0 call [MessageBoxA] jmp .MessageLoop .go_mute: call MuteVolume push dword 0 push dword ApplicationName push dword mute_msg push dword 0 call [MessageBoxA] jmp .MessageLoop .go_wait: push dword 0 push dword ApplicationName push dword wait_msg push dword 0 call [MessageBoxA] jmp .MessageLoop .go_exit: push dword 0 push dword ApplicationName push dword exit_msg push dword 0 call [MessageBoxA] jmp .ExitMessageLoop jmp .MessageLoop .go_sync: push dword 1 push dword ApplicationName push dword sync_msg push dword 0 call [MessageBoxA] cmp eax, IDOK jnz .MessageLoop call ReadConfig push dword 1 call RegisterKeys jmp .MessageLoop .go_prev: call PrevVolume push dword 0 push dword ApplicationName push dword prev_msg push dword 0 call [MessageBoxA] jmp .MessageLoop .ExitMessageLoop: ;; If the parameter is 0, RegisterKeys() deregisters the hotkeys, and ;; does (just about) nothing else. push dword 0 call RegisterKeys xor eax, eax leave ret 0 ReadConfig: enter 144, 0 ;; hFile = [ebp-4] ;; ofs = [ebp-140] ;; brd = [ebp-144] pusha push dword dv1 push dword vl1 call strcpy push dword dv2 push dword vl2 call strcpy push dword dv3 push dword vl3 call strcpy push dword dv4 push dword vl4 call strcpy push dword dv5 push dword vl5 call strcpy push dword dv6 push dword vl6 call strcpy push dword dv7 push dword vl7 call strcpy mov dword [ebp-144], 0 ;; Open file. lea eax, [ebp-140] push dword 0 push dword eax push dword fn_cnf call [OpenFile] mov dword [ebp-4], eax ;; Read file to buffer. lea eax, [ebp-144] push dword 0 push dword eax push dword buff_len push dword buff_txt push dword [ebp-4] call [ReadFile] ;; NULL-terminate data. push dword [ebp-144] mov ebx, buff_txt pop ecx mov dword [ebx+ecx], 0 ;; Close file. push dword [ebp-4] call [CloseHandle] ;; Okay, now the scanning. We have to scan the text buffer, that we just read, for the configuration settings. mov ebx, buff_txt .lp1: cmp byte [ebx], 0 jz .lp1s ;; Copy whatever we're at to our temporary string. push dword ebx push dword temp_str call strcpy ;; Chomp the temporary string. push ebx mov ebx, temp_str call to_nl mov byte [ebx], 0 pop ebx ;; The temporary string most supposably contains a string of the format 'name=value' ;; Set the element, in our hash, with that name to that value. push dword temp_str push dword config call SetHash call to_nl jmp .lp1 .lp1s: popa leave ret 0 ;; RegisterKeys (bool register_keys); RegisterKeys: enter 516, 0 lea eax, [ebp-516] mov dword [ebp-4], eax mov eax, MY_LOUD call .undo mov eax, MY_MUTE call .undo mov eax, MY_WAIT call .undo mov eax, MY_EXIT call .undo ; mov eax, MY_TIME ; call .undo mov eax, MY_SYNC call .undo mov eax, MY_PREV call .undo ;; If need not to register keys, exit. mov eax, dword [ebp+8] test eax, eax jz .finish mov eax, values.j_loud mov ecx, MY_LOUD call .act mov eax, values.j_mute mov ecx, MY_MUTE call .act mov eax, values.j_wait mov ecx, MY_WAIT call .act mov eax, values.j_exit mov ecx, MY_EXIT call .act test eax, eax jnz .over1 mov eax, MY_LOUD call .undo mov eax, MY_MUTE call .undo mov eax, MY_WAIT call .undo push dword 0 push dword ApplicationName push dword startup_err_msg push dword 0 call [MessageBoxA] push dword 1 call [ExitProcess] .over1: ; mov eax, values.j_time ; mov ecx, MY_TIME ; call .act mov eax, values.j_sync mov ecx, MY_SYNC call .act mov eax, values.j_prev mov ecx, MY_PREV call .act call .work_time jmp .finish .act: push dword eax push dword [ebp-4] call strcpy push dword [ebp-4] push dword config call GetHash mov al, byte [ebp-516] call ensure_cap_byte push dword eax push dword MOD_CONTROL | MOD_ALT push dword ecx push dword 0 call [RegisterHotKey] ret 0 .undo: push dword eax push dword 0 call [UnregisterHotKey] ret 0 .work_time: push dword values.j_time push dword [ebp-4] call strcpy push dword [ebp-4] push dword config call GetHash push dword [ebp-4] call str2i mov dword [myTime], eax ret 0 .finish: leave ret 4 ensure_cap_byte: cmp al, 123 jnl .finish cmp al, 97 jl .finish sub al, 32 .finish: ret 0 to_nl: .lp1: mov al, byte [ebx] cmp al, 13 jz .lp1s cmp al, 10 jz .lp1s cmp al, 0 jz .lp1s inc ebx jmp .lp1 .lp1s: .lp2: mov al, byte [ebx] cmp al, 13 jz .lp2c cmp al, 10 jz .lp2c jmp .lp2s .lp2c: inc ebx jmp .lp2 .lp2s: ret 0 eq_nl: push eax push ebx mov eax, dword [esp+12] mov ebx, eax .lp1: mov al, byte [ebx] cmp al, 61 jz .lp1s cmp al, 0 jz .lp1s inc ebx jmp .lp1 .lp1s: mov byte [ebx], 0 pop ebx pop eax ret 4 InitVolumeControl: enter 512, 0 push dword prev_vol push dword 0 call [waveOutGetVolume] leave ret 0 PrevVolume: enter 512, 0 push dword [prev_vol] push dword 0 call [waveOutSetVolume] leave ret 0 LoudVolume: enter 512, 0 push dword [loud_vol] push dword 0 call [waveOutSetVolume] leave ret 0 MuteVolume: enter 512, 0 push dword 0 push dword 0 call [waveOutSetVolume] leave ret 0 %include "inc/str.asm" %include "inc/istr.asm" %include "inc/hash.asm" section .data myTime dd 30 ;; 30 seconds is the default wait time. fn_int db "interval.txt", 0 fn_cnf db "muteconf.txt", 0 ApplicationName db "SoundCat", 0 loud_msg db "Loud hotkey used. ", 0 mute_msg db "Mute hotkey used. ", 0 wait_msg db "Wait hotkey used. ", 0 exit_msg db "Press OK to exit. ", 0 sync_msg db "Press OK to sync SoundCat configurations. ", 0 prev_msg db "Prev hotkey used. ", 0 startup_err_msg db "Error: Could not register the exit hotkey. ", 0 nm1 db "loud", 0, 0, 0, 0 nm2 db "mute", 0, 0, 0, 0 nm3 db "wait", 0, 0, 0, 0 nm4 db "exit", 0, 0, 0, 0 nm5 db "time", 0, 0, 0, 0 nm6 db "sync", 0, 0, 0, 0 nm7 db "prev", 0, 0, 0, 0 dv1 db "L", 0 dv2 db "M", 0 dv3 db "W", 0 dv4 db "Q", 0 dv5 db "30", 0 dv6 db "S", 0 dv7 db "P", 0 config: dd nm1 dd vl1 dd nm2 dd vl2 dd nm3 dd vl3 dd nm4 dd vl4 dd nm5 dd vl5 dd nm6 dd vl6 dd nm7 dd vl7 dd 0 dd 0 values: .j_loud: db "loud", 0 .j_mute: db "mute", 0 .j_wait: db "wait", 0 .j_exit: db "exit", 0 .j_time: db "time", 0 .j_sync: db "sync", 0 .j_prev: db "prev", 0 section .bss prev_vol dd 0 loud_vol dd 0x7FFF7FFF buff_txt resb 4096 buff_len equ $ - buff_txt temp_str resb 4096 vl1 resb 512 vl2 resb 512 vl3 resb 512 vl4 resb 512 vl5 resb 512 vl6 resb 512 vl7 resb 512


Sign In
Create Account


Back to top









