|
Stephan Wright wrote:
I can't add a refernce to user32.dll because it says it is either an invalid COM or dll.
You don't use the "Add Reference" button. Like I said, they are native functions, so they are already compiled. The user32.dll is already on your computer, in the Windows\System32 path. I would recommend you read the Platform Invoke Tutorial[^] for more understanding of what is taking place to make these native function calls.
- Nick Parker My Blog | My Articles
|
|
|
|
|
thanks, the code compiles correctly now, but well it does not work at the moment because either the window is not found or my parameters are wrong in the FindWindow.
So I used Marshal.GetLastWin32Error() to tell me, which error was thrown. But well the only output I do receive is "2" as the error message.
Is there a list of errorcodes for this or what does it mean?
I tried to find out about the hashvalues of the handles and there I found out the window has hashvalue 2. But well, why is this an error?
And besides: Do I have to tell FindWindow the full pathname (meaning including the solution) which you do get when moving the mouse over the classname in debugmode or is it enough to just use the classname without the whole thing bevor this?
Do you or anyone else have an idea of what's wrong?
Thanks!
Stephan.
|
|
|
|
|
It works now!
Well the classname has some wired string added to the "selfdefined" name. Some numbers etc.
That was the problem, but with Spy++ I found out!
Well so at the moment just having to manage the window poping up again instead of only being shown in the taskbar again!
Because the window should be brought into foreground when a double invokation was found.
Stephan.
|
|
|
|
|
I managed to do what you recommended, well almost!
I hardcoded the parameters for FindWindow, because I thought it would be the same verytime I start my application.
But I found out it isn'T, the first parameter for example changes everytime I do restart the computer. And besides it's something really strange. I thought my Window was a Form but well there were numbers and other numeric or letters. So I will have to change this to reading or receiving this from the application, but where? Maybe I don't see the wood because of all the trees anymore but I guess I am stuck again. I was able to get the Handle, the hashvalue or whatever but not the Classname of my Form. Well the WindowName isn't the Problem because it's stored in the Form1.Name element and I just have to fetch this.
But where do I have to fetch the first parameter from? Could you or anyone else help me please, to automate it so I could remove the hardcoded thing!
Thanks!
Stephan.
|
|
|
|
|
Stephan Wright wrote:
But where do I have to fetch the first parameter from?
Are you talking about FindWindow ? This assumes you know the name of the window text. There are other methods of getting the window HWND (Handle) however if you are writing the application you should know this (more than likely). Does that make more sense?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Well, as I said before I should be able to get the name of the window with the Form1.Name field. What I wanted to do is trying to get the classname for my window.
Because it is something like WindowsForms10.Window.8.app88 and that's what I do not want to hardcode because this changes everytime I reboot my PC. It could be WindowsForms10.Window.8.appdd as well.
With "second instance" I ment the user shouldn't be able to invoke the same application on the same PC twice, e.g. by clicking twice on the button. If he does the running application should reappear.
So because it's the same application (but just a second instance) the classname has to be the same. So the second invokation would have the same classname (prooved via Spy++) so I should be able to get the classname from somewhere. But I am not sure where to fetch it.
I also have a mutex on the instance, maybe I could fetch the Handle from there if it is possible to use it in this context.
Stephan.
|
|
|
|
|
what about if you just do the following:
add the handle hash in the registry and evey other application will be able to check it. And if it matches then the application is running. Or if the value is set, then the application is running.
But do not forget to reset the value, because otherwise you won't know if there is an application running or not!
|
|
|
|
|
i downloaded and install project GotoFunction, and after i recompile source code and build new setup project for addin GotoFunction, the install package doesn't work. It doesn't add to menu Tools and doesn't appear in Add-In Manager. Please help me.
Thank you
nthevu
|
|
|
|
|
Your problem is very vague, have you looked through the code that you downloaded, what is it doing? Have you contacted the author of the code/article, what did he/she say? If you have a specific C# question many on here would be glad to help you.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi,
Actually i posted one queary that " How we will change the color(caption color) of a Tabpage". Unfortunately i forgot to post the answer here. So Here is the answer for " How we will change the color(caption color) of a Tabpage.
Who is going to draw ?
Tabcontrol have a properties called DrawMode. This will set or get the value that whether user or system will paint the caption.By default it is normal. Means system(OS) will paint the caption for you. If you(parent form) want to draw the caption you have to set the value of the property to OwnerDrawFixed.
You can mention DrawMode on design time or runtime like below mentioned code.
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
Now you mention who is going to draw the caption.
Next thing is how is going draw ?
Tab control have an event called DrawItem event which will occure when ever an area need to be painted.
eg:
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font f;
Brush backBrush;
Brush foreBrush;
if(e.Index == this.tabControl1.SelectedIndex)
{
f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold);
backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Gold, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
foreBrush = Brushes.White;
}
else
{
f = e.Font;
backBrush = new SolidBrush(e.BackColor);
foreBrush = new SolidBrush(e.ForeColor);
}
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(backBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
sf.Dispose();
if(e.Index == this.tabControl1.SelectedIndex)
{
f.Dispose();
backBrush.Dispose();
}
else
{
backBrush.Dispose();
foreBrush.Dispose();
}
}
}
Sory for this late posting
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Due to the large number of posts within the C# forum I would suggest that you consider writing up your findings in an article and posting it, otherwise this post will get lost and won't provide much help for others in the future.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi,
I will do that. why i am simply holding is, i need to explore little more on these sort of controls and their default properties. thanks
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
how to change the Height of the Title Bar for a particular application irrespective of what the user sets the height in Display properties and in Xp and Classic Styles?(in SDK, C#)
|
|
|
|
|
Hello,
I have a cute little problem here. I want to enable the logging for login events from within my program, but I cannot find anything about that. In windows you can set it from Local Security Settings -> Local Policies -> Audit Policy.
Does anyone know how to do this? I'm really Stuck here.
|
|
|
|
|
Those policies map to reigstry entries. I recommend you search http://msdn.microsoft.com/library[^] or http://support.microsoft.com[^] to find which registry entry that GPO entry maps to. Then changing is easy: use the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey classes, which are documented in the .NET Framework SDK and simple enough to use.
EDIT: You could also open the policy template (don't remember where it is off-hand, but that is in the MSDN and Support sites, too) and see where it is. The policy templates are pretty simple text files that you could even open in Notepad and search for to find the friendly name (i.e., what you see) and then find what registry key it maps to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Damn,
I wish it was that easy, but I've tried everything, and I cannot find the key.
Anyone got more ideas?
|
|
|
|
|
Sorry to say, but that works. All the policies do is set registry keys - nothing more. With some settings, a reboot may be required, though in Windows NT the policy update cycle (default is 15 minutes) is usually sufficient.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay, I found it,
the thing was that the registry key was secured, so I couldn't see it myself. Adjusting permissions edited the whole issue. Just one problem, I need to read the Default Value of the key HKEY_LOCAL_MACHINE\SECURITY\Policy\PolAdtEv, but how the hey can I do that, If I want to read a keyValue, I must supply a keyname, but the defaultvalue hasn't got any :S.
thanks for your help so far, I wouldn't have gotten this far without it.
|
|
|
|
|
Okey, I found how to read the default value. But now I've got a whole different problem. Since th type of value is REG_NONE I cannot get the value out. even though I know it is Binary.
Does anybody know how to read this kind of values anyhow? Or another workaround?
|
|
|
|
|
HI~
using C# compact framework, How can I:
1.add items in the start menu of pocket pc
2.add items in "new" in task bar in today screen of pocket pc
3.add an icon in the taskbar of the today screen of pocket pc. A menu appear when the user click the icon.
Thanks~
|
|
|
|
|
|
Help me, please ! How can I get a content of RichTextBox as Image (or Bitmap, or Metafile) or save it to a graphic file (any format) ?
|
|
|
|
|
Read How To Print the Content of a RichTextBox Control By Using Visual C# .NET[^] and modify the Print method documented in the KB article so that it accepts a Graphics object as the last parameter instead of a PrintPageEventArgs (you'll need to pass a struct for margins as well). This will allow you to pass a Graphics object (ultimately, the HDC - or handle to a device context - is used) for printing or to save an image.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI~
I am using compact framework and
I have written a class which extend Microsoft.WindowsCE.Forms.MessageWindow
How do I register the window class in C# so that I can find the window by using the function "FindWindow" ??
Note that the handle of the message window is existed in the instance of the MessageWindow.
|
|
|
|
|
FindWindow is a native function, however if you look at the documentation for FindWindow[^] on MSDN you will see that if you pass null for the lpClassName parameter it will find any window whose title matches the lpWindowName paramter. The P/Invoke signature for FindWindow is as follows:
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
This works if you pass null as the first parameter, however if you want to specify the class name, you will have to override the CreateParams and specify the ClassName property.
- Nick Parker My Blog | My Articles
|
|
|
|