|
-
Oct 18th, 2001, 04:09 PM
#1
Intercepting Windows Messages
I have an application that send's messages to any Windows programs using HWND_BROADCAST.
I need to write a VB program that will read those messages (without having the focus). The second application don't need to have any visual interface with the user (like a service).
Any clues on how doing this ?
Thank's
ps.: I already created a VB program, but it can read messages only if my application has the focus.
-
Oct 18th, 2001, 10:43 PM
#2
This is called subclassing - here is an example I posted earlier today. IT shows trapping a single message. There are several hundresd that you can trap.
Code:
Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Const WM_RBUTTONUP = &H205
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_RBUTTONUP Then
' display your popup menu here
Exit Function ' since you only want your menu exit
' if you let the message thru, then the other menu
' will appear
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
-
Oct 18th, 2001, 10:44 PM
#3
I'm looking for the same kind of information... I would like to capture keyboard input with an app that is running in the background.
I should maybe explain why I playing around with this. After reading a few posts I would like to make it clear that I'm NOT try to use this to capture users keystrokes. (I'm an admin, I could just reset passwords if I need to ) I would like to be able to open a small screen/form on top of a game screen when a 'shortcut' key is hit. I have no idea if this is even possible cause I have 0 graphics experience, but theres only one way to find out. So I would like my app running in the background to capture this shortcut key...
crazy or what?
-
Oct 19th, 2001, 12:20 AM
#4
Found what I was looking for..
Now to learn some graphics...
-
Oct 19th, 2001, 10:32 AM
#5
New Member
Subclass doesn't work
The subclass method works when messages are sent to the handle of the subclassed object. The problem here is that broadcasted messages are sent to applications not windows or object.
When a message is broadcasted, windows sends a message to each running application and sets the hwnd parameter to the application hinstance value. So when an applicaition receives the message, since the destination is itself, the application doens't distribute the message to forms or objects.
What we need is a way to subclass an application not a form. And the setwindowlong doens't work for applications.
Any solution?
-
Oct 19th, 2001, 02:36 PM
#6
Broadcasted messages work perfectly fine for me. Which message are you having trouble with? Is it a custom message (via RegsiterWindowMessage).
-
Oct 19th, 2001, 04:50 PM
#7
New Member
Intercepting windows messages
The messages we use are string messages with RegisterWindowMessage. The problem is when the application doens't have the focus. Sometimes even when the application does have the focus it doens't receive the messages.
-
Oct 20th, 2001, 11:52 AM
#8
All windows should receive the message. I've worked in this area before and everything turned out OK.
Can you post an example of how you are retrieving the message?
-
Oct 20th, 2001, 01:18 PM
#9
Newbie q....
This is a pretty specific example, but is there a way to know if your in a menu screen or not in a game? I have a little app running in the background and will respond to a 'hot key' pressed at anytime. I would like to limit when that hotkey will actually work, hence knowing what screen I'm in with in the game.
I've been using SPY++ to watch a game window and from what I can tell, you can't really tell whats going on inside the window, just what is being sent to and from. Is there a way to know whats going on inside a window, if you are looking for something specific?
If it is possible, I'm sure its pretty advanced, but I would still like to get the idea or logic on how one would perform such a task...
-
Oct 21st, 2001, 10:29 AM
#10
What kind of game is it? If it's a game simple game where you are using basic windows controls like static, edit etc? Or is it made with DirectX? (where everything is drawn on the same window).
-
Oct 21st, 2001, 10:14 PM
#11
It would be used for a boughten game.... directx/opengl... full screen, its not in a 'window' at all... When I used Spy++, I was hoping to see something that might jump out at me when I would click on menu items in the game options. The only thing that I could see was that the left mouse button was clicked, but no indication of any messages being sent. Well, there was a 'user' message sent, but they all appeared to be the same no matter what item I clicked or where on the screen it was clicked...
In the last few days I have found a way to have my app open with the press of a desired key input, even when another program has focus... I used the rgn and setwindow api calls to open my window. It works exactly like I want it to when a game is in OpenGL, it pops up on the game screen over top of it with out going back to the desktop. I minimize it, and the game goes on, perfect... When the game is in Directx, it pops up, but goes to the desktop first (as if you were to hit Alt-Tab), bad... I'm still trying to find a way to get it to react the same way it does when I use it in OpenGL... so if anyone has any ideas about that, please feel free to help me out...
PS
Thanks for helping me out... I really appreciate it...
-
Oct 22nd, 2001, 11:05 AM
#12
Re: Intercepting Windows Messages
Originally posted by mictou
I have an application that send's messages to any Windows programs using HWND_BROADCAST.
I need to write a VB program that will read those messages (without having the focus). The second application don't need to have any visual interface with the user (like a service).
Any clues on how doing this ?
Thank's
ps.: I already created a VB program, but it can read messages only if my application has the focus.
Try putting ur app into system tray!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|