gegj
October 19th, 2004, 02:54 PM
Hello. Im trying to make an app like the babylon translator where
u click over some text control and the application capture the string and process it.
My question is whats windows Api Functions i will must use to intercept the mouse clicks and capture the text.
I know that is complicated but i need some point to start.
Thanks
kawasaki056
October 20th, 2004, 01:30 AM
when the "focus" is in your application ( or you application is the "focused window" , WM_MOUSEMOVE is naturally, always coming to you application.(execept case some other window is intenrionaly capturing mouse , by SetCapture() )
this contains the coordinates of the mosue pointer. LOWRD(lParam) is x , HIWORD(lParam) is y.
this is in "client coordinate" . On the other hand, to get window handle of the window which to retrieve the text of , you use WindowFromPoint or, ChildWindowFromPonit . the former requires "screen coodinate" and the latter "client coodinate" . if you use former, exchangeing coordinate you use
MapWindowPoints() or MapWindowRect() (<= macro in windowsx.h )
and also you must sense the timing of the clikking .
WM_LBUTTONDOWN or WM_RBUTTONDOWN ,
I realized but , anyway, you handle this message, so you can use GetCursorPos( LPPOINT *lpPoint ) to get cursor pos.( it's in screen coordinates )
or sorry WM_LBUTTONDOWN itself contains COORDINATES !
so
case WM_LBUTTONDOWN :
{ HWND hBelow ; POINT pt ; pt.x = LOWORD( lParam) , pt.y = HIWORD(lParam) ;
char szstr[256] ;
MapWindowPoints( hWnd , NULL , &pt , 1 ) ; // to screen coordinates .
hBelow = WindowFromPoint( pt ) ; // get window handle. not "&pt" , just pt is ok
GetWindowText( hBelow , szstr , sizeof( szstr ) ) ; // you got it !
}
break ;
// but child windows does not send this , raw ,"WM_LBUTTONDOWN" to the "parent" window, so, you may do like this , it sends "WM_PARENTNOTIFY"
case WM_PARENTNOTIFY :
switch( LOWORD(wParam))
{ case WM_LBUTTONDOWN :
// here copy and paste whole of whole contentes of I wrote above in "WM_LBUTTONDOWN"
break ;
}
break ;
//and more !
//do first of all .( on WM_CREATE of parent window )
SetWindowLong( the_hadnle_of_child_containing_string , GWL_EXSTYLE ,
GetWindowLong( the_handle_of_child_containing_string , GWL_EXSTYLE ) & ~WS_EX_NOPARENTNOTIFY ) ) ; // &~ removes the flag !
........
// this is orthodox style. and , to static control , SS_NOTIFY style is needed.
// or, you may think , anyway you can only get the texts of windows which you created.
// to get texts rather freely , you can use "SetCapture( hWnd )" , setting your parent window the owner of Capture , and all of MOUSE events occur to your parents "WM_MOUSEXXX" .
// In that case , you make something like "capture mode" ,
// And switch between the modes using SetCapture() and ReleaseCapture() yourself.
gegj
October 20th, 2004, 10:23 AM
thanks a lot,
that is what i´m looking for.