Tutorials to .com

Tutorials to .com » Software » Asm » WIN32 compilation: 7. To deal with mouse input information

WIN32 compilation: 7. To deal with mouse input information

Print View , by: iSee ,Total views: 11 ,Word Count: 1332 ,Date: Mon, 11 May 2009 Time: 12:01 AM

Section VII of the mouse input information processing


This lesson we will learn how the process window in our mouse button function to deal with the news. Examples of procedures demonstrate how to press the left waiting for news, we will show in the press of a string position.

Theory:

And dealing with the same keyboard, WINDOWS will capture mouse movements and send them to the relevant windows. These activities include left and right-click, mobile, double-click, etc. (Translator's Note: The new mouse also includes the news wheel WM_WHEEL). WINDOWS do not like to deal with keyboard input, as all the mouse messages are input-oriented focus of a window, any window the mouse through the mouse would receive the message, regardless of whether the input focus. In addition, the window will receive the mouse movement in the non-client area of the message (WM_NCMOVE), but most cases we will be ignored. Each of the mouse button has two sources: WM_LBUTTONDOWN, WM_RBUTTONDOWN. Three-button mouse for WM_MBUTTONDOWN and WM_MBUTTONUP there will be news, when the mouse in a window area of mobile customers, the window will receive the message WM_MOUSEMOVE. If you want to deal with a window WM_LBUTTONDBCLK or WM_RBUTTONDBCLK, then it must have the window class CS_DBLCLKS style, otherwise it will receive a bunch of ups and downs of the keys (WM_XBUTTONDOWN or WM_XBUTTONUP) news. For all the news of the window function into the process of lParam parameter contains the location of the mouse, which at the end of spaces for the x coordinate, high for the y coordinates, these coordinates are relative to the upper left corner of the window client area value, wParam, however contains the status of the mouse button.

Examples:

.386
. model flat, stdcall
option casemap: none

WinMain proto: DWORD,: DWORD,: DWORD,: DWORD

include \ masm32 \ include \ windows.inc
include \ masm32 \ include \ user32.inc
include \ masm32 \ include \ kernel32.inc
include \ masm32 \ include \ gdi32.inc
includelib \ masm32 \ lib \ user32.lib
includelib \ masm32 \ lib \ kernel32.lib
includelib \ masm32 \ lib \ gdi32.lib

. data
ClassName db "SimpleWinClass", 0
AppName db "Our First Window", 0
MouseClick db 0; 0 = no click yet

. data?
hInstance HINSTANCE?
CommandLine LPSTR?
hitpoint POINT <>

. code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain proc hInst: HINSTANCE, hPrevInst: HINSTANCE, CmdLine: LPSTR, CmdShow: DWORD
LOCAL wc: WNDCLASSEX
LOCAL msg: MSG
LOCAL hwnd: HWND
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 hInst
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, eax
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, CW_USEDEFAULT, CW_USEDEFAULT, 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 DispatchMessage, ADDR msg
. ENDW
mov eax, msg.wParam
ret
WinMain endp

WndProc proc hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
LOCAL hdc: HDC
LOCAL ps: PAINTSTRUCT

. IF uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
. ELSEIF uMsg == WM_LBUTTONDOWN
mov eax, lParam
and eax, 0FFFFh
mov hitpoint.x, eax
mov eax, lParam
shr eax, 16
mov hitpoint.y, eax
mov MouseClick, TRUE
invoke InvalidateRect, hWnd, NULL, TRUE
. ELSEIF uMsg == WM_PAINT
invoke BeginPaint, hWnd, ADDR ps
mov hdc, eax
. IF MouseClick
invoke lstrlen, ADDR AppName
invoke TextOut, hdc, hitpoint.x, hitpoint.y, ADDR AppName, eax
. ENDIF
invoke EndPaint, hWnd, ADDR ps
. ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
. ENDIF
xor eax, eax
ret
WndProc endp
end start

Analysis:

. ELSEIF uMsg == WM_LBUTTONDOWN
mov eax, lParam
and eax, 0FFFFh
mov hitpoint.x, eax
mov eax, lParam
shr eax, 16
mov hitpoint.y, eax
mov MouseClick, TRUE
invoke InvalidateRect, hWnd, NULL, TRUE

WM_LBUTTONDOWN the process window of the message, when receiving the message, lParam contains the window client area relative to the coordinates of the upper-left corner, we have saved it, into a structure variable (POINT), the structure variables defined as follows:

POINT STRUCT
x dd?
y dd?
POINT ENDS

Then we set the mark MouseClick volume TRUE, this indicates that customers at least once in the left press the message area.

mov eax, lParam
and eax, 0FFFFh
mov hitpoint.x, eax

As the lParam is a 32-bit long number, including the high end of 16, respectively, including the x, y coordinates so we do something small in order to preserve them.

shr eax, 16
mov hitpoint.y, eax
Save End coordinates MouseClick signs we set for TRUE, which is used in handling the WM_PAINT determine whether there is any message press the left mouse button. Then we call InvalidateRect () function WINDOWS forcing customers to re-draw the district.

. IF MouseClick
invoke lstrlen, ADDR AppName
invoke TextOut, hdc, hitpoint.x, hitpoint.y, ADDR AppName, eax
. ENDIF

Drawing customers area code first MouseClick flag detection, and then decide whether or not to redraw. Because we show the window at the first press had not yet left the message, so we initially set the symbol FALSE, told not to redraw WINDOWS customer area, press the left button when the message, it will Press the mouse position in the string map. Call attention to TextOut () function, its parameters on the length of the string is called lstrlen () function to be calculated.



Assembly Language Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.