|
I tried this.close() again and got system.objectdisposedexception exception. So I called this.dispose() before this.close(), but still the same exception. What is the proper code for closing the form?
Thanks.
|
|
|
|
|
That is the proper code for closing a form. You shouldn't be getting any error.
Try putting the 'X' back on and close your form, if you still get the error then you can be absolutely certain that it has nothing to do with your closing code.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
If closing the form is to end the application you could use:
Application.Exit();
|
|
|
|
|
I get the error on the static constructor.
<code>using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using JCollections.Maps;
namespace TANK_2
{
class Images
{
public const int IMAGE_WIDTH = 18;
public const int IMAGE_HEIGHT = 18;
public static HashMap<Tank.Direction, Bitmap>; AI_TANKS;
public static HashMap<Tank.Direction, Bitmap> USER_TANKS;
public static Bitmap WALL = TANK_2.Resources.wall;
public static Bitmap ROAD = TANK_2.Resources.road;
public static Bitmap LOGO = TANK_2.Resources.logo;
public static Images()
{
TANK_2.Images.AI_TANKS = new HashMap<Tank.Direction, Bitmap>(4);
TANK_2.Images.AI_TANKS.Add(Tank.Direction.Left, TANK_2.Resources.ai_tank_left);
TANK_2.Images.AI_TANKS.Add(Tank.Direction.Right, TANK_2.Resources.ai_tank_right);
TANK_2.Images.AI_TANKS.Add(Tank.Direction.Up, TANK_2.Resources.ai_tank_up);
TANK_2.Images.AI_TANKS.Add(Tank.Direction.Down, TANK_2.Resources.ai_tank_down);
TANK_2.Images.USER_TANKS = new HashMap<Tank.Direction, Bitmap>(4);
TANK_2.Images.USER_TANKS.Add(Tank.Direction.Left, TANK_2.Resources.user_tank_left);
TANK_2.Images.USER_TANKS.Add(Tank.Direction.Right, TANK_2.Resources.user_tank_right);
TANK_2.Images.USER_TANKS.Add(Tank.Direction.Up, TANK_2.Resources.user_tank_up);
TANK_2.Images.USER_TANKS.Add(Tank.Direction.Down, TANK_2.Resources.user_tank_down);
}
}
}
</code>
I have an enum in the Tank class which has four things in it (I don't know the right term): Left, Up, Right and Down. Using the HashMap class which I made I have each enum thing point to a specific image. I'll probably figure it out after I click "Post Message".
|
|
|
|
|
Jordanwb wrote: access modifiers are not allowed on static constructors
Sender: Jordanwb
Jordanwb wrote: public static Images()
public is an access modifier. Access modifiers are not allowed on static constructors. So......
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ahh. I see okay. That works. It's always something small for whenever I get a problem.
Thanks.
|
|
|
|
|
*grin* I know just what you mean.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
i have sample code like this:
public class Service1 : System.Web.Services.WebService<br />
{<br />
[WebMethod]<br />
public string HelloWorld()<br />
{<br />
string ble = testowySingleton.Polaczenie;<br />
return ble;<br />
}<br />
}<br />
public static class testowySingleton<br />
{<br />
public static string Polaczenie<br />
{<br />
get<br />
{<br />
lock (connectionlock)<br />
{<br />
if (_polaczenie == null)<br />
{<br />
_polaczenie = "";<br />
<br />
}<br />
else<br />
{<br />
_polaczenie += "a";<br />
}<br />
return _polaczenie;<br />
}<br />
}<br />
}<br />
private static string _polaczenie = null;<br />
private static readonly object connectionlock = new object();<br />
}
How i can get one instance per client not one for all clients?
Any idea? And im wonder when this object will be destroyed...
Greetings
|
|
|
|
|
yarns wrote: How i can get one instance per client
They hide that information in the documentation[^]
led mike
|
|
|
|
|
Thank you
Greetings
|
|
|
|
|
Good day
I'm making a backgroundprocess that works as an addon for programs that actually don't support addons. It uses GDI+, and a global keyboard hook, to make the addon work. Now my problem is that I don't really know how to make my render loop. Normally I'd do something that interacts with Application.Idle, and keep on checking if the application is idle by using the Win32 API function PeekMessage and things, but that's when I want a render loop for my own program.
Now I actually have to decide when to render for another program. And I don't think I can retrieve in any way when should be the best moment to render for another program. It's not an application though, it's a game, so it has a continuous render loop. So maybe I can just decide for myself when to render? But how would I do that? I never actually really made a good render loop. When I made a game it was the XNA Framework doing it, and if I made an application with a render window or so, it was with the Application.Idle etc.
Thanks in advance.
|
|
|
|
|
Depending on how the other game draws itself, you're probably wasting your time. If the other game redraws itself continuously, as do just about every DirectX game out there, then anything you draw on the target form will immediately be overdrawn by the game. At best, your code will have to draw its stuff at the same framerate as the game is drawing (which is usually variable!), and you'll still end up with a horrible flicker that you can't get rid of.
Why? Because your code has no access to the drawing buffer in the game. What you see is two buffers, one is visible that the player see, and the other is behind the scenes, being used to draw the next frame. What that frame is complete, the "pages" are flipped. The newly rendered frame is drawn to the screen and the old buffer is used to render the next frame.
|
|
|
|
|
I see, is there a way to bypass that? A window on top of a game window hides the displaying of that piece of the screen drawing, obviously without flickering (because of the z-layering of Windows itself or so). Can I in some way make draw my screen on top of the game instead of in the same window? Then the screen has to be transparent of course, and because the specific regions that are overdrawn by me, overlap the drawing of the game, Windows will automatically disable that region (as it would do with a normal window on top of another normal window), and no flickering would appear. Still the user has to be able to have the game window itself as the active window, so I'd have to make my semi-transparent window an always-on-top window or so.
I could draw to a zero pointer (IntPtr.Zero), which makes it the most upper layer (thus the whole screen, ignoring other windows). Still I noticed this flickers. =/
Do you think my idea is worth a try? If yes, how would I do that? Or is it impossible to have some decent drawing in/on a game window by a third party program anyway?
Thanks in advance
|
|
|
|
|
Jitse wrote: is there a way to bypass that?
You're kidding, right?
Jitse wrote: A window on top of a game window hides the displaying of that piece of the screen drawing, obviously without flickering (because of the z-layering of Windows itself or so).
This doesn't work the way you think it does. The last process to write to a piece of screen real-estate is the winner, even with "transparent" windows. There are no "layers" in GDI or GDI+. The best you're going to be able to do is draw a small window covering just what you want, but you will not be able to "see through it".
|
|
|
|
|
Quote: "The best you're going to be able to do is draw a small window covering just what you want, but you will not be able to "see through it"." - By Dave Kreskowiak
Seems you were wrong.
Credit goes to Rui Godinho Lopes. This is the most important piece of code, works with with the user32.dll UpdateLayeredWindow function. Link is at the bottom.
<br />
public void SetBitmap(Bitmap bitmap)<br />
{<br />
IntPtr screenDC = Win32.GetDC(IntPtr.Zero);<br />
IntPtr memoryDC = Win32.CreateCompatibleDC(screenDC);<br />
<br />
IntPtr gdiBitmap = IntPtr.Zero;<br />
IntPtr emptyBitmap = IntPtr.Zero;<br />
<br />
try<br />
{<br />
gdiBitmap = bitmap.GetHbitmap();<br />
emptyBitmap = Win32.SelectObject(memoryDC, gdiBitmap);<br />
<br />
Win32.Point pointSource = new Win32.Point(0, 0);<br />
Win32.Point topPos = new Win32.Point(_form.Left, _form.Top);<br />
Win32.Size size = new Win32.Size(bitmap.Width, bitmap.Height);<br />
Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();<br />
blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA;<br />
blendFunc.BlendFlags = 0;<br />
blendFunc.BlendOp = Win32.AC_SRC_OVER;<br />
blendFunc.SourceConstantAlpha = 255;
<br />
Win32.UpdateLayeredWindow(<br />
_form.Handle,<br />
screenDC,<br />
ref topPos,<br />
ref size,<br />
memoryDC,<br />
ref pointSource,<br />
0,<br />
ref blendFunc,<br />
Win32.ULW_ALPHA);<br />
}<br />
finally<br />
{<br />
Win32.ReleaseDC(IntPtr.Zero, screenDC);<br />
if (gdiBitmap != IntPtr.Zero)<br />
{<br />
Win32.SelectObject(memoryDC, emptyBitmap);<br />
Win32.DeleteObject(gdiBitmap);<br />
}<br />
Win32.DeleteDC(memoryDC);<br />
}<br />
Here's the link: CodeProject: Per Pixel Alpha Blend in C#[^]
|
|
|
|
|
Jitse wrote: Seems you were wrong.
Credit goes to Rui Godinho Lopes. This is the most important piece of code, works with with the user32.dll UpdateLayeredWindow function. Link is at the bottom.
You haven't tried to cover a DirectX window with this yet, have you??
|
|
|
|
|
Dave Kreskowiak wrote: You haven't tried to cover a DirectX window with this yet, have you??
Was already wondering how I could ever know more than an MVP. I was thinking like: "Where's that catch I'm totally missing.".
Anyway, yes I did. And it works. Hmmmwell, it almost totally works. I've noticed something weird. I tested it with a few game windows, and they all worked perfectly. (If you want to know: Lord of the Rings Online, Pro Evolution Soccer 6, Tibia.) But! With this game called 'Tibia' (don't search it up, it's a horrible game), I can choose what API to render the game with in the advanced graphics options. You can choose two versions of DirectX, and OpenGL. The DirectX rendering works fine, but when I choose OpenGL the PNG images totally get overdrawn, and are not visible anymore.
This is weird though, why would it work with DirectX, but not with OpenGL...? Or is this just something about the game I tried?
Still, it does seem to work perfectly with the other game windows, there's 0% flickering. And the game I primarily want to make an addon for works as well.
|
|
|
|
|
Jitse wrote: Hmmmwell, it almost totally works.
You can't say I didn't warn you.
|
|
|
|
|
Dave Kreskowiak wrote: You can't say I didn't warn you.
My way works for any game I tried, except one little unknown game, and only when you choose OpenGL as its rendering. So actually it works very well. You were saying, "did you ever try it on an DirectX window", yes I did, with several games, and it all works perfect.
You don't seem to be able to explain me why it doesn't work for that one certain game when I choose OpenGL, but still works when I choose DirectX 8 or DirectX 5, or that it works with every other game I tried. Anyone else knows what's the reason for this?
|
|
|
|
|
I have an object that is several levels deep. It may or may not contain values in each level. I need to serialize the object as XML -- and yes, I would normally use XmlSerializer to accomplish this. The problem is that the application this is feeding requires an XML format that is not well-formed. The area in which it loses it's well-formedness (is that a word) is with arrays. That is also the area I'm having troubles getting my hands around.
I have my primary code which handles the parent and then creates instances of ObjectWalker and IEnumerableWalker to handle flat objects and arrays. Furthermore the arrays are only System.Collection.ArrayList. So I can specifically state that if property.DeclaringType.Name.Equals("ArrayList") then I know I have an array.
What I'd like to do is get the actual array object and pass it to my IEnumerableWalker, but it seems I cannot do that.
So I'm passing the PropertyInfo of the ArrayList, the object it is contained in, and the current Xml depth. What I cannot find on the internet or here is the next step of iterating through each element in the array and getting the property names and values.
If anyone can point me to a good article or snippet that does this I'd appreciate it!
Thanks
Here is my ObjectWalker that eventually calls an instance of IEnumerableWalker:
public void Walk(object newHierarchy, int depth)
{
Type objectType = newHierarchy.GetType();
XmlWriter.WriteOpen(objectType.Name);
PropertyInfo[] properties = objectType.GetProperties();
foreach (PropertyInfo property in properties)
{
Trace.WriteLine("Processing property" + property.Name);
if (property.DeclaringType.Name.Equals("ArrayList"))
{
new IEnumerableWalker().Walk(property, newHierarchy, depth);
}
else if (property.PropertyType.FullName.StartsWith("MyNamespace"))
{
object itemValue = property.GetValue(newHierarchy, null);
new ObjectWalker().Walk(itemValue, depth+1);
}
else if (property.CanRead && property.CanWrite && property.GetValue(newHierarchy, null) != null )
{
XmlWriter.WriteLine(property.Name, property.GetValue(newHierarchy, null).ToString(), depth);
}
}
XmlWriter.WriteClose(objectType.Name);
}
|
|
|
|
|
i'm not sure if i got what you want.
for now, it seems as if you need to replace
new IEnumerableWalker().Walk(property, newHierarchy, depth);
with something like
foreach (object val in ((ArrayList)property.GetValue(newHierarchy, null)).Items)<br />
{<br />
Walk(val, depth);<br />
}
..or did i get you wrong?
|
|
|
|
|
Almost. But you helped me realize I'm closer than I thought. Seems my base object being passed to the ObjectWalker IS the array list.
So I have to step through and find out why it isn't going to the IEnumerableWalker.
I have the enumerable walker there because this is where the well-formed xml fails. Instead of xml like this:
<pre>
<Employees>
<Employee>
<EmployeeName />
</Employee>
<Employees>
</pre>
They have this
<Employee>
<EmployeeName />
<Employee>
<EmployeeName />
So my IEnumerable object writes all contents of the array but does not create the parent root node of the Array.
really sucks. Don't know how those idiots that wrote the system handle the xml to begin with.
|
|
|
|
|
in this case, i'd consider generating the ouput like
<employees flagArray="true">
<employee>
<employeename />
</employee>
</employees>
and processing xslt transformation later to replace the well-formed array serialisation with desired format.
|
|
|
|
|
It was considered but I did not care to screw around with XSLT. Horrible stuff, IMHO.
But I did get the XmlSerializer working as I needed it. It was just finding where to look to determine the base class of the object. Once I got past that, the rest just flew. It left me with enough time to add the necessary logic to get the attributes, determine if there is an XmlElementAttribute and get the necessary element name. But you post got me headed in the right direction.
Turns out that my problem was caused because I fell into the wrong logic path with the ArrayList. That was due to not looking at the right place for the base object type.
All working. All done.
Thanks for your indirect help.
|
|
|
|
|
in the .NET IDE when you right click on a variable and choose quick watch and it says:
"error: identifier <identifiers name> out of scope "
what does this mean
and how can i resolve this issue?
thanks
robust
|
|
|
|
|