;-mouse.asm------------------------------------------------------------------ ; x86 - Dos & Win32 - Assembly Language Programming ; ; ; ; Written by: John A Lyons ; ; Email : sysop@megablast.8k.com ; ; Page : http://www.asmsource.8k.com/ ; ; Compiler : Masm32 v6.13 Microsoft Macro Assembler ; ; Date : 23-Dec-2000 ; ; Purpose : A simple win32 application, that opens a window, and prints ; ; out the mouse coordinates, and where the two buttons are ; ; pressed. ; ; ; ;---------------------------------------------------------------------------- ; Compile with nmake ; ; or ; ; C:\MASM32\!ME\HELLO>ml /c /coff /Cp /Ic:\masm32\include mouse.asm ; Microsoft (R) Macro Assembler Version 6.13.7299 ; Copyright (C) Microsoft Corp 1981-1997. All rights reserved. ; ; Assembling: mouse.asm ; ; C:\MASM32\!ME\HELLO>Link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib mouse.obj ; Microsoft (R) Incremental Linker Version 5.12.8078 ; Copyright (C) Microsoft Corp 1992-1998. All rights reserved. ; .386 ; 32-Bit when .386 appears before .MODEL .MODEL FLAT , STDCALL include windows.inc include user32.inc include kernel32.inc include gdi32.inc includelib user32.lib includelib kernel32.lib includelib gdi32.lib EXTRN wsprintfA:PROC .data ClassName db "SimpleWinClass",0 AppName db "Mouse",0 mouse1 db "Mouse at %lu , %lu ",0 mouser db "Right at %lu , %lu ",0 mousel db "Left at %lu , %lu ",0 mouse db "Mouse mouse in window",0 .data? hInstance HINSTANCE ? CommandLine LPSTR ? hwnd HWND ? hdc HDC ? temp db 100 dup(0) .code WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_WINDOW+1 mov wc.lpszMenuName,NULL mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,0 invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, ;postion 300,100, ;size NULL,NULL,\ hInst,NULL mov hwnd,eax INVOKE ShowWindow, hwnd,SW_SHOWNORMAL INVOKE UpdateWindow, hwnd .WHILE TRUE INVOKE GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) INVOKE TranslateMessage, ADDR msg INVOKE DispatchMessage, ADDR msg .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL ps:PAINTSTRUCT mov eax,uMsg .IF eax==WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF eax==WM_PAINT invoke BeginPaint,hWnd, ADDR ps mov hdc,eax invoke TextOut,hdc,0,0,ADDR mouse,(SIZEOF mouse) -1 invoke EndPaint,hWnd, ADDR ps .ELSEIF eax==WM_MOUSEMOVE mov ebx,lParam invoke GetDC,hWnd mov hdc,eax mov eax,ebx shr eax,16 and ebx,65535 push eax push ebx push offset mouse1 lea eax,temp push eax mov ebx,0 call wsprintfA call showtemp invoke EndPaint,hWnd, ADDR ps .ELSEIF eax==WM_LBUTTONDOWN mov ebx,lParam invoke GetDC,hWnd mov hdc,eax mov eax,ebx shr eax,16 and ebx,65535 push eax push ebx push offset mousel lea eax,temp push eax call wsprintfA mov ebx,15 call showtemp invoke EndPaint,hWnd, ADDR ps .ELSEIF eax==WM_RBUTTONDOWN mov ebx,lParam invoke GetDC,hWnd mov hdc,eax mov eax,ebx shr eax,16 and ebx,65535 push eax push ebx push offset mouser lea eax,temp push eax call wsprintfA mov ebx,30 call showtemp invoke EndPaint,hWnd, ADDR ps .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp showtemp proc near lea esi,temp xor ecx,ecx loll1: inc ecx inc esi cmp [esi],byte ptr 0 jne loll1 invoke TextOut,hdc,0,ebx,ADDR temp,ecx ret showtemp endp start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax end start