dll that grabs a window handle and then stops the window from redrawing?

jrdnoland

Member
Joined
May 15, 2016
Messages
9
Programming Experience
10+
I have a remote desktop application in which I want to make one of the windows to stop redrawing while it's loading and then to restart the drawing.

I was thinking a C# dll project would work but I'm having trouble finding a C# example of this API call.


C#:
 class DrawingControl

    {

        [DllImport("user32.dll")]

        public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);

   

        private const int WM_SETREDRAW = 11;

   

        public static void SuspendDrawing( Control parent )

        {

            SendMessage(parent.Handle, WM_SETREDRAW, false, 0);

        }

   

        public static void ResumeDrawing( Control parent )

        {

            SendMessage(parent.Handle, WM_SETREDRAW, true, 0);

            parent.Refresh();

        }

    }

I don't have a real good understanding of using and making a .dll that can work in another application. I'm not 100% sure that this is even the correct API to do what I need. I would also like to find a tutorial, article, book that explains the whole process. That being, Find API, build c# .dll, use the dll in another app, etc.

I posted a similar question on Stack Overflow but they rejected my question without an explanation. So I'm going to try here.


Thanks,
Jeff
 
The code there assumes, if you'll pardon the pun, that you control the WinForms Control. Since you want to control another window's redrawing, then you will need to get the window handle for that window, and then pass that handle to SendMessage(). None of this requires having your code to be called by their code.
 
Now if you want to have your code running in their process space, you will have to learn how to do DLL injection. There are many articles on the ever since this stopped being a black hat technique, and have become, at best, a grey hat technique.

What will complicate things for you is the fact that you want to do this in C# instead of C or C++. Recall that unless you have the C# compiler option to generate native code all at once, C# is dependent on the .NET Framework. A process can only have one version of the Framework loaded and running. If the process you are trying to inject into already has a version of the framework loaded and running, your code has to use that exact same version.

All I can say is good luck with this endeavor. I would recommend using C or C++.
 
I have a remote desktop application
And for this last piece of the puzzle. Search through the Windows Terminal Services API. There might be something there which will at best give you a way to get a window handle from a remote machine and send messages to it, or at worst a way to ship your code from your machine to the remote machine.
 

Latest posts

Back
Top Bottom