|
There most certainly is an easier way to do it and it's approximately 1700 times faster. If you ask nicely, I might even tell you about it
|
|
|
|
|
Pretty-please I suppose I probably should buy a book about C#.:->
|
|
|
|
|
See the other reply. You won't learn about a new language and framework in an hour. Believe me, from experience, C#/.NET is ten times faster/easier to use than the corresponding Win32 API (with or without MFC) in 99% of the cases. You'll just have to search for the appropiate classes to do your job.
One thing .NET is a thousand times better is that it has been designed from the ground up, so all the classess are very consistent with each other, whether you are developing a Windows or a web app.
Take your time to learn this new technology, and I'll bet anything you won't want to go back! :->
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
To Browse for files use OpenFileDialog you will find it in the toolbox after that ypu can write some thing like
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "CSharp files (*.cs)|*.cs" ;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
}
For More info look at <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsopenfiledialogclasstopic.asp" rel="nofollow">OpenFileDialog Class</a>[<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsopenfiledialogclasstopic.asp" target="_blank" rel="nofollow" title="New Window">^</a>]
If you really missed Windows API Function that you did not find counterpart in .Net You can use it By using P/Invoke which let you call function in traditional dll
look for Using P/Invoke to Access Win32 APIs[^]
MCAD
|
|
|
|
|
I need to do some cleanup when my dialog closes. I tried overriding mydialog.Close() doing the cleanup there and then calling base.Close(). When the user exits it using the close button everything works as intended, but the X doesn't call Close() and leaves my app in a messedup state.
|
|
|
|
|
The Windows recive WM_SYSCOMMAND Notification when you close minimize or maximize the window or you choose any command from the system menu
So overrid your form WndProc function and handle it
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if(m.WParam.ToInt32()==SC_CLOSE)
{
MessageBox.Show("Application will be close");
base.WndProc(ref m);
}
}
else
{
base.WndProc (ref m);
}
}
if you don not handle other Message you can write it like
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if(m.WParam.ToInt32()==SC_CLOSE)
{
MessageBox.Show("Application will be close");
}
}
base.WndProc (ref m);
}
for more information look at WM_SYSCOMMAND Notification[^]
MCAD
-- modified at 18:53 Friday 23rd September, 2005
|
|
|
|
|
You should handle the Closing event of System.Windows.Forms.Form . This event is fired regardless of whether the dialog was closed via the system menu or a close button on your form.
Regards,
mav
|
|
|
|
|
*blush*
In my defense I can only say Friday 4pm.
|
|
|
|
|
|
Real-time event notifications don't work very good over a WAN connection. I found that I had to buffer them and get an update pack about every 15 seconds to get it to work correctly. The VBScript code I used went something like this:
Set objWMIServices=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & machineName & "\root\CIMV2")
set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
WScript.Echo "Starting Listeners... Win32_Process"
objWMIServices.ExecNotificationQueryAsync objSink, "SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Process'"
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
Set objTargetInstance = objWMIServices.Get(wmiObject.Properties_("TargetInstance").Value.Path_.Path)
WScript.Echo Now() & " - " & objTargetInstance.GetObjectText_()
WScript.Echo objTargetInstance.CreationClassName
If objTargetInstance.CreationClassName = "Win32_Process" Then
Rtn = objTargetInstance.GetOwner(strNameOfUser, strDomain)
If Rtn <> 0 Then
Wscript.Echo "Could not get owner info for process " & objTargetInstance.Name & VBNewLine & "Error = " & Rtn
Else
Wscript.Echo "Process launched by " & strDomain & "\" & strNameOfUser & "."
End If
End If
End Sub
This code is part of a "quick little tool" that watches for new processes to launch and notifies me whenever it happens. I was looking for a certain someone to start gambling on company time and I needed to catch him with his hand in the cookie jar, so to speak.
The "WITHIN 60" clause just means I get an update from the remote machine every 60 seconds instead of right when the event happens. Over a slow connection, real time events tends to get dropped if they happen in quick succession. This was the work around to get more reliable notifications.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for the response.
But when I tried to run the same service on the remote host. I get "User credentials cannot be used for local connections" error. I am sure the loginid which I am using got 'Administrator' privileges.
In my case, I need to montitor the remote host event log and track the error from certain source (which is from config xml) and on certain conditions (which are from config xml). If that happens I restart (via ManagementClass.InvokeMethod) the affected application.
The programmer's national anthem is 'AAAAAAAARRRRGHHHHH!!'. This signature was created by "Code Project Quoter".
|
|
|
|
|
To all those SharePoint Gurus, tell me if this is possible.
I want to customize SharePoint's existing front-end site, and using the SharePoint database in the back end.
My prefered language would be C#. But before I head any further on this, is this feasible?
Stanley
|
|
|
|
|
I have a contextmenu that is called when you press a button. The contextmenu is associated with a single treeview. however, there are other treeviews on the form. When the user clicks on a different treeview and hits the button that calls the contextmenu for the previous treeview, it gives me an error. i expect this. Nevertheless, I need to fix it. How can I get the contextmenu to show only when the user has selected the designated treeview? Thanks.
D
|
|
|
|
|
I'm not understanding your problem. What error are you getting?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
This is the error I am receiving: Object reference not set to an instance of an object.
I know why I am receiving this error. I just dont know how to fix it. The contextmenu is designated for only one treeview. When you select on another treeview, and then hit the contextmenu BUTTON, you get this error. Now, keep in mind, if the user knows what they are doing, this should never happen. Nevertheless, I still have to prevent it.
|
|
|
|
|
Run your app in the debugger in VS (Hit F5), you'll see that one of your objects is null, thus throwing an exception.
|
|
|
|
|
How can I list all the databases that are available with sql server 2000.
|
|
|
|
|
SqlServer have sp_databases Stored Procedure which list databases available in the server instance you can write somthing like
private void ListDatabases_Click(object sender, System.EventArgs e)
{
using(SqlConnection cn=new SqlConnection("Server=localhost;Initial Catalog=master;Integrated Security=SSPI;"))
{
cn.Open();
SqlCommand cmd=new SqlCommand("sp_databases",cn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
Debug.WriteLine(dr.GetString(0));
}
dr.Close();
cmd.Dispose();
}
}
MCAD
-- modified at 21:43 Friday 23rd September, 2005
|
|
|
|
|
Fantastic!! I will give this a go and see how it works!
Much Appreciated.
|
|
|
|
|
I have been told and told and told (correctly) that I MUST do all my drawing in the Paint handler. That being said here is my simple problem.
1. I have a class:
MyClass
{
//let's forget Set/Get and make public....
public int x;
public int y;
}
2. I have the Paint handler:
protected override OnPaint(..,..)
{
}
Here's my problem?
I want to pass the x, and y coordinates as the x2, y2 coordinates of the args in a g.DrawLine overload inside some function as in--(assume x1, y1, both have a value of 20--
"return type" DrawFunc("some args or void?")
{
g.DrawLine(pen, 20, 20, "x", "y")
}
Is this the right way to do this?
Does "g.DrawLine(...) need to be INSIDE the paint handler?
Also I will want to draw more lines with different values of x, and y.
I know how to Set/Get them. I want to know the correct way to draw them in the Paint handler from a function call... please help thanks
|
|
|
|
|
You mean something like this?
protected override void OnPaint(PaintEventArgs pea) {
MyDrawLine(pea.Graphics, 89, 76);
MyDrawLine(pea.Graphics, 32, 45);
}
private void MyDrawLine(Graphics g, int x, int y) {
g.DrawLine(somePen, 20, 20, x, y);
}
For sure all painting should be done in the OnPaint-method but you can call helping drawing functions from there and just pass the Graphics object araound.
|
|
|
|
|
Yes-- something like that.... many thanks!
One other question, I forgot to add in my post. I need a button1 event to fire when the user wants the line drawn. Does "MyLineDraw(...)" go inside the button1 braces??
//i.e
button1_Click
{
// Want it do draw the first line.....
}
|
|
|
|
|
No. You'd call this.Invalidate() which in turn will call OnPaint()
|
|
|
|
|
Thanks for your answer. I guess I need to define it a bit more...
Lets say I have button1 that draws line A and button 2 that draws line B
How does the button get linked to the method that draws say, lineA and not lineB or vice-versa... - thanks again
|
|
|
|
|
Store somewhere what lines should be drawn. In the event that handles each button you update the information on which lines should be drawn, then you invalidate the area that has your paint event, so that the paint event will be called to redraw the area, thus redrawing the lines.
The reason that you have to store somewhere what lines should be drawn, is that the paint event will be called everytime the area needs redrawing. For an example, if you move some other window across your window, the paint event will be called to redraw the area when it appears again.
---
b { font-weight: normal; }
|
|
|
|