|
The project:
I wrote a program Ahook that hooks the keyboard and mouse events appear in the system and send them to other target application – the Paint which is not in focus and is in background window (i don't want it to be in focus and want it to be in the background). It means that I can for example move and use the mouse anywhere on the desktop or on any other application, but the Paint program will be operated as like the mouse was moving over it.
How it is done:
The Ahook uses the follow function to hook all keyboard and mouse events:
hHook=SetWindowsHookEx(WH_JOURNALRECORD,journalRecordProc, AhookInstance,0);
In order to send the messages to the Paint, the Ahook uses the follow function:
PostMessage(hPaintWnd, message,0, (iNy<<16) + iNx);
iNx and iNy are normalized mouse location values -means, I change the real location of the mouse to a location that is on the Paint program.
Results and problem:
I used the Spy++ to check the operation of all this and the Paint program receives all events Ahook sends. The location of the mouse as Paint sees is ok, means that paints "thinks" that the mouse is moving on it. But there is problem – the Paint program doesn't react to the events although it receives them. Why???
a) Is it because Paint is not in focus?
b) Is it because the messages found by WH_JOURNALRECORD hooked are not the relevant for sending to the Paint getmessage loop ?
c) Is there any other reason?
Some more information that may lead to conclusion:
a) Looking the Spy++ results for events Paint sees when Ahook sent it, shows very simple events such as WM_MOUSEMOVE and WM_LBUTTONDOWN etc.
b) Looking the Spy++ results for events received when mouse is used on the Paint, shows that the messages are much more complicated than just mouse move and mouse button down/up. It contains WM_NCHITTEST, WM_SETCURSOR, WM_NCMOUSEMOVE (but not WM_MOUSEMOVE) etc, is it says that what Ahook sends is not the relevant information???
Thansk
|
|
|
|
|
Hope u hooked the window proc too WH_CALLWNDPROC
Величие не Бога может быть недооценена.
|
|
|
|
|
Why should I do it? why it may solve the problem?
In addition, can I hook with WH_CALLWNDPROC with non-dll application (Ahook is not a Dll) ?
|
|
|
|
|
After another search for solution I found the concept of using SendInput while attaching my application thread to the application I want to control. Here is the short console program code for writing the letter 'g' on the notepad program.
But still problem - it doesn't put the letter on the notepad... why?
#include "stdafx.h"
#include "conio.h"
#include "windows.h"
void sendKey(WORD wVk)
{
INPUT input[2];
input[0].ki.wVk = wVk;
input[0].ki.wScan = 0;
input[0].ki.dwFlags = 0;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[0].type = INPUT_KEYBOARD;
input[1].ki.wVk = wVk;
input[1].ki.wScan = 0;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
SendInput(2, input, sizeof(INPUT));
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR sText[1024];
HWND hTargetWnd;
DWORD processID;
DWORD threadID;
HWND hNotepadWnd = FindWindow(NULL, L"Untitled - Notepad");
hTargetWnd=FindWindowEx(hNotepadWnd,NULL,L"Edit",NULL);
threadID = GetWindowThreadProcessId(hTargetWnd , &processID);
if(hTargetWnd)
{
wsprintf(sText, L"Target window found\nWindow = %p\nprocessID = %x\nThreadID = %x\n",hTargetWnd,processID,threadID);
wprintf(L"%s",sText);
if(AttachThreadInput( GetCurrentThreadId(), threadID,true))
{
sendKey('G');
AttachThreadInput(GetCurrentThreadId(),threadID, false);
}
}
else
{
wprintf(L"Window Notepad wasn't found\n");
}
while(_kbhit())
{
wprintf(L"%c",getch());
}
while(!_kbhit());
return 0;
}
|
|
|
|
|
Hi all,
I want to make a Data Stream.
I have used this code to make it. But using this code slows down my process.
IStream* pStream;
if(CreateStreamOnHGlobal(NULL, TRUE, &pStream) == S_OK)
{
ulWritten = 0;
pStream->Write(buffer1, 512, &ulWritten);
}
Can anybody please suggest the bug in this code or alternate code for doing this.
Thanks in advance
|
|
|
|
|
Well, all code slows things down. That's what doing stuff does.
You have to be careful to not do too much inside loops, etc. Classic programming stuff.
What might speed things up a little is if you know the size of data you'll be writing is to GlobalAlloc a chunk of memory, and feed that to CreateStreamOnHGlobal instead of it having to reallocate. But it's doubtful you'll get a great improvement.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hello All~~
Does anyone know how to display the OpenCV image structure "IplImage" in MFC CView?
Typically, many example shows that after we called 'cvLoadImage()', it will call 'cvShowImage' to display the image in another seperate window (as the code below).
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
What if I would like to display the image readed by OpenCV 'cvLoadImage' into CView, how can I do that????
Any suggestion, please?????
Thank you very much.
// I found that CImage from MS cannot open PPM file and I would like to use some features of OpenCV so I changed to OpenCV but now I found this problem. Please help.
|
|
|
|
|
hi all,
i am using xmlhttp request to fetch data from server but i have to set proxy with the request.please help me.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
Hi
I'm trying to submit a web form with method=POST parameter.
However, when I run the following code, I'm getting an error saying: "The URL is invalid"
CString strHeaders =_T("Content-Type: application/x-www-form-urlencoded");
CString strFormData = _T("query=murod&a=14");
CInternetSession* pSes=new CInternetSession();
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));
CHttpFile* pFile =
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
_T("/news/"));
BOOL result = pFile->SendRequest(strHeaders,
(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
What I'm doing wrong?
|
|
|
|
|
LOL I found my mistake
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));
Looks like I should not include "http://" in the url.
Now another problem:
I'm able to send the request, but how do I get the response? The response will be a web page source?
After sending the request I wrote the content of the pFile(CHttpFile class) to a file and based on that file I'm guessing either I didn't send the request, or either I didn't get the response.
What should I do to get the response?
|
|
|
|
|
after calling, CHttpFile::SendRequest
u should call CHttpFile::QueryInfoStatusCode
u will get status code...Http Error Codes...
if status code is 200, then u can download the response using CHttpFile::Read.
response may contain Html content or File Content if u have called to pdf,doc etc.
Regards,
Swapnil
|
|
|
|
|
Thanks alot for your reply Swapnil.
CHttpFile::QueryInfoStatusCode is very helpful, thank you!
That's what I did. I used CHttpFile::Read, and it didn't look like a right response.
Looks like I'm sending wrong headers and/or post data.
|
|
|
|
|
ADO, MFC, STUDIO 2008
There is control CListCtrl on a dialog window.
CListCtrl m_listCtrl;
DDX_Control(pDX, IDC_LIST1, m_listCtrl);
m_listCtrl.SetItemState(100,LVIS_SELECTED, LVIS_SELECTED); // choose row 100
How do by programmatically to scroll rows into control
of class CListCtrl?
There are only 7 rows into view area of control CListCtrl.
|
|
|
|
|
You should be able to do this using CListCtrl::EnsureVisible[^].
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Dir all.
How i can know my progarme run form exe file or release mode of VS.
Example :
...
// run by F5 in VS
#if ! define (ABC) // i try _DEBUG and NDEBUG but it ca not check
messagebox("run by VS");
// run by double click in exe file
#else
messagebox("run by it selft");
#endif
...
|
|
|
|
|
First of all, macros are evaluated during compile time, not runtime, your #if !defined... thing will be "built into your exe" when you build your program, and then no matter where you run your program from this won't change your already built exe.
A way you could do this is by giving a command line parameter to your program in visual studio and then checking the existence of this parameter in your exe, if it is there, you runned your program from VS, if it is not there, you runned it by doubleclicking it in an explorer window for example.
Does this help?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi,
Is it possible to find out file location using C language in Windows programming?Is there any function in C language which can display the file location?
|
|
|
|
|
Could you please elaborate?
For instance what would be the input of such function?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
i think that if i can found the location of the file so i can give that location of the file to my c program which would act as input.doing this that c program can read or whatever i want.
|
|
|
|
|
From your previous post, I may guess you need the file location, given mouse pointer position as input. If you need this the you've to write a shell extension, hence the link I provided.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi.
firstly i want to say very very thank you. actually i want to do all the work in C .can it is be possible that without writting shell extension which you have provide me i can do all that job?
|
|
|
|
|
AFAIK writing the shell extension is by far the simplest way to do it. Michael's articles are really good stuff, have a look at them.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
i understand what you want to say. but my problem is that i want an exe file that can do all those job.
|
|
|
|
|
ravi 12 wrote: Is it possible to find out file location using C language...
What file?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hi DavidCrow,
actually there is a order.docx file in my PC.I have placed it in D:\important\order.docx location. I want to know that can i find out it location using C Language?
|
|
|
|