|
Thanks for the correspondence Heath - however in the meantime I have figured it out. I created an event handler for Form.Load which as you know occurs before the form is displayed for the first time. In the event handler I change the WindowState of the form to maximised, invalidate the screen and ask for an update. This seems to do it for me nicely. See code
//the Event handler
this.Load += new System.EventHandler(this.welcome_Load);
private void welcome_Load(object sender, System.EventArgs e)
{
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Invalidate();
this.Update();
}
|
|
|
|
|
Hi folks,
I was recently reading Michael Kennedy's article, "Global System Hooks in .NET" [link], and I got to thinking:
If a global system hook injects the same stub of code into every running process in order to intercept the messages when they reach the process, wouldn't it be smarter to intercept the message before it was even dispatched to the process?
You'll have to forgive my ignorance here; I have next to no knowledge of the Messaging framework!
But, back on track, that thought struck me as quite odd. Surely it would be better to intercept it at a choke point rather than cater for every possible location? And if that was the case, surely it would also mean you wouldn't unnecessarily slow down the other processes on the system? Is that actually possible? Or do I simply not understand at all (quite likely )
Again, this is just a thought - like I said, I have no knowledge of the internals of Windows' messaging system
Thanks for any comments,
-Adam Goossens.
This space for rent.
|
|
|
|
|
Adam Goossens wrote:
Surely it would be better to intercept it at a choke point rather than cater for every possible location? And if that was the case, surely it would also mean you wouldn't unnecessarily slow down the other processes on the system?
That's the pitfall for using a global hook. If you monitor the system for a specific message to a specific window, a global hook is not an appropriate solution. Global hooks are more for, say, monitoring the the system for keyboard events, mouse events, ...
I've used it to disable the Window key on our keyboards since there are keyboard shortcuts to launch Explorer even though policy has launching Explorer prohibited. This was a low level keyboard hook that intercepted keyboard messages before they were dispatched to the system.
If written properly and by that, I mean very efficiently, you'd never know the hook was there. Improperly written hooks, on the other hand, can seriously degrade performance. The keyboard hook I wrote just examined the keys coming from the keyboard driver and didn't pass along the key combinations that we needed it to suppress. This hook never showed a single second of consumed CPU time during the entire time it has been running, so it works really fast.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, that's the thing, global hooks are using the "choke" points. Every app has its own message queue. Even threads have their own queue. The system itself has no queue. So, if you want to capture something globally, you have to put something into each app. No other way around it, unfortuneately.
Now, I'm not sure if this is a confusing point, but the "Messaging framework" is a different beast than "windows messaging". The messaging framework is a service that distribute messages using tcp/ip. The windows messaging is for the gui/user interaction. The two have absolutely nothing in common other than running on Windows machines.
I hope I've cleared things up. If not, well.... ask!
--
Joel Lucsy
|
|
|
|
|
Well, that's the thing, global hooks are using the "choke" points. Every app has its own message queue. Even threads have their own queue. The system itself has no queue. So, if you want to capture something globally, you have to put something into each app. No other way around it, unfortuneately.
Ah! That's what I was looking for . I was under the impression the system would have it's own queue where the messages were received from the hardware, processed, and then dispatched to the appropriate process/thread. Since this isn't the case, the idea of inserting that code stub into each process to catch them makes sense. Fair enough.
Now, I'm not sure if this is a confusing point, but the "Messaging framework" is a different beast than "windows messaging". The messaging framework is a service that distribute messages using tcp/ip.
Whoops, that's me talking about things I know nothing about again! I didn't know there was such a thing as the Messaging framework to be honest
Kudos to both of you for the quick and detailed responses! Much appreciated!
This space for rent.
|
|
|
|
|
hai there,
i need your valuable information.
i would like to create a text editor using c#.
i got a trouble in displaying line numbers on left side of the TextBox
Also i want the feature 'Add Breakpoint' in a panel near the texteditor.
How can we get the position of a cursor with respect to the control.
Thanks in advance.
Regards,
Shaju
|
|
|
|
|
I suggest you take a look at some open-source applications. You could find a horde of examples on http://www.sourceforge.net[^]. There's no "standard" way of doing this and it greatly depends on your implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Have a look at mine (see link below) It's a helluva lot harder than you mite think (dont look at silly implementations that use a seperate control for line numbers, like #develop)
top secret xacc-ide 0.0.1
|
|
|
|
|
dear friends
i am a new to c#..
plz help me how to run the algorithm whose source code is given in c#. e.g. the source code for the cyclic redundancy check is given in this site..
plz tell me the step by step procedure to run it..
with regards
from gcm
|
|
|
|
|
You should probably ask in the forum for the individual article.
However, I can't imaging why you'd want to run a CRC algorithm on its own, so I can only assume you want to integrate it with something else. It might be better for you to convert the algorithm to the language of your choice.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
|
|
|
|
|
Hi Friends,
I am working on Visual C# .NET. I want to insert one value in Registry and then retrive that value from registry. In VB.NET there is a funtion "SAVESETTING" to store values in registry. Is there any funtion to store values in registry and retriving that values from registry.
If u have any solution for this then please give reply as early as possible
Thank You
Hemant Mane.
|
|
|
|
|
|
I found this brilliant piece of code by Francesco Natali when I was looking for an easy way out.
/* ***************************************
* ModifyRegistry.cs
* ---------------------------------------
* a very simple class
* to read, write, delete and count
* registry values with C#
* ---------------------------------------
* if you improve this code
* please email me your improvement!
* ---------------------------------------
* by Francesco Natali
* - fn.varie@libero.it -
* ***************************************/
using System;
// it's required for reading/writing into the registry:
using Microsoft.Win32;
// and for the MessageBox function:
using System.Windows.Forms;
namespace Utility.ModifyRegistry
{
///
/// An useful class to read/write/delete/count registry keys
///
public class ModifyRegistry
{
private bool showError = false;
///
/// A property to show or hide error messages
/// (default = false)
///
public bool ShowError
{
get { return showError; }
set { showError = value; }
}
private string subKey = "SOFTWARE\\" + Application.ProductName.ToUpper();
///
/// A property to set the SubKey value
/// (default = "SOFTWARE\\" + Application.ProductName.ToUpper())
///
public string SubKey
{
get { return subKey; }
set { subKey = value; }
}
private RegistryKey baseRegistryKey = Registry.LocalMachine;
///
/// A property to set the BaseRegistryKey value.
/// (default = Registry.LocalMachine)
///
public RegistryKey BaseRegistryKey
{
get { return baseRegistryKey; }
set { baseRegistryKey = value; }
}
/* **************************************************************************
* **************************************************************************/
///
/// To read a registry key.
/// input: KeyName (string)
/// output: value (string)
///
public string Read(string KeyName)
{
// Opening the registry key
RegistryKey rk = baseRegistryKey ;
// Open a subKey as read-only
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistrySubKey doesn't exist -> (null)
if ( sk1 == null )
{
return null;
}
else
{
try
{
// If the RegistryKey exists I get its value
// or null is returned.
return (string)sk1.GetValue(KeyName.ToUpper());
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
return null;
}
}
}
/* **************************************************************************
* **************************************************************************/
///
/// To write into a registry key.
/// input: KeyName (string) , Value (object)
/// output: true or false
///
public bool Write(string KeyName, object Value)
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
// I have to use CreateSubKey
// (create or open it if already exits),
// 'cause OpenSubKey open a subKey as read-only
RegistryKey sk1 = rk.CreateSubKey(subKey);
// Save the value
sk1.SetValue(KeyName.ToUpper(), Value);
return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Writing registry " + KeyName.ToUpper());
return false;
}
}
/* **************************************************************************
* **************************************************************************/
///
/// To delete a registry key.
/// input: KeyName (string)
/// output: true or false
///
public bool DeleteKey(string KeyName)
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.CreateSubKey(subKey);
// If the RegistrySubKey doesn't exists -> (true)
if ( sk1 == null )
return true;
else
sk1.DeleteValue(KeyName);
return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Deleting SubKey " + subKey);
return false;
}
}
/* **************************************************************************
* **************************************************************************/
///
/// To delete a sub key and any child.
/// input: void
/// output: true or false
///
public bool DeleteSubKeyTree()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists, I delete it
if ( sk1 != null )
rk.DeleteSubKeyTree(subKey);
return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Deleting SubKey " + subKey);
return false;
}
}
/* **************************************************************************
* **************************************************************************/
///
/// Retrive the count of subkeys at the current key.
/// input: void
/// output: number of subkeys
///
public int SubKeyCount()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists...
if ( sk1 != null )
return sk1.SubKeyCount;
else
return 0;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Retriving subkeys of " + subKey);
return 0;
}
}
/* **************************************************************************
* **************************************************************************/
///
/// Retrive the count of values in the key.
/// input: void
/// output: number of keys
///
public int ValueCount()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists...
if ( sk1 != null )
return sk1.ValueCount;
else
return 0;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Retriving keys of " + subKey);
return 0;
}
}
/* **************************************************************************
* **************************************************************************/
private void ShowErrorMessage(Exception e, string Title)
{
if (showError == true)
MessageBox.Show(e.Message,
Title
,MessageBoxButtons.OK
,MessageBoxIcon.Error);
}
}
}
JV
|
|
|
|
|
Hi all,
I am trying to create a custom project for Visual Studio.Net. Basically, what I need is for a specific kind of project to appear within the wizard and then I need for my specific kind of code page (like .cs pages, .cpp pages), corresponding to a particular extension, to appear and to be able to work with it.
Any ideas on this one?
Any help would be greatly appeciated.
|
|
|
|
|
This question is better suited to the VS.NET IDE forum.
In either case, I don't have a clue what your trying to accompish...
Are you trying to write your own project template? Like a Windows Forms Application or a Web Forms Application...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How I figured it out (and use it quite often) - go to the installation directory for the VC# or VB.NET in the Visual Studio .NET directory and look at the file structure. Creating a new project or item type is as simple as defining a .vsdir file that points to the wizard files in a sibling directory. These files are either simple templates or contain multiple files that you can use variable replacement. VS.NET defines several variables and you can define your own using a set of HTML files for any wizards and a/some javascript file(s).
If you want more information beyond what you can discover for yourself, you'll need to get Visual Studio .NET Enterprise Architect which includes templates and documentation for creating templates. There is some vague information in MSDN Library[^] about this, but it doesn't tell you much beyond what you can discover and most of the time refers you to use the Enterprise Architect project for creating templates.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In fact I have already created an addin that works well and gets opened everytime VS is opened. What I need to do is to open that addin as a TAB (like the .cs code pages, for example)....
any ideas?
|
|
|
|
|
That's what I was talking about. See the sub-directories in C:\Program Files\Microsoft Visual Studio .NET 2003\VC# (the default installation directory for VC#).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hmmm
I don't understand.
these are the folders I have at that location:
CSharpContextItems
CSharpProjectItems
CSharpProjects
DesignerTemplates
eCSharpProjectItems
VC#Wizards
VCPackages
Which one do I have to touch to add a tab with my component?
|
|
|
|
|
The directory names should make it obvious, but if you're not sure - look. Like I said, I had no problems figuring it out.
For instance, I wanted to create an interface item, so I copied the related files for the class file from CSharpProjectItems and VC#Wizards and modified them.
Just explore - it's how the world was founded.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
look, everytime you answer me you say: "explore by yourself."
Would I come here to post a question if I had found an answer by exploring?
I AM exploring, but I try this too because I work with tight deadlines. Is it that bad? or what is the whole point of this forum? As a matter of fact everything can be found by exploring so this forum would be useless if we all applied that policy, huh?
I'm just trying to say: don't assume I'm not exploring. I am. But I ask for help to quicken things.
Now, the reason I ask is because there a very concrete thing I don't know: how to make my addin component appear in a TAB in vs.net, a code-style tab, like a .cs tab. I don't even know if that's possible. Is the answer in the folders you told me? Which one? How?
|
|
|
|
|
Look at the directory names: there's projects, project items, etc. If you actually open the files, it's obvious.
It would take an entire article to tell you exactly what to do. I did tell you were to look, since it seemed like you didn't even know before. Forum members are different, and most of us regulars don't just hand over the answers - you'll never learn anything that way. In this case, though, it's a matter of content length: it would take an entire article but can be discovered in a matter of minutes.
Most of what you need to do you can copy, paste, and modify ever so slightly to get what you want, like copying an existing .vsdir file from CSharpProjectItems and creating your own (works best for an installer) pointing to your own directories and items inside that. Create sub-directories in the VC#Wizards directory. Look at examples like CSharpAddClassWiz.
It's really quite simple. You can add new file types and projects to VS.NET this way.
And I don't know what you mean by "TAB". Do you know now many tabs there are throughout VS.NET? Dozens if not hundreds. If you mean in the toolbox where you'd find Windows Forms, Web Forms, and other components (it's not a "TAB"), then see the ToolBoxItem class documentation in the .NET Framework SDK. The class documentation includes plenty of information and example code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot. I fully understand your reasons and endorse them, too.
By TAB I mean a tab like a code page tab. When you open a .cs file where do you see it in VS? In a code tab! or a .cpp file, etc...
That's what I mean by tab, and that's what I don't see in the files in those folders....
|
|
|
|
|
You mean a window? How am I - or anyone - supposed to help you if you don't use proper terminology. What if I went to a doctor and told them my doodad hurt?
You can't open a component in a window, but that also depends on what you mean by "component" which you mentioned before. A component in .NET is a compiled class that gets instantiated on a Windows Form or UserControl or ASP.NET page or control (among other things).
Before you were talking about tabs, .cs files, and projects. It seemed like you were talking about new project item types (like when you right-click on a project or project folder and select Add New-<Add New Item....
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry
that's what I meant
sorry!
I call that a tab....
Yes, that's what I thought: it can't be done.
Sorry for the inconveniences and thanks a lot.
I hope to have more interesting questions in the near future, and I am sure I will ....
|
|
|
|
|