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;
            }
    }
 
You can't exit out of Main() and expect the program to continue running. You'll need to keep the message pump running. Just following the standard WPF or WinForms project template and it'll lead you down the right direction.
 
How do I return code so it can resume the WinForms. My form is locked up.

1. am starting in WinForms
2. I have a form that calls the Drawing.Graphics window
3. I want to resume the code back on WinForms form.
 
I'm going to assume that based off the namespace, you are trying to build something on the lines of Steam or Origin? In which case, while it is possible to do what you might be aiming to do, its also very difficult. It also requires knowledge of directX. And from a performance point of view, you are starting with the wrong project type. WPF is how you should be going with this. Lastly, you should also note that you will need extensive knowledge using tasks or threading.

This is of course if I assume correctly, as to what it is I'm trying to ascertain what function your application is directed to serve.

How do I return code so it can resume the WinForms.
Wouldn't that be a question best directed at the author of the code? I assume you are using this : Namespace GameOverlay.Windows | GameOverlay.Net Documentation ?

Topic also cross posted here : How to Close C# Graphics Window (Drawing.Graphics - non-form) and has since been closed for no clarity.
 
I actually got everything working great, except sharing the data or returning when completed. I just need to figure out how to close or return back to the form. It seems like it should be very easy, just not sure how.
 
Wait... so you know how to do DirectX but don't know how basic Windows works? Something is very wrong with this picture...
 
I can't believe I am entertaining this...
I am the author, can you help me out?
Prove it?

Lets double back :
This link contains Constructors : Class GraphicsWindow | GameOverlay.Net Documentation
Method :
C#:
public GraphicsWindow(Graphics device = null)
Next :
C#:
            public GraphicsWindow(int x, int y, int width, int height, Graphics device = null);
Also taken from that page. And it so happens to match the exact code you have above :
public GraphicsWindow(Graphics device = null);
public GraphicsWindow(int x, int y, int width, int height, Graphics device = null);
I despise bullshit. So please don't bullshit me. If you are the author of that code, you would and should most definitely know how it works. Since this claim you are making means that you wrote the documentation for it. If you wrote the documentation for it, then why are you here asking for help?

None of what you wrote on post 5 explains to any one here trying to help you what you are returning, when what exactly completes? You come in mid sentence and talk like we are meant to know what that means. We don't.

On p/#4 I asked you a number of questions which you disregarded. So tell us how are we to understand or help you when we don't have all the facts and answers to some of the questions I put to you?
 
1. "Steam or Origin...": Yes, a similar to their overlay interface
2. WPF? : No, a DevExpress ExtraForm but I believe this is similar to WinForms
3. Function of application is to have an overlay on top of a Game
4. Wouldn't that be a question best directed at the author of the code? I am the author of my code
5. Yes, I am using this: I assume you are using this : Namespace GameOverlay.Windows | GameOverlay.Net Documentation ?
6. I posted a question here, but I thought you would know how to return focus easily: Exit and Return Focus · Issue #65 · michel-pi/GameOverlay.Net
 
  1. You're reinventing the wheel. It's already been done, so how do you plan on competing with the competition... Rhetorical question. If you want to stand up to the quality of their UI designs. Use WPF and nothing else. I'd expect Michel Dignard would know this.

  2. This won't cut it. No matter what way your overlay will be rendered, it will look choppy, botched and ugly. This is due to how Winforms is rendered. (I'm speaking from experience as I've developed apps like this in the past.) Michel Dignard would also know this...

  3. 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?

  4. How does the author of the documented code (YOU), manage to write documentation for your own overlay project and yet, not understand how your overlay works or know the correct steps involved which require working with directX and OpenGL libraries?

  5. Let me get this straight. You need help understanding a library you allegedly wrote the code and documentation for? You claim to be the author of that code. You do know the author of that code works for Epic Games and yet; you don't know the correct procedures to overlay a hooked window by acquiring its handle, and inject your form into a game screen? You post as Jeff and not as Michel Pi on Stackoverflow who might I add is Michel Dignard of Epic Games.
You're the lead developer who made Fortnite and you don't understand your own documentation? Please :LOL: do you take us for idiots?

This topic is on the verge of being permanently closed along with your account for impersonating a known developer of Epic Games, which you clearly are not.

I should also advise you that impersonating someone is unlawful. One of my contacts on linked in is acquainted with Michel. I'd be careful how you next reply, or you may be issued with a cease and desist notice.
 
Sorry for the confusion, I said multiple times I am the author of my code. Not his code. I am the CEO of another gaming / software company called PlazSoft and am pretty good at coding, ,but definitely need some help. That is why I posted on this form.
 
Back
Top Bottom