Answered How to Close Graphics Window? (Drawing.Graphics)

rex64

Member
Joined
Jul 31, 2020
Messages
15
Programming Experience
10+
I am trying to figure out how to leave the class initialized but to return the code back to the calling function. I am calling a Drawing.Graphics window from a WinForms form.


I tried a few of these 1 at a time but they did not help:
C#:
    _window.Dispose();
    System.Windows.Forms.Application.ExitThread();
    System.Environment.Exit(Convert.ToInt32(unlockedPopup));
    return -1;



    #region Assembly GameOverlay, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null
    // C:\Users\Jeff\Documents\Visual Studio 2010\Projects\StudyxMain\StudyxMain\packages\GameOverlay.Net.4.3.0\lib\net45\GameOverlay.dll
    #endregion
  
    using System;
    using GameOverlay.Drawing;
  
    namespace GameOverlay.Windows
    {
        //
        // Summary:
        //     Represents an OverlayWindow which is used to draw at any given frame rate.
        public class GraphicsWindow : OverlayWindow
        {
            //
            // Summary:
            //     Initializes a new GraphicsWindow.
            //
            // Parameters:
            //   device:
            //     Optionally specify a Graphics device to use.
            public GraphicsWindow(Graphics device = null);
            //
            // Summary:
            //     Initializes a new GraphicsWindow with the specified window position and size.
            //
            // Parameters:
            //   x:
            //     The window position on the X-Axis.
            //
            //   y:
            //     The window position on the Y-Axis.
            //
            //   width:
            //     The width of the window.
            //
            //   height:
            //     The height of the window.
            //
            //   device:
            //     Optionally specify a Graphics device to use.
            public GraphicsWindow(int x, int y, int width, int height, Graphics device = null);
  
            //
            // Summary:
            //     Allows an object to try to free resources and perform other cleanup operations
            //     before it is reclaimed by garbage collection.
            ~GraphicsWindow();
  
            //
            // Summary:
            //     Gets or sets a Boolean which determines whether this instance is running.
            public bool IsRunning { get; set; }
            //
            // Summary:
            //     Gets or sets a Boolean which determines whether this instance is paused.
            public bool IsPaused { get; set; }
            //
            // Summary:
            //     Gets or sets the used Graphics surface.
            public Graphics Graphics { get; }
            //
            // Summary:
            //     Gets or sets the frames per second (frame rate) at which this instance invokes
            //     its DrawGraphics event.
            public int FPS { get; set; }
  
            //
            // Summary:
            //     Fires when you should free any resources used for drawing with this instance.
            public event EventHandler<DestroyGraphicsEventArgs> DestroyGraphics;
            //
            // Summary:
            //     Fires when a new Scene / frame needs to be rendered.
            public event EventHandler<DrawGraphicsEventArgs> DrawGraphics;
            //
            // Summary:
            //     Fires when you should allocate any resources you use to draw using this instance.
            public event EventHandler<SetupGraphicsEventArgs> SetupGraphics;
  
            //
            public override void Create();
            //
            public override void Join();
            //
            // Summary:
            //     Pauses the graphics thread.
            public void Pause();
            //
            // Summary:
            //     Resumes the graphics thread.
            public void Unpause();
            //
            // Summary:
            //     Releases all resources used by this GraphicsWindow.
            //
            // Parameters:
            //   disposing:
            //     A Boolean value indicating whether this is called from the destructor.
            protected override void Dispose(bool disposing);
            //
            // Summary:
            //     Gets called when the graphics thread destorys the Graphics surface.
            //
            // Parameters:
            //   graphics:
            //     A Graphics surface.
            protected virtual void OnDestroyGraphics(Graphics graphics);
            //
            // Summary:
            //     Gets called when the graphics thread needs to render a new Scene / frame.
            //
            // Parameters:
            //   frameCount:
            //     The number of the currently rendered frame. Starting at 1.
            //
            //   frameTime:
            //     The current time in milliseconds.
            //
            //   deltaTime:
            //     The elapsed time in milliseconds since the last frame.
            protected virtual void OnDrawGraphics(int frameCount, long frameTime, long deltaTime);
            //
            // Summary:
            //     Gets called when the graphics thread setups the Graphics surface.
            //
            // Parameters:
            //   graphics:
            //     A Graphics surface.
            protected virtual void OnSetupGraphics(Graphics graphics);
            //
            protected override void OnSizeChanged(int width, int height);
            //
            protected override void OnVisibilityChanged(bool isVisible);
        }
    }


    using System;
    using System.Collections.Generic;
    using System.Text;
  
    using GameOverlay.Drawing;
    using GameOverlay.Windows;
  
     namespace StudyCSharp
    {
        public class OverlayQuestion : IDisposable
        {
            private readonly GraphicsWindow _window;
  
  
     public OverlayQuestion()
            {
                StudyX.Module1.initializeModule1();
  
                _brushes = new Dictionary<string, SolidBrush>();
                _fonts = new Dictionary<string, Font>();
                _images = new Dictionary<string, Image>();
  
                generateStudyQuestion();
              
  
  
  
  
                var gfx = new Graphics()
                {
                    MeasureFPS = true,
                    PerPrimitiveAntiAliasing = true,
                    TextAntiAliasing = true
                };
  
                int _ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
                int _ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  
                _window = new GraphicsWindow(0, 0, _ScreenWidth, _ScreenHeight, gfx)
                {
                    FPS = 60,
                    IsTopmost = true,
                    IsVisible = true
                };
  
                _window.DestroyGraphics += _window_DestroyGraphics;
                _window.DrawGraphics += _window_DrawGraphics;
                _window.SetupGraphics += _window_SetupGraphics;
            }
    }
 
I just tried the Example and calling Dispose on the Example instance closes the overlay right away. One thing to note in the example is the call to _window.Join() in Run method. If you do something like this in a GUI application you must call Run in separate thread, in GUI application the Join call is also not necessary. Remember this is just something that draw on top of everything in screen, your own GUI application is supposed to remain responsive the whole time. The _window.Create method does create a new background thread, so that is not something to worry about.
 
I just tried the Example and calling Dispose on the Example instance closes the overlay right away. One thing to note in the example is the call to _window.Join() in Run method. If you do something like this in a GUI application you must call Run in separate thread, in GUI application the Join call is also not necessary. Remember this is just something that draw on top of everything in screen, your own GUI application is supposed to remain responsive the whole time. The _window.Create method does create a new background thread, so that is not something to worry about.
That seems like it freed up control when I commented out the join, thanks for your help!
 
1. "Steam or Origin...": Yes, a similar to their overlay interface
So its a similar interface but not a program like Steam, Origin or Xfire? So you're building a cheat or a game hack? That's what I take from that reply. Further, If any legitimate developer was making a program for users to use in a legitimate application, they would first take what I said below as a priority to ensure they don't get any of their users banned by anti cheat engines. Clearly you don't care about the reputation your application will generate when users start getting banned for using it. I'll also state that this is is not how Steam and other DRM software do it, and as I said, you will likely end up with any submission you send to anti-cheat companies blacklisting your application. The fact that this doesn't resonate with you, confirms and reinforces my suspicions.

And why are you going around the houses for this anyway? If you were building a legitimate DRM application. You are using a library which is dependent on another library sharpdx/SharpDX (which is also no longer supported). Moreover, its more or less a wrapper around directx dlls. Why not just use the directX dll's and OpenGL libs instead? You're increasing your odds of getting your users banned with this approach. As i said :
That's going about it the wrong way. Use directX and OpenGL for non-directX compliant games. You should also note and account for how you are going to get a handle on your game window and hook it and then inject into that process without triggering anti cheat engines from banning your users, and also permanently banning your application. I advise submitting your app for review to all AntiCheat organisations to prevent this.

I used to work with Glen from PunkBuster, amongst others so I am very well acquainted and familiar with the process to follow, and people in this industry. That said, your application is unlikely to be accepted. Hubs such as PBBans may also still ban users of your application. Streaming hubs like there's are not run by Punkbuster and they operate on their own rules and policies and also hold their own ban lists. Take that as a warning and research best practices for successfully interacting or injecting into game windows. Shouldn't you know this as a lead developer of Epic Games?
Why does this not spark your attention unless you are writing a game engine cheat?
I am the author of my code, not his code.
For the record, when you use someone else's library. You are not using your own code, you are in fact using someone else's code which you clearly copied from Github. That doesn't make you the author of the code.
 
So many misunderstandings in this thread lol :ROFLMAO:

In case you copied the project locally and compiled it yourself that is not necessary, all you need to do is to add the nuget package (VS: Project > Manage Nuget Packages) and the libaray is ready to use.
 
but I do appreciate the help even if it is critical. Anyways, we are not using this for cheating. We are using the overlay for educational purposes. I like the idea of submitting this to some of the anti cheat systems. Send me a list. Most of the anti-cheat systems will take a screenshot and a human will analyze the result when they see a new application that changes the GUI. In our case we will be the opposite of an anti cheat. Players will have reduced performance in game but better performance in education.

List of Anti Cheat:
Valve VAC
Punkbuster
FairFight (EA?)
EAC Easy Anti-Cheat

Proof of our project:
 
Last edited by a moderator:
For the record, when you use someone else's library. You are not using your own code, you are in fact using someone else's code which you clearly copied from Github. That doesn't make you the author of the code.
By your definition Michel Pi would not be the author of his code either because he used SlimDX. And SlimDX would not be author of their code because they used DirectX. Even Bill Gates is probably not the author of his code because he bought QDOS July 27 is a momentous day in Microsoft history — here's why
 
Congratulations you found out how to post a steam page via the dev store on Steam. That doesn't prove anything. What type of keys are you trying to store? I assume you are tying to acquire users game key codes?
Steam don't allow that through their API. By you advertising a program which likely circumvents this protection of users game key codes. I am sure it is against Steams terms of service. If you are providing your own keys for games provided by your application, then that's Ok. Once again, I'm trying to guide you, so that you do what you're doing correctly.

By your definition Michel Pi would not be the author of his code either because he used SlimDX. And SlimDX would not be author of their code because they used DirectX. Even Bill Gates is probably not the author of his code because he bought QDOS July 27 is a momentous day in Microsoft history — here's why

First. Don't try to be funny by being a smart arse posting rhetorical statements. I've been nothing but helpful by providing you with additional answers about how you should go about your app creation, while I also questioned you about your product too. And you chose not to engage with me once on any of my suggestions.

Secondly. You know exactly what you were claiming. It's clearly written in earlier posts where you said you were the author of the code, which also means to assume that you wrote the documentation also. Michel didn't claim to be the author of the libraries he used, did he?

Thirdly. If you don't state clearly the intentions of your project, and its purpose of use, then you will be questioned so we ascertain what basis and purpose your application serves. You could have avoided such questions had you been more forthcoming with your answers to the questions I first asked on the first page, instead of responding with shady one liners which leave more questions...

Lastly, if you come back and accuse me of attacking you again, I will ban you from the forum. Please keep your assertions to yourself. (Now removed)

If you don't want your project/character ridiculed, or scrutinised, then don't post on a public forum claiming to be someone you are not. If any person on this board had concerns about your project, it is there right to question you about your project until they are satisfied your project is not going to cause other people loss or harm. If you can not respect that, then find another forum who support those types of activities without question.
 
Back
Top Bottom