.NET sends _all_ data to a printer using Raster images. This means if you only send plain taxt to a printer, it still converts it into a raster image. If you communicate with the printer via the Serial port it takes quite a while.
If you only want to send text you can develop a component in VB (VS 6.0) that sends plain text to a printer and use this in .NET.
To get the domain name, you can use Environment.UserDomainName. For the username, you can use Environment.UserName. To get the computer name, use Environment.MachineName. If you want more information than this, you can P/Invoke the Network Management APIs. See the API documentation on MSDN at http://msdn.microsoft.com/library/en-us/netmgmt/netmgmt/network_management.asp[^] for more information about the Network Management API.
Although these are not macros they are much more powerful than the MFC equivalents.
The Debug version will only work in the debug build (or any build where you #define DEBUG).
The Trace version is more for instrumented builds where you want the output to go to a log file of the system event log and it is valid to have available in the release build. The Trace version will only work where you #define TRACE.
See also TraceListener
Also, for future reference: In the next version of .NET the Trace classes are meant to be vastly improved.
To add to that, the DefaultTraceListener will output messages you pass to Trace or Debug to the output window when you're debugging your application in .NET. To write to files, the event log, or any custom targets you can use additional TraceListener implementations even at runtime (we use one for error logging in our app).
You're right, though, it is much better than the various TRACE macros, though - as Colin mentioned - a much better trace facility would be nice and is expected. To elaborate, every message you pass is passed to each TraceListener, regardless of whether or not they want to handle it (based on a TraceSwitch setting or other proprietary filtering). This can hamper performance.
Call me stupid, but after coding for 1 year now, I'm going to ask such a trivial question:
Object o; //Where does o fit in memory?
o = new Object(); //Now what? Instantiated? What's that?!
//Work on o somehow; then: o = some_fuction_that_returns_a_newly_created_object(); //Now?
How about the first o that was allocated? I used the same variable to point to two instances (or at least that's what I think) consequently. What happens to the first instance? What about if I want to destroy this o in memory because I simply don't need it anymore?!
Thank you, I appreciate your patience.
"A good friend, is like a good book: the inside is better than the cover..."
profoundwhispers wrote: Object o; //Where does o fit in memory?
It allocates enough memory on the stack for a reference (pointer) to the actual object (what ever it may eventually be)
profoundwhispers wrote: o = new Object(); //Now what? Instantiated? What's that?!
This allocates memory on the heap for the newly instantiated object.
profoundwhispers wrote: o = some_fuction_that_returns_a_newly_created_object(); //Now?
the actual newly created object will be on the heap. o itself is still a pointer/reference on the stack to that object.
profoundwhispers wrote: How about the first o that was allocated? ... What happens to the first instance?
The garbage collector will remove it from the system when it gets around to it, assuming nothing else is referencing it.
profoundwhispers wrote: What about if I want to destroy this o in memory because I simply don't need it anymore?!
If you don't need it anymore just don't reference it. The garbage collector will free the memory when it gets around to it.
One caveat is objects that have a Dispose() method. These usually have resources that the managed heap in .NET cannot garbage collect efficiently. When you no longer need these objects you should call Dispose(). The garbage collector would eventually Dispose it anyway, but it will take a few attempts at it.
Let me just say I'm a programming newbie. I have this problem that's been irritating me.
I have a list view in my app and I've specified a DataSource for it. I have other functions that are constantly updating the Array that is the DataSource (it's an array of integers, in this case.)
The only way I've found to have the ListView update is to set the DataSource to null and then reassign it. Is there a more elegant way to do this?
I've created an icon-file with a 16x16 icon and selected that file in the "Icon" property of my main form. This changes the icon in the top-left corner of the app, but it doesn't change the icon that appears in the ALT-TAB sequence pop-up. I suppose that I need a 32x32 icon for that purpose, but even if I create a such in the icon file - it still doesn't change from the default .Net icon when running the app. Any ideas ?
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
Either change the App.ico file in your project, or replace it / add a new icon (presumably the same one as which you designated as your Form.Icon) and change the Application Icon to reference that icon in your project properties. You should at least have both a 16x16 and 32x32 icon for your .ico file.
I'm developing a set of Windows form controls that should extend the functionalities of the following classes:
public class MyPushButton : System.Windows.Forms.Button
public class MyCheckbox : System.Windows.Forms.CheckBox
public class MyRadioButton : System.Windows.Forms.RadioButton
I decided to derive a class from each of these base classes in order to get the right notifications from the base class events.
Now these custom controls should apply some graphic effect to the buttons through a set of properties that would be common to all of the "MyXXX" button classes: due to the fact that multiple inheritance is not supported in C#, how can I avoid to have all of the properties and their get/set helpers duplicated in each of the "MyXXX" classes?
After some serious research i've managed to display some balloon tooltips on a notifiyicon, hooked up to a windows form.
But i inteded to write a windows service instead of a form-based application.
Since you need a window handle to run the shell_notifyicon function, needed to display the balloon tooltips, and i don't seem to find the handle from a service, i have a problem
Does anybody know how to get the handle from a windows service, or any way to hook up a balloon tooltip to the notifyicon from a service??
Your service, if run as LocalSystem, will also have to have the "Allow service to interact with desktop" option checked in the Service snap-in. See your Control Panel\Administrative Tools for the snap-in.
public static IntPtr GetHInstance()
In an attempt to create a global hook using WH_KEYBOARD.
The problem I have is it doesn't work. It works globally with WH_KEYBOARD_LL but as soon as I use WH_KEYBOARD it doesn't work at all. This meaning it doesn't capture keyboard strokes in either the windows form or anywhere else. Now Dino's code worked fine for a local hook (aka the form) but I want a global or system hook.
Now I have the class he wrote in an external DLL but there must be something else i am missing. If anyone has any suggestions they would be very much appreciated.
Thanks very much.
Dino Esposito modified project and my test windows form can be found here
The WH_KEYBOARD_LL hook is called in your app. context so can easily be made in C#.
A global WH_KEYBOARD hook however executes in teh context of the app. that is recieving the keyboard message so your code has to be injected into every running process. This is NOT a good idea IMHO. It only seems to work if the m_filterfunc is exported from the DLL in the [EXPORTS] table.
If a hook is in place globally whether it is WH_MOUSE or WH_KEYBOARD or WH_KEYBOARD_LL the hook functions the exact same for each case. Nothing is injected into any running process, it doesn't work like that. A hook is ultimately a callback function that applications register with a particular system event. It is not injected into every running process as you say. Doing this with C# is no different then any other language as I am just using the windows API.
Now I have the code that can capture WH_MOUSE events at the thread or local application level but I need them to be captured at the global or system level. Any suggestions?
I take it you have read the MSDN article on hooks? It states:
....This is because global hook procedures are called in the process context of every application in the desktop, causing an implicit call to the LoadLibrary function for all of those processes....
If you only want to be aware of mouse or keyboard events system wide use a WH_JOURNALRECORD hook. Otherwise write your hook stuff in a standard DLL with an EXPORTS section.