|
Hi,
I use ShellExecute to open standard email program und create an email with predefined content and allow user to change it before he send it out. As following, the code compiles, but any email program is opened and no email is created. Why, what may I do?
[DllImport("shell32.dll")]
public static extern IntPtr ShellExecute(...)
private void cmdEmail_Click(object sender, System.EventArgs e){
string sEmail = "mailto:le.nhan@freenet.de?"
+ "subject=Error notification"
+ "&body=%0D%0A%0D%0A%0D%0A" + "Description : ";
ShellExecute((System.IntPtr)0, "open", sEmail, null, null, 1);
}
Thanks
TNL
|
|
|
|
|
Why not just use Process.Start ? You P/Invoked what has already been encapsualted for you.
Simply:
Process.Start("mailto:le.nhan@freenet.de?subject=Error notification"); Many email clients do not support the body parameter, which may be the source of your error.
If you tell us what email program you're using, that may help as well. Not giving us any details is like giving a small chunk of code and simply stating that "it doesn't work". Please be specific.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks,
but it doesn't work too, I don't know why. The errormessage:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll.
I call simply so:
System.Diagnostics.Process.Start("mailto:le.nhan@freenet.de?subject=Error");
I use Outlook 2000
I don't know, which Email program will the users use, therefore I used shellexecute in VB, VC, now I want to use it again.
I saw in this site, there are many email solutions, but I can not decide, which suits my aim, simply send a text to a receiver, the user can change the text, but he don't need to login...
Thanks
TNL
|
|
|
|
|
Process.Start uses ShellExecute . If you use an IL disassembler like ildasm.exe or a decompiler like .NET Reflector[^] you can see that. Of course, the ProcessStartInfo.UseShellExecute property should be a pretty good indication, too.
This does work and many, many people use it. Something else with your setup is wrong. What were the details of the Win32Exception ? Just telling me the exception type doesn't typically help much, especially for the Win32Exception . I need to know the error code and any exception text that was returned to you. Only then do you have some chance of figuring out what is wrong.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
is there a class made for dealing with bit stuff like setting bits removing bits and pre defined bit values?
|
|
|
|
|
Read about the BitVector32 structure in the .NET Framework SDK. You can also use the BitArray , but the former structure is more efficient.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I created a Windows Form. The form contains a button called "Line". When I click the button I want a line do be drawn on the Form. I also want the button to disappear.
While I appreciate any help/advice things like "just call DrawLine" or "create a Graphics object" are beyond obvious as general concepts. I would like specifics or even the code fragment.
thanks very much-
|
|
|
|
|
Hi
Here's the code you'll need. If comments aren't enough, just reply:
bool bPaintLine = false;
Pen p = new Pen(Color.Blue);
private void btnLine_Click(object sender, System.EventArgs e)
{
bPaintLine = true;
this.Invalidate();
btnLine.Visible = false;
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(bPaintLine)
{
using(Graphics g = e.Graphics)
{
Point pStart = new Point(10,10);
Point pEnd = new Point(500,500);
g.DrawLine(p,pStart,pEnd);
}
}
}
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|
|
SimonS wrote:
using(Graphics g = e.Graphics)
That's bad. Do NOT dispose the Graphics given to you in the PaintEventArgs . It will do this itself and may require the HDC that's attacked to it that you've disposed. The OnPaint event handler that fires the Paint event may need it before, after, or both in relation to when the event is fired.
Besides, when extending a class in which you want to paint it is far more efficient to override the event handler instead of handling the event in the very same class. For example:
public class Form1 : Form
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
} This requires less overhead and gives you more control. There may be times - like when overriding WndProc - that you don't want to call the base implementation. So don't. With an event you can't do that. With events you also can't control when the base implementation is called, while you can with an override.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Simon,
Thanks very much for you help. If you have a second I have two questions:
1. Why is "this" in "this.Invalidate();" the Form and not the button?
2. I've never seen the "using(Graphics g = e.Graphics)" syntax. Don't you have to create a new Graphics(); ?
thanks again...
|
|
|
|
|
1. Because the line is being painted on the form, not the button. Invalidate invalidates a region of a window (controls are windows, too, BTW) and the next time a paint message (WM_PAINT ) is sent to the window the line is painted.
2. using compiles to the following:
Graphics g = e.Graphics;
try
{
}
finally
{
g.Dispose();
} The using block is documented in the C# Language specification.
As I said in my reply, though, do not dispose the Graphics object. You only dispose Graphics objects (and pretty much anything else, for that matter) that you create. Since your code did not create the Graphics object via Control.CreateGraphics , Graphics.FromImage , or several other methods you should not dispose it yourself. The default implementation will dispose of the Graphics it created (which is actually from Graphics.FromHdc internally) when the OnPaint method (and any event handlers attached to the Paint event) return.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
To rephrase Heath's response in more plain english:
1.
I'm basically telling the form that something has changed and it needs to redraw itself. In a way, it is like calling the Paint event.
2.
As per Heath's quick response, it is exactly the same as writing: Graphics g = e.Graphics;
Except that you are automatically handling the disposing of the object yourself. Whether this is correct or not is, in my opinion, secondary to getting the code written, by hey, it's new year's and I've had a bit to drink... Thanks for point ing that out, H.
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|
|
Before you say it's just your opinion, you may want to look at the IL for the Control.WndProc and Control.OnPaint methods. If you have experience with GDI the reason is obvious: the Graphics is the HDC for the control to paint in, and if you dispose of it before it is used again the control will not be painted right and - depending on the implementation - may cause an AV (access violation) exception.
As a general rule of thumb you only dispose what you've created.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for all the help... here's what I have so far...
/////////
bool bPaintLine = false;
Pen p = new Pen(Color.Plum);
private void btnGraph_Click(object sender, System.EventArgs e)
{
bPaintLine = true;
this.Invalidate();
btnGraph.Visible = false;
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(bPaintLine)
{
Point pt1 = new Point(10, 0);
Point pt2 = new Point(10, 400);
for(int i = pt1.X; i <= 40;)
{
Graphics g = e.Graphics;
g.DrawLine(p, pt1, pt2);
pt1.X += 10;
pt2.X += 10;
}
}
}
PROBLEM: It draws the lines and indeed the button disappears - but then it hangs up and crashes if I try to close the Form.....
|
|
|
|
|
What are you trying to do?
It looks like you have an infinite loop, if we assume that you really didn't indend to end your for statement with a -- Nevertheless it looks like you intended this:
for(int i = pt1.X; i <= 40; )
{
...
}
Which doesn't seem to make any sense. Since i is never changed, it is an infinite loop.
Are you trying to draw one line or several lines? If several, you might want to change to a scheme where instead of using a boolean (bPaintLine), you maintain a collection of lines to draw. Whenever you want to draw a line, you add it to the collection. Your OnPaint() draws whatever lines are in the collection.
By the way, it is probably a CP bug that it interprets emoticons inside preformatted blocks.
Matt Gerrans
|
|
|
|
|
hi all here and happy new year
i have bringing out thes problim yesterday in vb.net thread but i don't have any suggestion
i wish if any body here could help me the problem was published as :
i have urgent problem i don't know what i must do to solve it
the project that i work on consist of server and client application
it represent real Time system
and have three connections
on the client sied the problem is that:
i have found that the CPU usage is 100% this isn't the usaual case of the client
first :when i watch the threads from control panal-->performance i found that one thread go up
and take most resource
i don't know how to catch this thread
second :i note that if i put any break point to stop the applecation then let it run again
the CPU usage go down to a good level
Aswanee
|
|
|
|
|
|
I was reviewing articles at CP for quickstarts and articles that would cover the ability to send email messages and attchments from a Windows C# program. I came across an article about SMTP Trace Listeners at http://www.codeproject.com/csharp/smtptracelistenerarticle.asp, but this article appears to deal with the System.Web.Mail namespace which is not available in a windows application.
Is what I am looking for presented at the MESSAGING segment provided at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpqstart/html/cpsmpnetsamples-howtodiagnostics.asp? Any suggestions on how to proceed with sending an email message and possible attachment either using an .htm/javascript file ON THE FLY (transparently) or a windows namespace using C#?
|
|
|
|
|
new_phoenix wrote:
I came across an article about SMTP Trace Listeners at http://www.codeproject.com/csharp/smtptracelistenerarticle.asp, but this article appears to deal with the System.Web.Mail namespace which is not available in a windows application.
Of course it is, but you need to add a reference to the System.Web.dll to your project, first.
Best regards
Dennis
|
|
|
|
|
Doh!!! Thanks, Dennis. I will give it a try. Appreciate the nudge in the right direction.
|
|
|
|
|
Keep in mind that will only work for Windows NT-based platforms. The System.Web.Mail classes use CDO to send mail, which is implemented by a small client library and by services like Microsoft Virtual SMTP Server (required to send mail for ASP.NET applications) and Microsoft Exchange (can also be used for ASP.NET applications, but is not required).
If you want to support all platforms on which the .NET Framework is supported, you need to send SMTP messages yourself. It's really not hard and is very similar to the HTTP protocol. See RFC 821[^] for the technical details, although you could click "Search comments" directly above this message board and search for my previous comments about this very question, such as how to resolve MX records for the SMTP server for a domain (so that you know which computer to actually connect to and send mail).
There are third-party libraries out there that are either cheap or free, too. The .NET Framework 2.0 beta also includes a "generic" implementation of SMTP that doesn't rely on CDO to send mail.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I will read the RFC 821 article that you had provided. It is my understanding from your comments that the System.Web.Mail namespace will only work on a Windows NT platform. I would like my application to work on any CLIENT computer from a standard windows form. For example, I am using only Windows 2000 Professional, and I am not certain that there are any services included providing even SMTP services.
There are several articles provided at codeproject.com. Could you kindly write an article, and itemize/clarify all the steps that are required to send an email message with attachments, describing this MX record in more detail, and for maximum portability? Also, what are the limits for this technology, operating systems, etc.
Would appreciate further elaboration...
|
|
|
|
|
new_phoenix wrote:
For example, I am using only Windows 2000 Professional, and I am not certain that there are any services included providing even SMTP services.
As I mentioned in my reply, if a client application is using SmtpMail the CDO client library is used. It's only when you're doing this within ASP.NET that a CDO server is required. If you know you'll only be running on Windows 2000 Pro or newer, then you don't really need to send SMTP messages yourself.
new_phoenix wrote:
Could you kindly write an article, and itemize/clarify all the steps that are required to send an email message with attachments, describing this MX record in more detail, and for maximum portability?
As I said in my last reply, click "Search comments" and search for SMTP. I've covered this more times than I'd like in the past. Searching is just part of research, which is just part of development.
I will write an article eventually but when I have more time, which is rare. SMTP is not a difficult protocol to implement, however. What my planned article is about has more to do with MIME and S/MIME than SMTP, though that will be covered. It could be a couple months before I release this.
Making SMTP portable is not a problem: it's a well-established protocol, and a protocol means that every implementation of the protocol must follow it. Making your code portable is simply a matter of looking at the bottom of the member documentation in the .NET Framework SDK and making sure it supports the platforms you require. For most of the .NET BCL (base class library) the members are supported on all Windows platforms.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Also, if you're looking for articles then you should search this site, first. Here's a URL for a search (using the textbox directly below the logo at the top of the page) limited to C# and .NET categories, simply searching for "SMTP". A few of these have good ratings, so view those first (within your scope; some may not apply):
http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=SMTP[^]
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I’m building a Dictation / Transcription program. I’ve got everything working however I would like to put a indicator on the form that will show when someone is dictating that it is recording their voice ( i.e. Like the simple Record Sound program in Windows that shows a real time amplitude graph). I believe this can be done using the Mixer API but there is just not enough documentation that I can find on this.
Is there a plug-in that I can purchase out there already made? Or perhaps some type of documentation to steer me in the right direction to create my own?
This project is being created in C# using DirectX 9 SDK
Any advice would be appreciated.
|
|
|
|
|