|
Hi,
I am facing problems in sending mouse clicks via SendInput API.
Mouse clicks are being sent but at the X,Y co-ordinates.
I am mapping my monitor to the (0,0,65535,65535) virtual monitor as needed by the SendInput. But the mouse clicks are always reported at the "current cursor location" (I am testing it with the notepad) irrespective of the X,Y co-ordinates specified.
Here is the code.
void SendMouseInput(unsigned int iX,unsigned int iY)
{
MOUSEINPUT mousei={0};
INPUT Input={0};
BlockInput(true);
::ZeroMemory(&Input,sizeof(INPUT));
::ZeroMemory(&mousei,sizeof(MOUSEINPUT));
mousei.dx=VirtualXFromAbsoluteX(iX);
mousei.dy=VirtualYFromAbsoluteY(iY);
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN;
Input.type = INPUT_MOUSE;
Input.mi = mousei;
if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTUP;
Input.type = INPUT_MOUSE;
Input.mi = mousei;
if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
BlockInput(false);
Sleep(1000);
}
static int VirtualXFromAbsoluteX ( int iX )
{
double Width = GetSystemMetrics ( SM_CXSCREEN ) ;
double Val = ( ((double)iX/Width) * (double)(65535) ) ;
double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;
if ( Ceil > Floor )
{
iX = (int)Ceil ;
}
else
{
iX = (int)Floor ;
}
return ( iX ) ;
}
static int VirtualYFromAbsoluteY ( int iY )
{
double Height = GetSystemMetrics ( SM_CYSCREEN ) ;
double Val = ( ((double)iY/Height) * (double)(65535) ) ;
double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;
if ( Ceil > Floor )
{
iY = (int)Ceil ;
}
else
{
iY = (int)Floor ;
}
return ( iY ) ;
}
void ShowError(LPTSTR lpszFunction)
{
TCHAR szBuf[80];
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
wsprintf(szBuf,
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);
::MessageBox(NULL, szBuf, "Error", MB_OK);
LocalFree(lpMsgBuf);
}
Am I doing something wrong?
PS: I am able to send key board events using SendInput.
Thanks a load in advance.
Subra
|
|
|
|
|
Hi Subra,
Try debugging the code by putting a break point over the event.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
I tried all possible debugging.
The data is going to SendInput correctly.
But the click is happening at the point where my mouse pointer is currently pointing. I also set windows hooks to monitor the mouse events before any application gets its hands on it. There also I see that the x,y co-ordinates are coming wrongly.
|
|
|
|
|
Function();
{...
m_nftp.MoveFile("/"+NameSelected,"C:\\"+NameSelected,
FALSE,TRUE);
m_nftp.LogOffServer();
//SetFileName(Filetitle,path+filetitle)
theApp.m_pWinamp->SetFileName(NameSelected,
"C:\\"+NameSelected);
theApp.m_pWinamp->Wload(); //Load WinAmp's playlist
My problem is that Winamp cant load the life altought (after manually i can add it )(file not corrupted)
Is a way to delay so Winamp can load its Playlist ?
|
|
|
|
|
Can u give me few more details of the problem ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Can you be more specific
whitesky
|
|
|
|
|
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
pCon=pContext;
m_wndSplitter.CreateStatic(this,2,1);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CView1),CSize(100,100),pContext);
m_wndSplitter1.CreateStatic(&m_wndSplitter,1,2,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(1,0));
m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CMyTreeCtrl),CSize(100,100),pContext);
m_wndSplitter1.CreateView(0,1,RUNTIME_CLASS(CView3),CSize(400,400),pContext);
return TRUE;
}
/////////////////////////////////////////////////////
void CMainFrame::SwitchView(CString str)
{
int id=m_wndSplitter1.IdFromRowCol(0,1);
m_wndSplitter1.DeleteView(0,1);
m_wndSplitter2.CreateStatic(&m_wndSplitter1,2,1,WS_CHILD|WS_VISIBLE,id);
m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CView2),CSize(100,100),pCon);
m_wndSplitter2.CreateView(1,0,RUNTIME_CLASS(CView2),CSize(400,400),pCon);
}
iam not getting any error wnen the same code in SwitchView(CString str)
fn is written in on OnCreateClient(.....) but it getting error it is written in SwitchView.where switch view is a fn called when a tree item is clicked
*********Heere i want to get a spiltter when an event is arised send me a gud solution.***********
...............sahaja
|
|
|
|
|
In case of the code in OnCreateClient(...) it is working because the splitter window is created there for the first time.
But if you want to change the view in the splitter window at runtime then you have to follow different procedure. Its not just simple delete one view and create another.;P
Regards
Anil
-- modified at 6:39 Tuesday 30th May, 2006
|
|
|
|
|
plz give me a brief idea of the procedure to be followed.
Thanks
..........sahaja
|
|
|
|
|
|
Hi,
I am lookoing for an an example in Visual C++ how to store/laod a TreeView in database, and show the hierachical data in a treeview.
In each row in the database there is an ID and a PARENTID
Thank you
Karl-Heinz
|
|
|
|
|
Hello guys I am beginner to MFC threading. Can any body give me a link to samples for learning multi threaded programming (other then MSDN)
Thank You
|
|
|
|
|
Search codeproject with multithreading in the search box.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Start here[^].
You'll find other excellent articles written by Joe Newcomer on his site.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
|
The first book i read is program windown in c (win32api) .When i come here i see that many u use MFC. Is MFC app is faster or easy to program than win32api.
i also see that i write code using gdi++, and i bring it to another computer, it'll not work because lack of dll.
MFC is the same???.
If u have good book and u want me read it, let send me at "sea.loves.you@gmail.com". Thanks
And i alway get problem that is when i write my app and it run well in my computer but when i bring it to another it can't. I try to copy some dll required, some app work and some don't. mysetting is incorrect,isn't it?
I use .Net 2005.
Another problem: when i write program, i compile and it run well, but at another time when i chose Rebuild solution, and i run my app, but it alway drop the message that can't not find msvc80....( dont remember). Why?
Thanks.
|
|
|
|
|
I think three question
1-?
2-maybe you use from serivces that are install only in your computer
3-Can you be more specific
whitesky
|
|
|
|
|
1. I don't know mfc i only know win32api, i wonder how it is. Because i see many u use it to write code! May be i'm "out of date".Does app Programming with mfc need some additional dll when running. If some kind send me a ebook about mfc.
2. I use .Net 2005 when i build my app and bring to another computer, i run it and alway get error message (0xc5).May be that computer need install framework2.0. can i avoid it .
3. I use .Net 2005 and each time i "Rebuild solution" then may app can't not run again because there is error message says that the app can't not find msvcd80.dll( not sure).
I don't know why?I always get that problem. When i start a new solution it build well and run well but if i press "rebuild solution" and i'm mad (Note: i have to project in my solution ). Now i go back to .Net2003 but if some one know tell me.
Thank everyone?
|
|
|
|
|
1- well it depend to your project of course basically yes
2-you answer to your question you use framework2.0 in your project and
maybe it not install in another computer
3-I use vs2005 and i create one project and build and again rebuild solution
and its not problem (maybe im not sure your vs has problem)
whitesky
|
|
|
|
|
hi!
there's a window that i don't own (displayed from a code on an external dll). is it possible to attach to the move event of that window?
i just need to move my app so that those two windows are always side by side. i've done this with the wm_move event on my side.
thanks!
|
|
|
|
|
You can get the handle of window by FindWindow .
then create the User messages and post it to the specific window by PostMessage
Cheers
"Peace of mind through Technology"
|
|
|
|
|
i don't want to Post messages to that window, I need to be notified what that window moves.
in short i need that window (which i only have a dll) to post messages to me.
|
|
|
|
|
ilidan wrote: there's a window that i don't own (displayed from a code on an external dll). is it possible to attach to the move event of that window?
Look up WH_CALLWNDPROC and WH_CALLWNDPROCRET .
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Thanks. This is exactly what I'm looking for!
|
|
|
|
|