Resolved Interactable graphics draw over a different process window

sbondo1234

Member
Joined
Jan 21, 2020
Messages
8
Programming Experience
1-3
My main goal is to be able to move a window that doesn't have borders, the window is for a different process that wasn't made with the same c# script. If this is the wrong way to go about it please tell.

Is it possible to draw graphics over a different processes window that is interactable?

When I say interactable I mainly mean that the user is able to move the window around by using the drawn graphics.

Edit (Found some code that kind of helps):

This code keeps drawing a box onto the desktop:

C#:
[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);

while (true)
{
    IntPtr desktopPtr = GetDC(IntPtr.Zero);
    Graphics g = Graphics.FromHdc(desktopPtr);

    SolidBrush b = new SolidBrush(Color.Red);
    g.FillRectangle(b, new Rectangle(0, 0, 192, 108));

    g.Dispose();
    ReleaseDC(IntPtr.Zero, desktopPtr);
}

Is there a way to make it draw over a window, instead of just directly onto the desktop?

More importantly, is there a way to check if the user click/drags on the graphic and then call another function when that happens?
 
Last edited:
I've never drawn outside my own app but GDI+ is just pixels on the screen. There are no objects to interact with. I did write some code that allowed a user to drag GDI+ drawing around but that relied on events raised by the object it was drawn on. If you can't get feedback from the other app about mouse interactions then you're out of luck but, if you can, the drawing may be no value in the first place.
 
I've never drawn outside my own app but GDI+ is just pixels on the screen. There are no objects to interact with. I did write some code that allowed a user to drag GDI+ drawing around but that relied on events raised by the object it was drawn on. If you can't get feedback from the other app about mouse interactions then you're out of luck but, if you can, the drawing may be no value in the first place.
Alright, thanks. I might look into events to check where the user's mouse is dragging.
 
Is it possible to draw graphics over a different processes window that is interactable?
For what reason would you want to do that? Even though its highly unlikely going to be any use to you at all.
When I say interactable I mainly mean that the user is able to move the window around by using the drawn graphics.
I don't think that is possible. Nor would that work on it's own. You will likely need to call on pinvoke at some point, and to actually achieve what you're trying to do is likely going to require a whole new application.
I might look into events to check where the user's mouse is dragging.
It's not the events you need to be looking at. Focus instead on the pinvoke calls you can make to acquire all the needed inputs such as mouse clicks mouse location, and set window position etc. They can all be looked up on pinvoke.net.
 
Together and using GDi, you could maybe draw objects on the screen and upon clicking these objects, it can move the window you acquired the handle of and place it wherever you want to put it. Looks like there might be some DLL injecting needed as well. And just so you know, its not the easiest of tasks to undertake with 1-3 years experience.
 
Together and using GDi, you could maybe draw objects on the screen and upon clicking these objects, it can move the window you acquired the handle of and place it wherever you want to put it. Looks like there might be some DLL injecting needed as well. And just so you know, its not the easiest of tasks to undertake with 1-3 years experience.

Ok, I have decided to just move the window in the code itself without an option to move it whilst the code is running.

Got help from this post: pinvoke.net: movewindow (user32)
 

Latest posts

Back
Top Bottom