Creating Win32 Windows in C# for games
A little background on the problem. .NET does not provide an easy way to Create Windows or Call Win32 functions. So as a programmer, you have to import dlls and define the interfaces which is a painstaking process.
The examples on the net show you how to get a msgbox working (woohoo!) Unfortunately creating a window takes a lot more than that.
So far I know RegisterClassExA is working correctly because it gives me a valid hInstance.
When CreateWindowExA is called it creates the window, but doesn't return a proper Window Handle. I know it is called because the callback function is called several times which outputs messages to the console.
I need to know why the valid handle is not being returned.
FindWindowExA can't get a handle to the window either.
I found a good resource on hooks, but is it really necessary to create a Win32 window in C#? The messagebox doesn't need it...
http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/
I have bundled the project files, so you can easily see what's going on with CreateWindowEx.
http://www.tagenigma.com/qa/CSharp.Win32.zip
Any suggestions?
~Tim (tgraupmann@yahoo.com
I'm trying to avoid windows.forms. for sake of simplicity ha!
[Edited by - tgraupmann on July 5, 2004 3:30:55 PM]
*News tagenigma.com is my new domain.
I'm not a windows guys, so I can't help you with something like winforms, but
if all you're trying to do is create the window, wouldn't SDL.NET or Tao (another SDL C# wrapper w/ OPenGL and other thigngs, too) work nicely? without using windows specific stuff that you can't seem to get working?
if all you're trying to do is create the window, wouldn't SDL.NET or Tao (another SDL C# wrapper w/ OPenGL and other thigngs, too) work nicely? without using windows specific stuff that you can't seem to get working?
Oh the cool part is you can see the new Window calling the call back function but you can't get a handle to the window. It's all very strange but cool.
For a game once this works, is you switch the application type from console to application and then your game is ready to go.
To debug your game, you can use Console.Writeline until you make the easy switch.
For a game once this works, is you switch the application type from console to application and then your game is ready to go.
To debug your game, you can use Console.Writeline until you make the easy switch.
*News tagenigma.com is my new domain.
Quote: Original post by C-Junkie
I'm not a windows guys, so I can't help you with something like winforms, but
if all you're trying to do is create the window, wouldn't SDL.NET or Tao (another SDL C# wrapper w/ OPenGL and other thigngs, too) work nicely? without using windows specific stuff that you can't seem to get working?
We'll if I keep it Win32 specific it will work with the Mono Native DLLs too. So that takes care of Windows and Linux. 1% of games are sold for the Mac. So that should cover it.
*News tagenigma.com is my new domain.
- Christoph---Hypotenubel.net Big Words Without Meaning | Jaic Wain The IRC client that never gets oldFlat Crap Not pushing 2D graphics to its limits | TWLog Keeping the world under surveillance
Do yourself a favour and use the inbuilt stuff :)
Here's a simple game loop.
I've written a tutorial about using c# to make a Direct3D 2D tile game, i'm not sure how much useful it would be in general. I don't think my writing style is concise enough but it assumes very little of the reader (I was writing it for myself so after a few months of not looking at my code, i could know exactly what I was doing and how I had gone about doing it). I may submit it, but I don't really have time to proof read it as I'm leaving the country soon.
Here's a simple game loop.
using System;using System.Windows.Forms;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D; public class example : Form { Device device = null; static void Main() { example form = new example(); form.Show(); while (form.Created) { form.Render(); //Where we tell our 'device' what to do! Application.DoEvents(); //Let the OS handle what it needs to } } private void Render() { if (device == null) return; } }
I've written a tutorial about using c# to make a Direct3D 2D tile game, i'm not sure how much useful it would be in general. I don't think my writing style is concise enough but it assumes very little of the reader (I was writing it for myself so after a few months of not looking at my code, i could know exactly what I was doing and how I had gone about doing it). I may submit it, but I don't really have time to proof read it as I'm leaving the country soon.
I'm writing a book about How To Make An RPG, check it out! | Blog
Quote: Original post by Balaamwhile (form.Created) { form.Render(); //Where we tell our 'device' what to do! Application.DoEvents(); //Let the OS handle what it needs to }
Why this render loop is wrong.
Some possible alternatives. Miller's "Kickstart" book uses the first alternative, so that's what I've been using as well.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Thanks for the heads up!
The first alternative he gives seems the easiest to implement, so I guess I will go with that one too when I next starting tinkering with my code.
The first alternative he gives seems the easiest to implement, so I guess I will go with that one too when I next starting tinkering with my code.
I'm writing a book about How To Make An RPG, check it out! | Blog
Got it working. The create message was just getting stuck. Here is the solution, if you are interested in doing OpenGL in C# using Win32.
http://www.tagenigma.com/qa/CSharp.Win32-3.zip
http://www.tagenigma.com/qa/CSharp.Win32-3.zip
*News tagenigma.com is my new domain.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement