flat assembler
Message board for the users of flat assembler.
Index
> Windows > [homework help] Get Mouse Position |
Author |
|
CrawlUp 20 Feb 2018, 19:30
Code: include 'd:\fasm\include\win32a.inc' entry start; ;_________CODE___________________________________________________________ section '_code' code readable executable start: invoke GetModuleHandle,0; invoke DialogBoxParam,eax,ID_DIALOG,0,DialogProc,0; invoke ExitProcess,0; ;_________DialogProc_____________________________________________________ proc DialogProc uses ebx esi edi,hdlg,msg,wparam,lparam xor eax,eax; cmp [msg],WM_CLOSE; jz .close; cmp [msg],WM_INITDIALOG; jz .initdialog; cmp [msg],WM_TIMER; jz .timer; ret; ;Initializing the dialog box .initdialog: invoke SetTimer,[hdlg],0,10,0; invoke GetCursorPos,point; invoke CreateThread,0,0,ThreadCheckTime,0,0,0; invoke CloseHandle,eax; invoke GetDC,[hdlg]; mov [hDC],eax; ret; ;Timer processing .timer: invoke GetCursorPos,point; invoke wsprintf,buff_Pos,mask_Pos,[point.x],[point.y]; add esp,16; ;get lenght string xor eax,eax; mov ecx,20; mov edi,buff_Pos; repnz scasb; mov eax,20; sub eax,ecx; ;setting a convenient position for display shl eax,3; sub eax,10; (count_symbol * 2 * 2 * 2)-10 = Width_window add [point.x],10; add [point.y],10; ;set new position and size for our window invoke MoveWindow,[hdlg],[point.x],[point.y],eax,15,TRUE cmp [Flag_SAME],1; jz @f; ;if Flag_SAME=0 print position mouse invoke TextOut,[hDC],0,0,buff_Pos,20 jmp .clear; @@: ;if Flag_SAME=1 pringt text 'SAME' invoke TextOut,[hDC],0,0,str_SAME,20 ;clear buffer buff_Pos: .clear: mov ecx,20; mov eax,buff_Pos; @@: mov byte[eax],0; inc eax; loop @b; ret; ;Close dialog .close: invoke CloseHandle,[hDC]; invoke EndDialog,[hdlg],0; xor eax,eax; ret; ret; endp; ;_________ThreadCheckTime_______________________________________________ ;Depending on the change in coordinates during the time, the flag is set proc ThreadCheckTime; xor eax,eax; xor edx,edx; lp: cmp eax,[point.x]; jnz SAME_0; cmp edx,[point.y]; jnz SAME_0; ;if the mouse position not changed set Flag_SAME = 1; mov [Flag_SAME],1; jmp SAME_1 SAME_0: mov [Flag_SAME],0; SAME_1: mov eax,[point.x]; mov edx,[point.y]; push eax edx; invoke Sleep,5000; pop edx eax; jmp lp; ret; endp; ;_________DATA___________________________________________________________ section '_data' data readable writeable; ;structure point POINT ;Descriptors hDC dd ?; ;mask mask_Pos db 'X:%u Y:%u',0; ;buffers buff_Pos rb 20; ;flag Flag_SAME dd 0; ;string str_SAME db 'SAME',0; ;_________RESOURCE________________________________________________________________ section '_res' resource data readable writeable; ID_DIALOG = 1000; directory RT_DIALOG,my_dialogs resource my_dialogs,ID_DIALOG,LANG_ENGLISH,my_dialog dialog my_dialog,'',0,0,0,0,WS_VISIBLE+WS_POPUP; enddialog ;_______IMPORT___________________________________________________________________ section '_import' import data readable writeable; library kernel32,'kernel32.dll',user32,'user32.dll',comctl32,'comctl32.dll',\ comdlg32,'COMDLG32.DLL',\; gdi32,'gdi32.dll' include 'd:\fasm\include\api\kernel32.inc'; include 'd:\fasm\include\api\user32.inc'; include 'd:\fasm\include\api\comctl32.inc' include 'd:\fasm\include\api\comdlg32.inc' include 'd:\fasm\include\api\gdi32.inc';
_________________ Use GoogleTranslate.... |
|||||||||||
20 Feb 2018, 19:30 |
|
DimonSoft 20 Feb 2018, 20:50
SC0U7 wrote: Can somebody help me with make a simple fasm program which do this: No need to use multiple threads, it would be plain over-engineering. Besides, no need to convert anything to string just to compare two points. I guess, this one would be the simplest solution (error handling skipped). Should compile with plain FASM with any paths. Code: format PE GUI 4.0 entry WinMain include 'win32w.inc' IDD_MAINDIALOG = 10 TIMER_ID = 1 proc MainDialog.DialogProc uses ebx esi edi,\ hDlg, uMsg, wParam, lParam mov eax, [uMsg] mov ebx, [hDlg] cmp eax, WM_INITDIALOG je .WMInitDialog cmp eax, WM_CLOSE je .WMClose cmp eax, WM_TIMER je .WMTimer .Default: xor eax, eax jmp .EndProc .WMInitDialog: invoke GetCursorPos, ptInitial invoke SetTimer, ebx, TIMER_ID, 5000, 0 jmp .ReturnTRUE .WMClose: invoke EndDialog, ebx, 0 jmp .ReturnTRUE .WMTimer: cmp [wParam], TIMER_ID jne .Default invoke GetCursorPos, ptNew mov ecx, [ptInitial.x] mov edx, [ptInitial.y] cmp ecx, [ptNew.x] jne .ReturnTRUE cmp edx, [ptNew.y] jne .ReturnTRUE invoke MessageBox, ebx, szText, szTitle, MB_ICONINFORMATION invoke KillTimer, ebx, TIMER_ID .ReturnTRUE: mov eax, TRUE .EndProc: ret endp proc WinMain invoke GetModuleHandle, 0 invoke DialogBoxParam, eax, IDD_MAINDIALOG, 0, MainDialog.DialogProc, 0 invoke ExitProcess, 0 endp szTitle du 'Info', 0 szText du 'SAME', 0 ptInitial POINT ptNew POINT data import library kernel32, 'kernel32.dll',\ user32, 'user32.dll' include 'api\kernel32.inc' include 'api\user32.inc' end data data resource directory RT_DIALOG, Dialogs resource Dialogs,\ IDD_MAINDIALOG, LANG_NEUTRAL, Dialogs.MainDialog dialog Dialogs.MainDialog, 'Mouse demo', 0, 0, 200, 200, WS_OVERLAPPEDWINDOW enddialog end data Feel free to ask any additional questions. |
|||
20 Feb 2018, 20:50 |
|
SC0U7 21 Feb 2018, 07:29
Thx both but CrawlUp you save my live
|
|||
21 Feb 2018, 07:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.