|
ekynox wrote: Maybe this person is writing in this manner intentionally just to annoy a few people on these forums
Without doubt. In fact, this is one way, I apprehend, these low profile creatures are staging a Denial of Service attacks. As we focus on such people, we can actually help other deserving ones right?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
I have created a visual C# windows application project with one form. I have removed the close x button by setting ControBox=False. Then if I use this.close() method to close the form I get error. It doesn't show any error message but shows dialog "application has top close...".
I was under the impression that it was happening due to Application.Run method. But can anyone please suggest a solution to this?
|
|
|
|
|
Do you have any other threads running ? this.Close() should work just fine.
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 )
|
|
|
|
|
No, I don't think so. It is a very simple application with 2 functions. Is there a way to figure out if any other thread is running?
Thanks.
|
|
|
|
|
harsha1305 wrote: Then if I use this.close()
Application.Exit();
led mike
|
|
|
|
|
*grin* I knew there was an Application. method, but couldn't recall. Does that do a hard close, or still post WM_CLOSE to all windows ?
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 )
|
|
|
|
|
Christian Graus wrote: Does that do a hard close, or still post WM_CLOSE to all windows ?
Who knows, it's .NET so it might all change from version to the next anyway! :-> At one point I do believe I read something that said it does stop all the threads in that process. But again that was some time ago so now, on what versions, I don't really know or probably care. When I care about those types of details I will fall back to C++ native development.
Like someone said the other day, C# is VB in wolfs clothing. I added, yes just like Delphi and Java. Really it's the .NET platform as opposed to the languages. When one of the main purposes of the platform is to hide the details of how stuff works from the developers it's difficult to remain interested in them. The platform is fine for many projects but not necessarily for any project.
I eat my peas with honey
I've done it all my life
It makes the peas taste funny
But it keeps them on my knife
led mike
|
|
|
|
|
It tells the message pumps to terminate and then closes the app windows.
|
|
|
|
|
I should Application.Exit() be called in main()? If so I tried it, but shows the same error.
|
|
|
|
|
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??
|
|
|
|