Adding a menu in another program
Hello everyone.
In a java game (Minecraft) I want to add a server menu containing chat admin server commands. I already worked out everything required to send the keys (sendmessage WM_KEYDOWN) and to simulate mouse clicks. The only problem I have is a nice gui.
I already tried a topmost transparant window, but it has one large problem: focus change causes the background game window to lose focus, and thus open the game menu. I somewhat fixed this by sending focus/activate messages to the game window, but this causes the game to go fullscreen on 64 bit machines. (for some reason)
Then I thought of painting my controls ontop of the window, but I would still have to handle mouse movement which is not (easily) possible at that point. Is there any way to add a control to another window (with the coding) or set up some sort of Window hook to handle the events?
The final goal is a simple overlay which is clickable as if it is part of the game.
I do not have to read any information from the parent window, only have to add a Windows Forms control to it. Since java is different from .NET I doubt adding the control is even possible...
I know window hooking is a sensitive subject at these forums, if what I want to do is not allowed using hooking then hooking is not an option, and all I would have to know then is how to add my own control as child to another (window) handle.
Re: Adding a menu in another program
I am not sure but have you searched if you can use the APIs GetMenu and InsertMenuItem?
Re: Adding a menu in another program
A veeeeeeery old unresolved (:() thread of mine: http://www.vbforums.com/showthread.php?t=376337
See my code in the 1st post. It will show you how to add menu item to external program using Moeur's HookControl OCX.
Re: Adding a menu in another program
Thanks I'll look into it.
Not sure about changing the items' colour; you'd need the header declaration and API's for the context menu then. May be this link can *somewhat* help you with that...too complicated for em though...
http://msdn.microsoft.com/en-us/library/bb776881%28v=VS.85%29.aspx
EDIT
Wow can't believe it actually worked. This test code simply did what I wanted...
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim w As New Window("Minecraft")
w = w.Children.Last
With HookControl
.AddMessage(API.WM.msg.LBUTTONDOWN, "WM_LBUTTONDOWN")
.TargethWnd = w.Handle
MsgBox("Success: " & .SetHook)
End With
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Removed all hooks: " & HookControl.RemoveAllHooks)
End Sub
Private Sub HookControl_PostedMessage(ByVal sender As System.Object, ByVal e As AxHookCtrl.__HookControl_PostedMessageEvent) Handles HookControl.PostedMessage
Dim Msg
'display the messages as they arrive
For Each Msg In HookControl.Messages
If e.uMsg = Msg.Value Then
Debug.Print("Posted: " & Msg.Label & " " & e.wParam)
Exit For
End If
Next
End Sub
End Class
Nicely posts when the left mouse button is clicked. I do wonder: any chance this 'API' will fail on a 64 bit system?
Re: Adding a menu in another program
Quote:
Originally Posted by
bergerkiller
Thanks for the link. But it is for shell extension context menus. Not exactly what I was looking for.
Quote:
Originally Posted by
bergerkiller
Nicely posts when the left mouse button is clicked. I do wonder: any chance this 'API' will fail on a 64 bit system?
I have no idea. If it failes, try "x86" setting instead of "Any Cpu".
Edit: Sorry. I forgot it is in VB6 forum. :p I have no idea if this will work with x64.
Re: Adding a menu in another program
Afraid it did not work on 64 bit systems. It failed to bind the DLL and OCX DirectX control to the program, giving a crash report on startup. Since I can't compile older c++ projects, and I don't know how to compile to 64 bit on a 32 bit system, I can't get to a 64 bit DLL...
That is what my problem was with these types of DLL's...they don't work on both platforms. I'll see if I can add a VB .NET menu control...