flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > [homework help] Get Mouse Position

Author
Thread Post new topic Reply to topic
SC0U7



Joined: 20 Feb 2018
Posts: 12

[homework help] Get Mouse Position

Hello all

Can somebody help me with make a simple fasm program which do this:

1.Get current cursor position
2.X and Y and when this position is same after 5sec then show messagebox with text "SAME"

Thx i have my school homework but i didnt find anywhere this info.

Thanks for all replies Embarassed
Post 20 Feb 2018, 13:34
View user's profile Send private message Reply with quote
CrawlUp



Joined: 23 May 2017
Posts: 8
Location: the USSR


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';



Description:
Download
Filename: GetPositionMouse.zip
Filesize: 2.52 KB
Downloaded: 27 Time(s)


_________________
Use GoogleTranslate....
Post 20 Feb 2018, 19:30
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 242
Location: Belarus

Re: Get Mouse Position


SC0U7 wrote:
Can somebody help me with make a simple fasm program which do this:

1.Get current cursor position
2.X and Y and when this position is same after 5sec then show messagebox with text "SAME"


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,\
             hDlguMsgwParamlParam

             mov        eax, [uMsg]
             mov        ebx, [hDlg]
             cmp        eaxWM_INITDIALOG
             je         .WMInitDialog
             cmp        eaxWM_CLOSE
             je         .WMClose
             cmp        eaxWM_TIMER
             je         .WMTimer
        .Default:
             xor        eaxeax
             jmp        .EndProc

        .WMInitDialog:
             invoke     GetCursorPosptInitial
             invoke     SetTimerebxTIMER_ID50000
             jmp        .ReturnTRUE
        .WMClose:
             invoke     EndDialogebx0
             jmp        .ReturnTRUE
        .WMTimer:
             cmp        [wParam], TIMER_ID
             jne        .Default
             invoke     GetCursorPosptNew
             mov        ecx, [ptInitial.x]
             mov        edx, [ptInitial.y]
             cmp        ecx, [ptNew.x]
             jne        .ReturnTRUE
             cmp        edx, [ptNew.y]
             jne        .ReturnTRUE
             invoke     MessageBoxebxszTextszTitleMB_ICONINFORMATION
             invoke     KillTimerebxTIMER_ID
        .ReturnTRUE:
             mov        eaxTRUE
        .EndProc:
             ret
        endp

        proc WinMain
             invoke     GetModuleHandle0
             invoke     DialogBoxParameaxIDD_MAINDIALOG0MainDialog.DialogProc0
             invoke     ExitProcess0
        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_DIALOGDialogs

        resource Dialogs,\
                 IDD_MAINDIALOGLANG_NEUTRALDialogs.MainDialog

        dialog Dialogs.MainDialog'Mouse demo'00200200WS_OVERLAPPEDWINDOW
        enddialog
end data


Feel free to ask any additional questions.
Post 20 Feb 2018, 20:50
View user's profile Send private message Visit poster's website Reply with quote
SC0U7



Joined: 20 Feb 2018
Posts: 12

Thx both but CrawlUp you save my live Shocked
Post 21 Feb 2018, 07:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.