|
This object does not exist is C#. Use any int instead :
(from MSDN)
public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
|
|
|
|
|
but if i have to call vc++ sendMessage then i have to provide a valied hwnd .
i f not like that how to do it?
r00d0034@yahoo.com
|
|
|
|
|
I am afraid there is no more windows messaging API in C#. I guess you have to use interop and pass the HWND to lower-level code to send the message for you.
Here we go : (MSDN)
public class NativeMethods
{
public NativeMethods(){}
[StructLayout(LayoutKind.Sequential)]
public struct CopyDataStruct
{
public string ID;
public int Length;
public string Data;
}
[DllImport("user32.dll", EntryPoint="FindWindow")]
public extern static System.IntPtr FindWindow(string lpClasName,
string lpWindowName);
public const int WM_COPYDATA = 0x004a;
[DllImport("user32.dll", EntryPoint="SendMessage")]
public extern static int SendMessage(System.IntPtr hWnd,
int Msg, int wParam,
ref CopyDataStruct lParam);
}
private void SendingForm_Load(object sender, System.EventArgs e)
{
ReceivingForm rec = new ReceivingForm();
rec.Show();
}
private void button1_Click(object sender, System.EventArgs e)
{
NativeMethods.CopyDataStruct DataStruct = new NativeMethods.CopyDataStruct
();
DataStruct.ID = "1";
DataStruct.Data = "Sample Text";
DataStruct.Length = DataStruct.Data.Length;
IntPtr WHnd = NativeMethods.FindWindow(null, "ReceivingForm");
if(!WHnd.Equals(System.IntPtr.Zero))
{
NativeMethods.SendMessage(WHnd, NativeMethods.WM_COPYDATA,
0, ref DataStruct);
}
}
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case(NativeMethods.WM_COPYDATA) :
NativeMethods.CopyDataStruct ds =
(NativeMethods.CopyDataStruct)m.GetLParam(typeof
(NativeMethods.CopyDataStruct));
string s = ds.Data;
break;
default :
break;
}
base.WndProc(ref m);
}
|
|
|
|
|
You can get the Handle to the main window of a process from the "System.Diagnostics.Process" class. It has a "MainWindowHandle" property. Don't know if this helps, but hopefully it will
m
|
|
|
|
|
anybody done or know of anything fancy done with this.
the templates in visual studio aren't bad but they seem to ignore the <exception> and <example> fields amongst others
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Go to http://www.gotdotnet.com/team/csharp, choose tools and utilities on the right. There are a couple of better programs there.
|
|
|
|
|
thanks eric - by the way what are your favourite tools? I see you have created a regular expression workbench - a tool I wish was in Visual Studio from the beginning.
My particular favourite is XML spy - damn useful for creating xpath queries and such.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Please help me solve this problem
I created an application that saves its settings to a file. This file has to be globally accessible. Here is the problem: If the administrator is the first to use the program, then the file will be created by the administrator. When a user with less rights logs-in, the application tries to modify the file. But, the they dont have enough rights.
How do I create a file that everyone has rights to? Or, How do I change the permissions to allow everyone to read, write to the file? (note: this file doesn't contain anything important, so its safe to allow unlimited access)
If someone could do me a favor and post an answer, I would be very glad. Thanks!
|
|
|
|
|
AK wrote:
Here is the problem: If the administrator is the first to use the program, then the file will be created by the administrator. When a user with less rights logs-in, the application tries to modify the file. But, the they dont have enough rights.
AK,
What you are describing sounds like a network rights issue. When the app is first installed the Admin needs to set the rights to the file for use by everyone.
With that said, are you sure that you want to be using a file for multi-user read-write? You will run into all kinds of issues related to concurrency. A database (even an Access MDB) would serve you better. (If you were using the file for read-only you could get away w/o any problems but read/write will give you headaches in a multi-user environ.)
|
|
|
|
|
Actually this is pretty similar to a network issue. But, in my case the problem resides in the NT file system. When an admin account creats a file the users with less rights (ie. normal users) cannot access the file that was created. Another thing, if a person with low rights creats this file it is accessible to the admins and people that have more power.
I just dont know how to change the permissions, to allow everyone to have full control.
|
|
|
|
|
AK,
Yeah, thats what I'm talking about. The Admin needs to change the rights.
|
|
|
|
|
I have a library at http://www.codeproject.com/useritems/NTSecurityNET.asp that allows one to manipulate NTFS access control lists. This may help you change the permissions of the file so that the appropriate users have access.
|
|
|
|
|
I sincerly thank you for point out the article. Its a wonderful peice of work. In fact, it solved my problem in only 3 lines of code!
Thanks again.
|
|
|
|
|
I'm trying to draw directly on the screen. Whatever is drawn needs to be "above" the controls on the form. And, of course, I need to erase whatever is drawn to restore the way things looked before I did my drawing.
I looked at the "Reversible" drawing functions on the ControlPaint object but these don't give me the control over the color that I need. (I really only need Black, White, and a dotted grid of Gray.)
What should I be looking at now to get GDI+ to work with me on this?
-----
I'm essentially trying allow users to select controls. If one control overlaps another I still want the selection cues to appear atop the covering control.
|
|
|
|
|
With DirectDraw you are able to draw directly on the screen!
|
|
|
|
|
Really all I'm trying to do is recreate Visual Studio's form desinger. I think adding DirectDraw would be overkill.
|
|
|
|
|
You got me interested!
What do you mean recreate VisualStudio's form designer?
I think there is a way you can just import the functionality from a the original libary. I think its located in C:\Program Files\Microsoft Visual Studio .NET\Common7\IDE\Microsoft.VSDesigner.dll.
If you want to do it another way, it can get very messy very fast. Ie. if you draw directly on the screen you then have to do hooks to handle the mouse events...
Good luck to you. By the way, ASP WebMatrix did an ASP think like this. They have a VisualStudio like UI, with with the ASP webforms designer surface.
|
|
|
|
|
To answer your question directly, this is how you can draw on the screen:
System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(System.IntPtr.Zero);
-or, something like this-
IntPtr handle = System.IntPtr.Zero;
System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(handle);
--
Basicly you need to tell it you use null as the handle. This creates a graphics object that draw on top of everything. But, it can be very messy.
|
|
|
|
|
AK,
I tried both suggestions. The second throws an exception and the first doesnt crash but it doesn't do anything. Can you give me a link to a web page about using the null pointer to gain access to the screen?
Thanks.
|
|
|
|
|
Hi,
I read AK's article and experimented with his second solution. It did throw an exception. And I modify it as follow and now it works:
IntPtr hdc = GetDC(IntPtr.Zero); // get hdc for the screen
Graphics g = Graphics.FromHdc(hdc);
g.DrawLine(new Pen(Color.Blue), 0,0,500,500); // draw a line for testing.
g.Dispose(); // <- I don't know if I should use g.Dispose or g.ReleaseHdc here...
ReleaseDC(IntPtr.Zero,hdc);
GetDC & ReleaseDC are Win32 API in user32.dll
Hope this could help you
|
|
|
|
|
Sorry, I forgot to tell you to use GetDC.
I knew I missed something.
|
|
|
|
|
I've never tried this, so it may or may not work but here goes
Create a control the same size as the Form (a panel would do), now when you want to draw your grid or whatever above the Form you do several things....
form will be the Form you are trying to draw on top of
parent will be the panel or whatever that the Form is sitting on top of
<br />
Graphics g = parent.CreateGraphics();<br />
PaintEventArgs e = new PaintEventArgs(e, form.Bounds);<br />
<br />
InvokePaint(form, e); <br />
<br />
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
James,
Hmm, I've been trying a similar approach but I like yours better because there is only a single surface to draw on. My only question is will I need to make your panel Transparent? I ask because I’ve been trying to create a user control with the graphics drawn on it around the edges. Then I was going to make the background color transparent and place this usercontrol over the other control (lets say it is a button) already on the form. In this way the button would show threw and my usercontrol's graphics would indicate that the button has been selected; even though the user control completely covers the button.
The only problem is that I can't make the usercontrol transparent!!! Will I have to make your panel transparent too. Because this just isn't working for me.
|
|
|
|
|
Here you go, a quick demo showing how its done
It doesn't paint the non-client area but I think you can send some messages to windows to get it to do that (just need to call GetHdc/ReleaseHdc when passing it to windows).
InvokePaintTest.zip (8.1 Kb)
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Wow, thanks James
I tried out your sample just now and its pretty cool. I'm probably not going to use it though because I want to keep the controls on the same form BUT if the screen painting turns out to be a hassle I’ll definitely come back to your solution.
|
|
|
|