|
here, i wrote this a yesterday - it checks to find out the location of the default browser, then opens the file
using Microsoft.Win32;
using System.Text;
public string GetBrowser()
{
RegistryKey root = Registry.ClassesRoot;
RegistryKey regKey = root.OpenSubKey(@"\htmlfile\shell\open\command");
StringBuilder sb = new StringBuilder((string)regKey.GetValue(String.Empty));
sb.Remove(0, 1);
string str = sb.ToString();
int i = str.IndexOf('"');
sb.Remove(i, (sb.Length-i));
return sb.ToString();
}
System.Diagnostics.Process.Start(GetBrowser(), "http://www.codeproject.com");
there ya go
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Nnamdi,
Why don't you just use this:
System.Diagnostics.Process.Start("http://www.sendfakemail.com");
I thought that this would open the default browser anyway.
Can you tell me why you are using the GetBrowser() function?
Thank you for your help.
Regards
Wobble
|
|
|
|
|
i thought that:
System.Diagnostics.Process.Start("http://www.sendfakemail.com");
would mean IE hijacks it, when that may not be the default browser.
wobble wrote:
an you tell me why you are using the GetBrowser() function?
that is the function i made - shown above, that reads the registry, to find the location of the default browser, by checking what app is set to open .html files.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
|
No, you will need to get ODBC.NET[^] and MyODBC[^]. These will allow you to use similiar classes to the SQL data classes in the data .net framework.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
Hi all
I have 4 classes. About 80% of there functions are common. So I make an abstract baseclass to inherit from and add any function that is common. The question is how should i declare the functions in the base class and how must i declare the functions that are not applicable in the inherited class. This is what I have come up with.
Option 1:
Abstract class:
protected void Function(){...}
Inherited class:
if needed:
public new Function(){ base.Function() } or
public new Function(){ ...implement...}
if not needed:
do nothing
Option 2:
Abstract class:
public void Function(){...}
Inherited class:
if needed:
do nothing if implementation is not different or
public override void Function(){...implement...}
if not needed:
private new void Function(){} //hide the member
What is the correct / suggested way?
ANy help appreciated
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Rather than straight-out answer your questions I'll offer some suggestions.
Use an abstract base class when the base classes logically follow to inherit from it.
An example is the TextWriter class; it is an abstract class and all of the classes that inherit from it logically follow in the chain (XmlWriter, StreamWriter).
Now I will say that you should re-think the design of your base class if it turns out you have many methods that shouldn't be used by the inheriting classes.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thanx James
I think it needs some redesign too
How I wish for multiple inheritance...
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
You could fake it like Eiffel does
given three classes A, B, and C; where A and B are unrelated but C inherits from A and B the Eiffel compiler will do something like this.
interface IA<br />
{<br />
... methods, properties, etc of A ...<br />
}<br />
<br />
interface IB <br />
{<br />
... methods, properties, etc of C ...<br />
}<br />
<br />
class C : object, IA, IB<br />
{<br />
private A a;<br />
private B b;<br />
<br />
public void MethodOfA()<br />
{<br />
a.MethodOfA();<br />
}<br />
<br />
void IA.MethodOfA()<br />
{<br />
a.MethodOfA();<br />
}<br />
<br />
....<br />
}
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
James T. Johnson wrote:
You could fake it like Eiffel does
What the hell is Eiffel, presumably nothin' to do with a tower in Paris.
The quote is about the only thing I understood from the post . Thanx though
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
What the hell is Eiffel
Eiffel is another programming language that has been ported to .NET.
Like C++ it supports multiple inheritence, but unlike MC++ they kept that feature in there.
But since .NET only supports single inheritence they got around that by making an interface for the classes that are being inherited and use interface implementation to fake multiple inheritence.
To the language it all looks the same but to the CLR it is just implementation of interfaces.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
What do you have against Eiffel mate ?
A guy from Paris.
|
|
|
|
|
|
Thanx had a look, not sure how it is suppose to help me
It does indeed have something to do with that tower in Paris.
From Eiffel website:
When creating Eiffel in 1985, we decided to pay homage to one of the greatest engineers of all time: Gustave Eiffel, the man who built the eponymous Tower in Paris,...
CHeers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
how to write a DNS query for finding Mail server at a site
in c#
|
|
|
|
|
You could try the System.Net.Dns class's Resolve method, but I doubt that will perform the MX record look-up needed to get the mail server given a domain name (ie you would have to do a look-up using the mail servers name).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
How do I forcibly unload a .NET dll [the dll holds a global hook proc and thus it loads in the address space of any program that is run]
My problem is that even after unhooking the hook and closing the hook-setting program, the dll is still in use [I think the dll because of it's being a clr run dll is having probs unloading itself from non-clr program address spaces]
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
The correct term is an Assembly
You can't explicitly unload an Assembly; but you can unload the AppDomain that the assembly is loaded in. Unfortunately I'm not sure how well this would work; but its worth a shot.
After you unhook the hook, make a call to AppDomain.CurrentDomain.Unload() . That may or may not work though; so be sure to catch the CannotUnloadAppDomainException exception
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
Consider this C++ code:
//Thread 1
HWND target = ::SendMessage(hWnd, UWM_HERE_I_AM, (WPARAM)m_hWnd);
//Thread 2
LRESULT CTheOtherApp::OnHereIAm(WPARAM wParam, LPARAM)
{
other = new CWnd;
other.Attach((HWND)wParam);
return (LRESULT)m_hWnd;
}
Q1: How would I "register" the OnHereIam handler in a C# Program? (I read about AddMessageFilter in MSDN but its rather vague to me.)
Q2: What would the "return" statement look like? I mean how do you "cast" LRESULT in C#?
Q3: I guess if there is a way to register the OnHereIam message handler I won’t need to write a custom WndProc. But if I have too write one how is this usually done?
Thanks!
|
|
|
|
|
|
ke5in wrote:
Q1: How would I "register" the OnHereIam handler in a C# Program? (I read about AddMessageFilter in MSDN but its rather vague to me.)
You are better off overriding WndProc for this. AddMessageFilter should be the last option because of the overhead involved of calling the added message filters for *every* message passed to the UI thread, where-as WndProc only gets called for messages passed to that particular window.
The On* methods are called by the WndProc, not through any sort of magic but by putting something such as a switch statement in the WndProc and test for each message then calling the appropriate On* method.
ke5in wrote:
Q2: What would the "return" statement look like? I mean how do you "cast" LRESULT in C#?
The return type should be IntPtr.
ke5in wrote:
Q3: I guess if there is a way to register the OnHereIam message handler I won’t need to write a custom WndProc. But if I have too write one how is this usually done?
protected override void WndProc( ref Message m )
{
const int UWM_HERE_I_AM = 0x1234;
switch( m.Msg )
{
case UWM_HERE_I_AM:
m.Result = OnHereIAm( m.WParam, m.LParam );
return;
}
base.WndProc( ref m );
} Normally you would follow the event architecture that .NET already provides (event, delegate, and protected On* method for inheritors to override).
HTH,
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I tried emailing this but just got a bounce-back in return:
> In C# I can create a class for a thread and get it running.
> But the thing that has me confused is the “event” which
> occurs in the application. How do I notify the thread that
> this “event” has occurred using “the event architecture that
> .NET already provides”?
Here is how I would set it up (ignore capitalization, I'm typing in outlook so it likes to 'correct' me). There are two different ways of doing this, the first is used if its just a notification that something happened ("I was clicked", "I finished processing the task you already know about", etc), the second is used if you need to supply some data to the listener.
First the notification method:
class MyThread : ....
{
public event EventHandler MyEvent;
protected virtual void OnMyEvent(EventArgs e)
{
FireMyEvent(e);
}
private void FireMyEvent(EventArgs e)
{
if( MyEvent != null )
{
MyEvent(this, e);
}
}
private void SomeCode()
{
SomeLengthyProcessing();
SomeMoreProcessing();
OnMyEvent(EventArgs.Empty);
EvenMoreProcessing();
}
} Now in the code that needs to receive that event:
.....
MyThread mt = new MyThread();
mt.MyEvent += new EventHandler(myMethodToExecuteWhenMyEventHappens);
.....
private void myMethodToExecuteWhenMyEventHappens(object sender, EventArgs e) {
}
In the cases where you have data to be returned you use the same pattern, but the type names change a bit
class MyEventEventArgs : EventArgs
{
private int myValue;
public MyEventEventArgs( int myValue )
{
this.myValue = myValue;
}
public int MyValue
{
get { return myValue; }
}
}
class MyThread : ....
{
public delegate void MyEventEventHandler(object sender, MyEventEventArgs e);
public event MyEventEventHandler MyEvent;
protected virtual void OnMyEvent(MyEventEventArgs e)
{
FireMyEvent(e);
}
private void FireMyEvent(MyEventEventArgs e)
{
if( MyEvent != null )
{
MyEvent(this, e);
}
}
private void SomeCode()
{
SomeLengthyProcessing();
SomeMoreProcessing();
MyEventEventArgs e = new MyEventEventArgs(42);
OnMyEvent(e);
EvenMoreProcessing();
}
} Now in the code that needs to receive that event:
.....
MyThread mt = new MyThread();
mt.MyEvent += new MyEventEventHandler(myMethodToExecuteWhenMyEventHappens);
.....
private void myMethodToExecuteWhenMyEventHappens(object sender, MyEventEventArgs e) {
int value = e.MyValue;
} A lot of this seems like its overkill, but once you have used the framework for a while you begin to appreciate this style of event handling (its possible to attach 100 listeners to an event, where as posting to a thread's message queue only notifys that thread).
HTH,
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|