News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SetCaptue probelm

Started by realcr, December 26, 2004, 08:36:30 PM

Previous topic - Next topic

realcr

I was trying to create a piece of code which finds a window's handle by clicking on it:



.elseif eax==IDC_GETHANDLE ;we should get the handle of the target window.
mov IsHandle,0 ;in the process of looking for a handle.
invoke SetCapture,hWnd ;captue the mouse.
invoke ShowWindow,hWnd,SW_MINIMIZE ;hiding this window.

.endif





.elseif uMsg==WM_LBUTTONDOWN

cmp IsHandle,0
jnz a1 ;if it is not equal get out.
Debg 1
invoke ReleaseCapture ;release the mouse capture:
;get the point coordinates:
        mov eax,lParam
        and eax,0FFFFh
        mov hitpoint.x,eax
        mov eax,lParam
        shr eax,16
        mov hitpoint.y,eax
invoke WindowFromPoint,hitpoint.x,hitpoint.y
mov THandle,eax ;save the target window handle.
invoke dwtoa,eax,addr buffer

invoke SetWindowText,HTHANDLE,addr buffer

invoke ShowWindow,hWnd,SW_SHOWDEFAULT   ;show the window again.

or IsHandle,-1


a1:



However  , after the window is minimized , It doesn't react for any clicks on other windows. (it should get the window visible again and write down the handle of the window I clicked on).

bar.

gabor

Hi!

The linked thread may have some usefull hints, since getting the window handle under the mouse cursor is discussed there.
In your code there is a WindowFromPoint call just as it is in this other topic. It might help...
http://www.masmforum.com/simple/index.php?topic=3755

If you achieve something, please tell about the solution you found.

Greets, Gábor

tenkey

Quote from: realcr on December 26, 2004, 08:36:30 PM
I was trying to create a piece of code which finds a window's handle by clicking on it:



.elseif eax==IDC_GETHANDLE ;we should get the handle of the target window.
mov IsHandle,0 ;in the process of looking for a handle.
invoke SetCapture,hWnd ;captue the mouse.
invoke ShowWindow,hWnd,SW_MINIMIZE ;hiding this window.

.endif



However  , after the window is minimized , It doesn't react for any clicks on other windows. (it should get the window visible again and write down the handle of the window I clicked on).

That's because in Win32, the mouse capture is released as soon as your cursor moves out of all windows associated with your process (program instance). If all your windows together fill the screen, capture works as expected. But if your windows don't fill up the screen, then moving outside releases the capture.

I got caught with that, and had to reread the Win32 docs several times to figure out under what conditions the capture works. It is much more limited than in Win16.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

ramguru

I must disagree with you, tenkey. SetCapture works until you ReleaseCapture. Want some evidence, try to select text in standard edit box, you'll see that you can select text from whatever position (from the moment you pressed down (SetCapture) .. until you'll press up (ReleaseCapture)). But I must admit that WindowFromPoint works properly only with mouse-hook.

tenkey

Reduce the window containing the edit box to half size. Move your cursor outside the containing window. Mouse capture released.

If I've misremembered, then open up Notepad or any other app. Moving the cursor over the new app will release mouse from the other app.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

ramguru

Sorry, neither resizing nor mouse over other app releases capture, but Alt+Tab or suddenly popuped window (say IM window) of course will...

zooba

Quote from: MSDNSetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down. Only one window at a time can capture the mouse.

Quote from: MSDNA window that has captured the mouse receives all mouse input, regardless of the position of the cursor, except when a mouse button is clicked while the cursor hot spot is in the window of another thread.

So when it is captured, moving the mouse outside of your client will stop the messages coming, and a click will change the focus (and lose the capture) without sending a mouse message.