|
MSN, for example, uses COM plugins. You could write a component in C# (gets compiled to IL in an assembly module) that exposes a COM-Callable Wrapper, or CCW. See Nick's article, Creating a CCW for COM-enabled, non-.NET Applications[^]. You register this appropriately, which is defined in the MSN Messenger SDK on the MSN Messenger web site (if you can find the SDK - they moved it some time back).
Since regasm.exe that ships with the .NET Framework SDK only registers the necessary keys and you need to register additional keys so that you can register as an MSN plugin, you'll need to read about the ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute in the .NET Framework SDK.
For some applications, creating a CCW is the only way. You can also use P/Invoke to call native functions and pass them data. You could hook an application that exports the necessary hook functions as well.
There's lots of ways - provided that the application/library allows for it - and you can learn more by reading through the .NET Framework SDK, especially the section, Interoperating with Unmanaged Code[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am writing the chat program in LAN that is similar to the mIRC. When the user connect to server, it will activate the chat form that connected to server in port 9999, and when the user want to chat private, it will active the private chat form that connected to server in port 9998. In my program, I use the "privatechatform.ShowDialog()" to activate the private chat form, but it does not allow to chat in multi-users. but if I use the "privatechatform.Show()", my program is crashed. Please! Help me!!
|
|
|
|
|
What was the exception? What error happened? Where did it happen? What did the stack trace look like?
You need to provide more information if we are to help you. The most obvious thing is contention of resources. When you only have on chat session there is only one thing using one resource, when you have two or more chat windows open they are sharing the same resource.
When you use ShowDialog() dialog opens and as you see the application ignores the user in everything but the dialog. This is the correct behaviour. So, while this dialog is open other events are not firing. If you use Show() the application will continue to receive events. Perhaps some event in another part of the application is interfering with your dialog.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
I'm trying to put a picturebox on a form but I've already done showDialog on the form. I try to refresh the form but it doesn't do anything. The picturebox is already instantiated and I just want to a dd a picture to it at run time.
|
|
|
|
|
You didn't post any code or really explain exactly what the problem is, but this is how you would add a control at run-time:
PictureBox pb = new PictureBox();
pb.Image = Image.FromFile(fileName);
this.Controls.Add(pb);
If that doesn't solve your problem, you should post again, being more specific about what you need done and what you've got so far.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Yeah your probably right. This time I'll give code. I'm just a beginner but I'm working on a poker game and have a picturBox on my table that displays the players cards face down. I want to redraw this picture to show one card then a card on top of that card like if a person was dealt one card then another. I've got the two bitmaps that I want to interchange but if I use showdialog I get a little flicker before the other bitmap comes up.I can't have the flicker cause it has to look like it just appeared onscreen and not redraw form1.
this is my player class and under that is my main method where I use AddCard
public class Player : Form1
{
PictureBox bust = new PictureBox();
PictureBox playerCard1 = new PictureBox();
PictureBox playerCard2 = new PictureBox();
PictureBox tableCards = new PictureBox();
PictureBox tableChip = new PictureBox();
TextBox playerMoney = new TextBox();
TextBox betAmount = new TextBox();
PictureBox button = new PictureBox();
public Player()
{
}
public Player(int cardLoc1, int cardLoc2, int cardSize1, int cardSize2, Form1 surface)
{
this.tableCards.Location = new System.Drawing.Point(cardLoc1, cardLoc2);
this.tableCards.Size = new System.Drawing.Size(cardSize1, cardSize2);
this.tableCards.BackColor = System.Drawing.Color.Black;
surface.Controls.Add(tableCards);
}
public void AddCard1(Form1 surface)
{
//surface.Controls.Add(tableCards);
this.tableCards.Image = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures)+ @"\1card.bmp");
surface.Controls.Add(this.tableCards);
}
}
}
[STAThread]
static void Main()
{
Form1 Game = new Form1();
Form2 Begin = new Form2();
Form1 Game = new Form1();
if(Begin.ShowDialog() != DialogResult.Abort)
{
Player seat1 = new Player(656, 272, 27, 44,
624, 280, 28, 22,
616, 152, 80, 32,
616, 184, 40, 56,
656, 184, 40, 56,
616, 240, 80, 13,
624, 304, 40, 13,
576, 120, 33, 33,
Game);
Game.ShowDialog();
seat1.AddCard1(Game);
Game.ShowDialog();
}
}
I hope this isn't confusing. If anyone can help I would greatly apprecciate it.
|
|
|
|
|
Well, you instantiate six separate PictureBox controls in the Player class, but only one (tableCards) is ever actually added to the Controls collection of the form.
An instantiated control will exist in memory, but it will never show up on the surface of the form until it is added to the Controls collection.
Charlie
if(!curlies){ return; }
|
|
|
|
|
the picturebox tableCards is already added with a black box background. I just want it to add the image and show up on scrren. Is there any way to do this without using ShowDialog twice. It works if I do a showdialog, then add the image, then do a showdialog again, but the form flickers before it changes.
|
|
|
|
|
Why are you even calling ShowDialog anyway? If you actually read about it in the SDK documentation, you'd see that it's a synchronous call (i.e., the executing thread waits until the method returns) so you can't change anything about the form from your calling thread after calling ShowDialog , but you can before:
using (MyForm form = new MyForm())
{
form.tableCards.Image = someImage;
form.ShowDialog();
} This is enclosed in a using statement because also in the SDK documentation for ShowDialog is a remark that states that a modal dialog should be disposed when you're finished using it to free native, unmanaged resources. Using using makes sure that - even in the case when an exception is thrown - the form variable is disposed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is their any other way to get my form on the screen without using showdialog.
Also I think the dispose is what is giving me the flicker.
|
|
|
|
|
Yes, .Show() instead of ShowDialog(). But, your really shouldn't be calling this anyway. Your form should not have to show itself again and again every time you want to change the image. Also, your use of many different pictureboxes is probably what is giving you your flickering. If your pictureboxes are on top of each other, a repaint of the form will repaint each picturebox. Each box will repaint and invalidate an area of another picturebox, which will repaint and invalidate another area of another picturebox, which will repaint, ...
Like Heath told you before, and I'll say it again, your should be using only a single picturebox and painting all of your images into that one box yourself. That way you have MUCH greater control over what gets painted when and you will eliminate nearly all possible causes of flickering.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I just tried your method in my Player class to show the new picture but it still flashes when the ShowDialog is called again. I'm thining I'm just picking a really bad way to do this.
|
|
|
|
|
the picturebox tableCards is already added with a black box background. I just want it to change the tablecard image and refresh the form to show the change. Is there any way to do this without using ShowDialog twice. It works if I do a showdialog, then add the image, then do a showdialog again, but the form flickers before it changes.
|
|
|
|
|
Heath already described a MUCH easier method of doing this than using many many pictureboxes. Part of the problem with using dynamically generated picture boxes is making sure they show up on the form in the correct order. If you have two pictures boxes, one at least partially on top of the other, you will have a difficult time making sure which one will actually display on top.
Painting the images onto ONE picturebox is MUCH easier and MUCH easier to control the order in which images are painted.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I am trying to write a custom user control which is a "On screen keyboard" used for touch screen monitor. So when user press a key on the "On screen keyboard", the program knows as if the key on the keyboard is pressed. What should I have in KeyPress event for each keyboard character? or there are some other ways to do it? Also, how to loop through all key chars on keyboard?
Thank!!!!
|
|
|
|
|
Alan Zhao wrote:
What should I have in KeyPress event for each keyboard character?
How complete a keyboard are you emulating?
Anyways, the truly simple way of figuring this out is try it with a keyboard!
However, the right answer (I think) is that you'll want to inject the key-down and key-up messages into the Windows message queue. These keycodes are different (I think) from what you get with KeyPress. The reason for doing it this way is that any control can then receive the key up/down messages from your (I suppose) background thread. It's probably a bit more complicated than I've described, but that's the approach I would start with.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
How do you send the messages to Windows message queue and what's Windows message queue?
I am emulating a keyboard with all letters, digits, and a enter key.
Correction: What should I have in MouseDown or Click event b/c the keys are clicked by touch on the screen.
|
|
|
|
|
The Windows message queue is the heart of the Windows operating system, something you really should understand before attempting such a project.
The message queue is just what it (should) sounds like: a queue for messages. A message contains data about the destination window (every control and dialog in Windows is a window), the message you want to send, and to parameters that can point to anything and be used for whatever you like (although the pre-defined Windows messages do define what those should contain in the Platform SDK on MSDN Online[^].
You should read about Windowing[^] to gain a better understanding.
You can also P/Invoke SendInput , which is defined and discussed in the function reference section of another section you should read and understand, Keyboard Input[^]. If you're not familiar with P/Invoke, you should learn[^], but you could also just take a look at http://pinvoke.net/default.aspx/user32.SendInput[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Actually, they are the same, fortunately. This saves work of having to define a separate enum to send keyboard messages and P/Invoke related functions. This is true for the .NET FCL as well - it saves them work, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor.
Thank!
|
|
|
|
|
|
Alan Zhao wrote:
So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor.
You'll need a worker thread monitoring the input from the touch screen. The one's I've used had an RS-232 interface that provided the x, y coordinates of where the user touched. Of course, this had to be de-jittered, tested for a sufficiently long period of touch, and mapped to whatever graphics I had on the screen. Oh yes, and there's a calibration process involved to.
Sounds like you're in some deep water.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Hi, thanks for the help, but I didn't expect it to be this complicated.;)
This on-screen keyboard is written in Visual C#, so each Button represents a key. Therefore, when the user touch the button on the screen, it's like you click the button using mouse. So the SomeKey_Click() event fired. My problem is how do I tell system that SomeKey is pressed without physically type the key.
Thanks again!
|
|
|
|
|
I'm a bit confused as to the state of affairs.
Alan Zhao wrote:
This on-screen keyboard is written in Visual C#, so each Button represents a key.
Is that part working already?
Alan Zhao wrote:
Therefore, when the user touch the button on the screen, it's like you click the button using mouse.
Does that part work too?
Alan Zhao wrote:
So the SomeKey_Click() event fired.
And each button on the screen has an event associated with it, so that when the user touches the screen, the button's Click event fires?
Alan Zhao wrote:
My problem is how do I tell system that SomeKey is pressed without physically type the key.
Heath already answered that question, I thought.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Hi,
I don't want to crosspost, but I'm not sure if I have put the question in the right forum. The original post:
http://www.codeproject.com/script/comments/forums.asp?msg=830163&forumid=12076#xx830163xx[^]
Maybe some of you have encountered the above problem.
In short:
I change a source file of an ASP.NET project
Recompile
- and the assembly isn't updated, nor am I blessed with the usual errormessages if I write something syntaktically wrong - just to provoke the compiler to note a filechange.
but if I delete the assembly and recompile, I do get errormessages / a new assembly.
Even shorter:
- what can make VS.NET 2003 NOT compile a file ? I must be missing something.
UPDATE: A "Rebuild solution" works ! So it must definately be VS that just can't figure out when a code file has changed. Hope this gives you a clue - I'm still lost.
Best regards - and thanks in advance
Jan Hansen
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|