|
Yes it is. Unfortunately, solving your problem with Win32's drag-n-drop is not easy and reading about it is necessary before I could even explain half of the stuff to you (otherwise I end up writing a book! ). So, while you can't be notified of drop operations in another app (unfortunately, this is a problem that many people have asked about), you can use native dragging and dropping to provide a stream when the other application asks for it - just make sure that you use common clipboard formats that the other app supports (like the Windows Shell supports the CF_HDROP while specifying TYMED_ISTREAM to pass a stream reference that the Shell can read, or something like that).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
Can anyone tell me how I can determine how much memory, disk space, and free disk space are on a computer programmatically? This will be displayed on a windows form.
I'm thinking it's got to be in one of the dlls that come with windows, but I don't know which one and what functions to use.
Thanks!
|
|
|
|
|
Instead of P/Invoking native methods, this is a perfect opportunity to use WMI (see the System.Management namespace). In fact, there's already several great tools to help you. This also allows you to query remote computers where the native functions won't always allow you to do that.
VS.NET makes it even easier. Show your Server Explorer tab, expand your computer, then Management Classes, then My Computer and select your computer. You'll notice the property grid has a lot of information you want. Simply drag that to your form and it creates an easy-to-use wrapper class for querying that management information. You can change the computer name and get that information for other computers as well.
For disk infomration, you should've noticed the Disk Volumes class right above My Computer. You can create a management class wrapper for that, too, and then specify the path and get the drive's information.
You could use the following native functions, but querying information for other computers isn't as easy (GetDiskFreeSpaceEx can use UNC paths, but they must have a trailing backslash (\) and require a share on the machine to query):
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern bool GetDiskFreeSpaceEx(string root,
out long freeBytesToCaller,
out long totalBytes,
out long freeBytes);
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatus(out MemoryStatus status);
[StructLayout(LayoutKind.Sequential)]
public struct MemoryStatus
{
public int length;
public int memoryLoad;
public long totalPhysical;
public long availablePhysical;
public long totalPageFile;
public long availablePageFile;
public long totalVirtual;
public long availableVirtual;
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Thanks for your help, but I can not find the System.Management namespace. Where is this namespace located and or how do I add it? I tried using System.Management; but that doesn't work.
Thanks
|
|
|
|
|
Sorry,
I figured out that I didn't add the reference. Hey, it's a Monday morning.
Thanks
|
|
|
|
|
Look at the System.Management namespace
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
object freeSpace = disk.Properties["FreeSpace"].Value;
Jonathan
|
|
|
|
|
I am running an application that uses a managed image list of icons pulled from the System kernel that uses extentions to look them up via a modified version Heath's little GetFileInfo source code.
The problem I have is, while my embeded resources, or any opened from the directory work fine in my XP visualStyle, with the alpha filtered ONLY at 32 bit ImageList settings, those that I pull from the system are still blocky and suffering from alpha textures showing up.
I am not sure what to do about this, I have written an algorythm to convert the pixels to RGB, but that leaves them on a black background. I don't understand why it occurs, as it does not occur else where.
Any ideas as to why?
Cheers
Cata
|
|
|
|
|
By definition, alpha channels require 32-bit images because the first 24 bits are the colors (RGB) while the last 8 bits are the alpha channel.
As far as the problem goes, this has to do with the common controls version. If you use XP Visual Styles (either look at my article detailing this, or - for .NET 1.1 and up - call Application.EnableVisualStyles before calling Application.Run ) most of the image handling code is redirected to common controls 6 (a side-by-side native assembly), which understands alpha channels. If not, the alpha channel gets converted to a close color like you've seen. .NET may understand alpha channels implicitly (which is why your embedded images with alpha channels work), but when pulling icons using file associations, you need enabled XP Visual Styles. This worked for me.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've enabled the VisualStyles, with the DoEvents() methods.
Without those, even the embeded icons show the alpha texture.
I know it works, as the embedded icons, and those that I import from files (I unpacked the system icons from the DLL to experiment with them, and they work too), all come without the alpha.
What I don't understand is, when I construct the bitmaps from an icon handle, pulled from shell32, no matter what I do, the alpha is still there.
It's confusing me, because I can clearly see things working in some areas and others not.
I've set all my image lists to 32bit, and also added numerous 32bit reset points to test whether it was a drop in image quality that caused this. Still no luck.
Any ideas?
Cata
(I have a screen shot of the anomaly, if anyone wants a look. It's confusing indeed...)
|
|
|
|
|
Ok, I found out that the problem lay in the extraction process.
Basicaly, when the icon is pulled from shell32, it was converted straight into a Bitmap, and then returned, before being added to the image list.
By leaving it as an Icon, and backing this up to the point where it is added to the image list, the Alpha is now recognised and removed. I guess that it looks for alpha in icons, but not in bitmaps.
Anyway, I am happy now.
Regards
Cata
|
|
|
|
|
Hello!
I found that the inline code documentation defined on the classes and methods does not get compiled into assembly! When looking into object browser, the documentation is only visible for the items found under project node. When coding in the project referencing the library containing the documentation, I only get class/method/argument names but no single word in addition.
The MSDN documentation says that the /doc compiler option should be used to produce xml file which could be used by IntelliSense - the file should have the same name as the assembly produced. I tried it but with no the effect.
What do I do wrong?
Thanks for any suggestions.
Vasek
VB6, C#, MS DNA, MS.NET
Software Developer
|
|
|
|
|
using: /doc:file
The file should have the same name as the assembly but with xml extension:
MyLib.dll
MyLib.xml
These should be kept together in the same folder.
|
|
|
|
|
Hi, this exactly I made but I made it using IDE, I did not run compiler from the command line. There is /doc configuration option int the project setting. The file was created but the documentation was not inserted to the compiled file.
Could you tell me, whether the /doc: dicrective works for you?
Thanks
Vasek
VB6, C#, MS DNA, MS.NET
Software Developer
|
|
|
|
|
Yes, I also do it using the IDE "XML Documentation File" setting and the documentation is put in the specified .xml documentation file. It is not supposed to be put in the compiled file.
|
|
|
|
|
Hello,
I'm trying to use the Microsoft.Win32.Registry namespace for getting owner information from the registry. I found that this namespace isn't supported by .net compact framework and that i have to use Win Api functions and to import coredll .dll
But I don't know how can I fix my problem:
I have to
[DllImport("coredll.dll")]
and then to use RegCreateKeyEx(..) and RegCreateKeyEx(..)
LONG RegCreateKeyEx ( HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult, LPDWORD lpdwDisposition );
LONG RegQueryValueEx( HKEY hKey, LPCWSTR lpValueName,
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData );
but I don't know how to transform types of parameters for using this functions in c# and to use the macro like HKEY_CURRENT_USER
thank you for your time.
Ramona
|
|
|
|
|
Look at the System.Runtime.InteropServices.MarshalAsAttribute for some interformation. This should be pretty easy, though, and you should understand before proceeding. Basically, any handles become IntPtr , any strings become string (and in the DllImportAttribute you should specify the CharSet that's appropriate), DWORDs (and the like) become int , and structures must also be defined with appropriate attributes like StructLayoutAttribute . You should gain a good understanding of these. You also need to use the ref and out keywords appropriate based on the parameter type and the Platform SDK (PSDK) documentation ([in/out] translates to a ref , while [out] translates to an out ).
As far as macros, you need to download and install the PSDK (if you didn't install it with VS.NET) and find it in the headers (the PSDK usually tells you what header it's in, otherwise search) and see what it's defined as.
Also, you could download a good decompiler like .NET Reflector[^] and look at the code for the Microsoft.Win32.Registry classes, structs, etc. This will give you some good idea of how Microsoft does it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I need to 'associate' a Server Event to a Button via code. I built a Form, a Table, and a Button and I need to get a server event attached to the 'click' method for that button see code snippet below...
HtmlForm frmROPtbl = new HtmlForm();
frmROPtbl.Attributes.Add("runat", "server");
Table maintable = new Table();
maintable.Width = Unit.Percentage(100);
TableRow hdrRow = new TableRow();
TableCell hdrCell0 = new TableCell();
TableCell hdrCell1 = new TableCell();
hdrRow.Width = Unit.Percentage(100);
hdrCell0.Width = Unit.Percentage(50);
hdrCell1.Width = Unit.Percentage(50);
Label hdrLabel = new Label();
hdrLabel.ID = "lblCustomerDesc".ToString();
hdrLabel.Width = Unit.Pixel(360);
Button btnToExcel = new Button();
btnToExcel.ID = "btnToExcel";
btnToExcel.CssClass ="Button".ToString();
btnToExcel.Text = "To Excel";
btnToExcel.Click += new System.EventHandler(this.btnToExcel_Click);
btnToExcel.Attributes.Add("runat", "server");
//* Attach a Server Event to this Button
hdrCell0.Controls.Add(hdrLabel);
hdrCell1.Controls.Add(btnToExcel);
hdrRow.Cells.Add (hdrCell0);
hdrRow.Cells.Add (hdrCell1);
...
Thanks
Andy
(Andrew.Kirin@verizon.net)
|
|
|
|
|
What do you mean by "server" event? Adding the Click event handler automatically renders the correct HTML. If you want the server to watch for something to happen, you can't for so many reasons:- HTTP is by nature non-stateful.
- ASP.NET runs server-side and generates client-side code (HTML, Javascript, images, etc.) that the browser downloads to the user's machine.
- These two do not maintain persistent communications.
- The only way the client can alert the server of a change is by making a new request to get the file (without the use of ActiveX, Java Applets, or using javascript with special automation objects that are different from browser to browser and sometimes not available at all).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
http://www.china-vips.com/bbs/dispbbs.asp?BoardID=12&id=12866&replyID=82911&star=1&skin=
village in my fatherland.
my broken heart
|
|
|
|
|
Hello,
I would like to know if there is some way to use a static library (a .LIB developed using C++) from C#.
Any idea?
Regards
Severino
|
|
|
|
|
Isn't possible. .NET uses assemblies that contain dependency references, assembly attributes, modules (what actually contain the code), embedded resources, and a manifest that lists it all.
This does imply, however, that you could write a library and compile it as a module (only possible with the command-line compiler, csc.exe (C# compiler) using the /t:module parameter. You can then compile an assembly that contains your code plus this module. It's not quite the same thing, but the result is pretty much the same. Again, this is only available with the command-line compiler. VS.NET doesn't support this.
Doing things this way will result in an assembly with two different modules. There is an article at an old hang-out that describes writing assemblies with modules in different languages. The principal is the same even if you use the same language, though: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=466[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Two options:
1) Compile it into a DLL.
2) Write a wrapper using Managed C++.
|
|
|
|
|
I have created a worker thread. Now I would like to create a separate window (form) to watch the progress of the thread. I specifically do NOT want to use an invoke back to the main form because I'm starting several such threads and wish to monitor them independantly. Obviously I would like the worker thread to directly create and show its own form.
Well I can easily create and show a form from the worker thread, however the form is not receiving window events and consequently nothing much happens.
What do I need to do in order to get this form to respond to windows messages?
Any advice people? Thanks Alastair
Only change is constant unless it isn't
|
|
|
|
|
Are there any Application.DoEvents(); calls in the worker thread? Otherwise the form gets no time to process the window messages.
|
|
|
|
|
Ohmygod. Do I feel stupid or what? Thank you John. I have no idea what I was thinking. Anyhow of course I didn't so the poor thread couldn't service events. In partial mitigation it is 11.47pm here and I have flu.
Problem solved. Thanks again!
Only change is constant
|
|
|
|
|