[.net] Handle to App
Is there anyway to get the handle to an app outside of the main class? I want to put my DirectInput stuff in a class by itself but SetCooperativeLevel needs the handle to the app. I know I could just do this.Handle in my main class and pass it through but I was hoping there was a cleaner solution then passing a variable through several classes.
It probably goes against the rules of encapsulation but I always have a class called Global that has a bunch of stuff I share between classes.
Then when I create the form I just make Global.Form point to it..
[Edited by - Headkaze on May 5, 2007 8:19:29 PM]
public class Global{ public static MainForm Form = null;}
Then when I create the form I just make Global.Form point to it..
using (Global.Form = new MainForm()){ ...}
[Edited by - Headkaze on May 5, 2007 8:19:29 PM]
If you're using WinForms or the WPF, there should be a static property along the lines of
Application.Current
Don't know why I didn't think about using a "Global", I already have a couple of others for things I need to share.
After I've created my OpenGL window I assign it to my global class and it works. This probably isn't the best way to do it, but I really don't want my MainWindow class creating the keyboard and joystick to have it used in my game loop class.
Headkaze, you forgot to give a variable name for Form.
After I've created my OpenGL window I assign it to my global class and it works. This probably isn't the best way to do it, but I really don't want my MainWindow class creating the keyboard and joystick to have it used in my game loop class.
Headkaze, you forgot to give a variable name for Form.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement