|
Hi all,
is it possible to intercept keystrokes in a service?
Every Service run in a different desktop from the one a user logs, so basically I think this service should grab any keystrokes in any desktop. Do you have any experience on that?
Thanx alot n' Merry Xmas.
|
|
|
|
|
> ..so basically I think this service should grab any keystrokes in any desktop
Not at all.
To grab keystrokes you have to call the SetWindowsHookEx API. Problem: SetWindowsHookEx resides in user32.dll and user32 functions are generally bound to a specific desktop. Because most services don't run under the logged-on user account you won't be able to grab the keystrokes of the loged-on user either (nor the keystrokes of any other desktop, like WinLogon for example) - at least not directly.
Fortunately there are two exceptions to the above rule:
1. Services running under the local System account can be made interactive. In other words, they can interact with the user and thus grab its keystrokes too. But this way you will only grab the keystrokes of the loged-on users desktop -> it's the same as if you would make an ordinary win32 exe right away.
2. You can "connect" a (service) thread to a desktop via SetThreadDesktop . Knowing this, you could try on of the following:
a) Spawn a new thread for each desktop that is present on the system; then call SetThreadDesktop and SetWindowsHookEx from within each thread.
b) Since there is only one interactive desktop (=desktop, that receives the user input) at any time, simply call SetThreadDesktop and SetWindowsHookEx always when the active desktop gets switched.
Note: This were just presumptions from the top of my head -> for the exact behavior/terminology and implementation check the MSDN documentation.
RK
|
|
|
|
|
Thanx a lot. I will check for something.
Merry xmas
|
|
|
|
|
I used two socket to communication with two computer,and My Computer acts as Server and Client。Socket1 receive order of "Connect A" from the Clent(now my computer is server)and connect Machine A(now my computer is clent) by Socket2。when Received "Stop" order,my computer disconnect A.I have tried,but failured.the error is that Socket2 can't connect Machine A in the Child thread.
Please help me,thanks a lot
|
|
|
|
|
As I undestand, you are trying to use socket in a thread which have not message pump. It is not works. Because CAsyncSocket ar CSocket derived classes have to be used in thread which have message pump. Sockets are needs message pump interface.
Try to use in main thread or another process which have message pump.
Erkan Ermis
|
|
|
|
|
hi ,
i have created an activex control in vb. in one of the method the user passes the file path to the control.
in vb i used string to get the file path... now in vc++ when i insert the control its been declared i.e the string variable is been declared as BSTR* filepath...so i cant pass the variable which i am capturing as a CString.
What is the problem???
Thanking you.
Satadru.
|
|
|
|
|
strings are used as BSTR in COM
VB Hides this complexity from the user
but in VC u'll have to convert BSTR in to CString
there are many good bstr classes in VC u can use
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
hi thanks for your reply ..
i have found out the problem... while creating the methods for the control i used functions which are by default reference but in vc++ its by value .... that was the problem ..thanks anyway
|
|
|
|
|
|
You bet
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
hi thanks for your reply ..
i have found out the problem... while creating the methods for the control i used functions which are by default reference but in vc++ its by value .... that was the problem ..thanks anyway
|
|
|
|
|
I made com exe (not service) i have few interface in that, One of my requirement is to listen to windows messages also how do i do that ?
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
Create an Invisible Window and create a message Loop for that in a new thread if required
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
i figured that already and i implemented that too...
what i wanted to know that since i am using atl is there anything that atl provides to do the message handling.
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
You need some thing like spy++. I believe I have seen a simular program here at codeproject. You can also look at sourceforge.
The difference seems to be that you want to listen to all message sent to your program. This is easy if it was written in C, but if you are using MFC (or some other frame work) then you needed to understand where the frame work is rerouting the messages so you can intercept them.
Hey! With a little patience you can single step through, from the beggining, any (Windows) application to determine how to intercept all messages.
INTP
|
|
|
|
|
hi..i need help on a prob pls...
i have a proj where i draw a rect in the OnDraw of my proj's View...
code:
--------------------------------------------------------------------------------
//
//Set the mapping mode to LOENGLISH
//
pDC->SetMapMode(MM_LOENGLISH);
//
//Convert arguments to coordinates to MM_LOENGLISH units.
//
CSize szTemp;
szTemp.cx = pDoc->GetGridX();//get the left of the rect to be drawn
szTemp.cy = pDoc->GetGridY();//get the bottom of the same rect
pDC->DPtoLP(&szTemp);
//
//Draw the size preview
//
CRect rect( 10, -10, szTemp.cx, -szTemp.cy );
pDC->Rectangle(rect);
--------------------------------------------------------------------------------
now after the rect is draw..i want to do the following:
given a point say 20,20.....so every time i get i point i make it into a rect and color it say red...
so if i get a point 20, 20
i amke arect
20,-20,21,-21
works fine now...but io ahve one doubt...
where should i do this this calculation???in the OnUpdate?
in the DOC?make my own fn in a view and put it there?
the point i get from which i am supposed to make the small rect comes from DOC.
so from doc where should i go to do this calulation???
code:
--------------------------------------------------------------------------------
CRect rect(x,-y,x+1,-(y+1));
pDC->Rectangle(rect);
pDC->FillRect(rect, &brush);
UpdateAllViews(NULL,.....);
--------------------------------------------------------------------------------
if i do this in doc..how do i get the DC????
please help...tks a lot...
can i get the dc like this
CClient dc(this);
will this dc be the dc of the view???
can i do the drtawiung using this dc that i make in doc???
tks a lot..really appreciate your time and help..
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
in the OnDraw of View call GetDocument to get the Document Pointer and access the Data that is required to Draw the Stuff
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
cannot do that...the data is not fixed..it keeps changing...something like the scribble applicaiton,,,
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
If ur drawing is based on constant User input
then have no choice but to do the calculations in the Drawing code itself
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
What you seem to want is where to store the rectangle information.
1) If more then 1 view needs the rectangle information, then store it in the document class and tell all views when the information has changed.
2) If only the current view needs the rectangle information, then store it in the view class.
Question: "if i do this in doc..how do i get the DC????"
Answer: The DC only matters when your are drawing the image, and it is given to you (if you are using MFC).
Question: "CClient dc(this);"
Answer: Yes! But you normaly do not need to (when using MFC), since it is given to you in the OnDraw() function.
Question: "will this dc be the dc of the view???"
Answer: If you are getting the DC in the view class, then yes.
Question: "can i do the drtawiung using this dc that i make in doc???"
Answer: Yes! But a document class does not know a DC from a hole in the ground. I wish I could say NO but if you try hard enough then the answer must be yes. (DO NOT DO THIS!)
INTP
|
|
|
|
|
How to know a toolbar button ID under the mouse!??
Best regards,
Eugene Pustovoyt
|
|
|
|
|
A quick look implies the following:
1) Use pToolBar = CToolBar::GetToolBarCtrl(); to get access to control
2) Use pToolBar->GetItemRect(); to find which item the mouse is over.
3) Now use pToolBar->GetItemID(); to get the ID.
Accept for all the typing (loops, ect..), it should be easy.
P.S. It would be easier if each button on an MFC toolbar was an indiviual window, but they are not. If this helps helps, send me your solution; if not write an article on your solution.
INTP
|
|
|
|
|
Good and how can I know a quantities of the toolbar button?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
What do you mean? Do you mean the number of items on the toolbar?
The base class of CToolBar is the CControlBar class and has a GetCount() member. If you have the display coordinates, then just loop through count items until you find an item rectangle (CToolBar::GetItemRect(nIndex, &Rect)) in which the cursor (also in display coordinates) is located. Now you should have the index of the toolbar item, call CToolBar::GetItemID(nIndex) to get ID.
INTP
|
|
|
|
|
Yes, I need to know the number of the items for the enumerate method.
Thank you, your answer was full!!!
Best regards,
Eugene Pustovoyt
|
|
|
|