|
Thx James, you dont seem to overlook anything. How do u do it? Of course the the unmanaged function has no clue to what it is returning its returned value to.
And I continue to slap myself repeatedly.....
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Thx James, you dont seem to overlook anything. How do u do it?
I have no real social life and I've worked with .NET since Beta 1; chances are that I've already had to think a lot of issues through at one time or another
Other times something just comes to me that seems to fit and makes sense when I think it through; such was the case here when returning values from unmanaged functions. In this case it was my 10 week long assembly course I took my first year of uni where we spent about 2 weeks on how the processor stores numbers (bitwise).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
How can I do Auto Tabbing on my Controls? Example on my Form I have two Text Box, reaching a specific length in first Text Box the focus automatically goes into the next Text Box.
Anybody HELP!
|
|
|
|
|
Easily
register keypress event, check the length of the textbox1's text and do textbox2.Select().
Sorry im a bit too lazy to write out the code
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
For an app that may or may not be run in the console (ie it can be run with a dlg interface or at the cmd prompt) how could one determine whether the app is running in the console or not in the entry point?
|
|
|
|
|
Nevermind... I didn't realize it was an either or situation. Really miss the allocconsole. Maybe we'll just have to import. That's disappointing.
|
|
|
|
|
Hi all again,
What type of resource can i embed into an assembly to use at runtime? Is it possible to embed (embedding works) a Win32 dll and use that dll directly from the embedded resources?
Also , how do you view what resources are in an assembly?
Any help will be appreciated.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Like Nnamdi said you can embed anything into the assembly
If you have VS.NET it is very easy to do; add the file to your project, then in its properties set Build Type to "Embedded Resource".
To get it back out is simple, if you know the name of the object (and yes it is possible to get all of the names)
Type type = typeof(MyClassFromAssemblyWithResources); ;P
Assembly asm = type.Assembly;
Stream stream = asm.GetManifestResourceStream(name);
Now to get the names of the resources use this bit of code (real simple )
Type type = typeof(MyClassFromAssemblyWithResources); ;P
Assembly asm = type.Assembly;
string [] names = asm.GetManifestResourceNames(); Done
Now, how is the name generated in VS.NET? First it takes the default namespace ("MyCompany.MyProduct"), then appends the names of any folders it is placed in within the project ("Resources"), finally it appends the filename of the resource ("MyResource.ext"). Given the above example the name would be MyCompany.MyProduct.Resources.MyResource.ext.
If you compile using the command line then you specify the name as the second argument to the /resource compiler switch.
I don't know how SharpDevelop derives its naming scheme.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
And you compiled using SharpDevelop?
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
yer. or maybe i did give it the namespace.class at the beginning - hmmmm i cant remember 100%, and i cant access at code cos im at work.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Thanx all
James T. Johnson wrote:
Type type = typeof(MyClassFromAssemblyWithResources);
Can I use any class from the assesmbly?
James T. Johnson wrote:
Stream stream = asm.GetManifestResourceStream(name); // Do something with the Stream
I just want to use the static functions in a Win32 dll, how? Do I load to memory? Im totally clueless.
In DllImportAttribute(string filename) , what do i say/do with filename here, do i have to write to file 1st?
Please help :
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Can I use any class from the assesmbly?
Yep
leppie wrote:
I just want to use the static functions in a Win32 dll, how? Do I load to memory? Im totally clueless.
That is where it gets tricky.
I think the easiest method would be to write it to a file (with the same name it had when you compiled), and hope that the DLL doesn't get loaded until the imported method executes [so the DLL will be written to file before then]. I think there is a slight problem. From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx James I will have a look
James T. Johnson wrote:
From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
Thanx for that bit of info.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I’ve been trying to figure out where to place some drawing code in my application. Sometimes, I want to paint OVER some controls slightly. If I place the custom painting code in the form’s Paint Event (even override OnPaint ) when the controls on the form are painted my custom paint job is overpainted by the controls. Is there someplace that I can do my painting AFTER the controls have been painted?
|
|
|
|
|
Im not so sure , but from what i understand is you need to draw to the Graphics object found at IntPtr.Zero. Look for more info, a couple days back.
IntPtr.Zero? u may ask. I read that that is allways the pointer to the current foreground window. So it all makes sense
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi leppie,
Actually passing IntPtr.Zero (i.e. null) to GetDC will return a handle to the screen. This is a fine solution (as suggested in a thread below by Li-kai Liu and AK) and this is what I am doing.
However, when I do this in the Form Paint event the Screen is painted fine, then the controls get painted and it erases what is drawn. So I’m left with my original Question:
Is there someplace that I can do my painting AFTER the controls have been painted?
Try this code out to see for yourself. Start a new project, place a button on the form. Then add the Form1_Paint event and place this code in that event:
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
IntPtr hdc = GetDC(IntPtr.Zero); // get hdc for the screen
Graphics g = Graphics.FromHdc(hdc);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y - 7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
//This should COVER the button but the control is redrawn over it
g.FillRegion(hatchBrush, region);
/////////////////////////////////////
//Place this code outside the paint event:
/////////////////////////////////////
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
|
|
|
|
|
You might want to try something like this:
void MyPaintMethod()
{
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
Graphics g = new Graphics.FromHwnd(this.Handle);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y -7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
g.Dispose();
}
I can't test this to see if it will work, but I am thinking this should be correct, thus you wouldn't need the DllImport portion.
HTH
Nick Parker
|
|
|
|
|
I didnt test it but it seems that all it would do is get the Graphics object to the form (i.e. your "this" = Form1). Then after this code is painted on the form the controls would be painted over it. Leaving me with the same problem.
I need to find a way to paint over the controls on the form. I simply dont know where to hook my code in.
|
|
|
|
|
|
Thanks Nick,
I took a look at these articles but they don't apply. I'm not trying to create a control. I need to draw over ANY control that is placed on my form.
|
|
|
|
|
It sounds like you need to have an otherwise invisible window on top of which to paint. This window can sit above all other controls, and it's painting won't be affected by the controls under it. This would only work under Win2k and above, though.
An uglier solution might be to attach event handlers to ALL of your child control's Paint events, so that you can repaint the screen whenever one of your child controls repaints itself. This will, however, lead to some unavoidable flicker...
--
Russell Morris
"Have you gone mad Frink? Put down that science pole!"
|
|
|
|
|
Hi all,
I have question about distributed application. I bought a book from Wrox, Professional C#.
And now, I am trying to work on one of the samples in chapter Distributed Application.
However, I got this error when I execute my client application:
"Trying to create a proxy to an unbound type."
Main purpose of the program is to create 2 small applications which execute a remote object
called Hello. It's using TCP as the channel. In both applications, I already put a reference to
remote object's namespace (DistributedApp1CL).
Server application has no problem at all, but client does. The error comes in this line:
Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8086/Hi");
Does anyone know what this error means?
|
|
|
|
|
maybe because "tcp://localhost:8086/Hi" is a reference to a folder, and not the file that it is supposed to create something with?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|