 |
|
 |
Dear Odah,
i have seen your article it's looking like for a beginner rather than for a professional.
My Query is : What if i want to display My Network Places, My Computer,etc., what ever the folders that are residing on the desktop in the combobox?
Is there any possibility,then please tell me.
thanks
tirumal
|
|
|
|
 |
|
|
 |
|
 |
I want to use OnComboDrawItem for my vb.net project , how can I ?
Thanks in advance
Hardik Shah.
|
|
|
|
 |
|
 |
You must us ethis:
[DllImport("kernel32.dll")]
private static extern long GetVolumeInformation(
string PathName,
StringBuilder VolumeNameBuffer,
UInt32 VolumeNameSize,
ref UInt32 VolumeSerialNumber,
ref UInt32 MaximumComponentLength,
ref UInt32 FileSystemFlags,
StringBuilder FileSystemNameBuffer,
UInt32 FileSystemNameSize);
....
public string GetDriveName(string drive)
{
//receives volume name of drive
StringBuilder volname = new StringBuilder(256);
//receives serial number of drive,not in case of network drive(win95/98)
UInt32 sn = new UInt32();
UInt32 maxcomplen = new UInt32();//receives maximum component length
UInt32 sysflags = new UInt32();//receives file system flags
StringBuilder sysname = new StringBuilder(256);//receives the file system name
long retval = new long();//return value
retval = GetVolumeInformation(drive, volname, 256, ref sn, ref maxcomplen,
ref sysflags, sysname, 256);
if (retval != 0) return volname.ToString();
else return "";
}
Oliver Degnan
|
|
|
|
 |
|
 |
Very nice control but there is one problem (and don't feel bad because no one on CodeProject that has implemented an OwnerDraw Combo has figured it out either). When the Width of the drop-down list is smaller the the Widest Item, the Horizontal Scrollbar does NOT appear.
Do you or anyone else know how to do this? I am trying to implement my own OwnerDraw Combo in VB.NET but I can't seem to figure it out. Also, changing the OwnerDraw Style to be "OwnerDrawVariable" and setting the width explicitly does absolutely nothing either.
|
|
|
|
 |
|
 |
[seems like the perfect place to ask this question]
Any idea how to get the icon for a file using .NET.
I know that it's a real mission to do in C++, but I'm hoping that you'll know of an easier way.
Cheers,
Simon
"Every good work of software starts by scratching a developer's personal itch.", Eric S. Raymond
|
|
|
|
 |
|
|
 |
|
 |
==========================
Notes
==========================
1) DWORD are 32bit unsigned integers. Translate it to c# and you have "uint" (long are 64bit integers)
2) [out] params declared as "LPDWORD", so you've to pass them by reference. This can be done adding "ref" keyword before "uint"
1-ITA) Le DWORD sono definite come interi senza segno da 32 bit (double word (2x16bit)). In c# gli interi senza segno di 32 bit sono dichiarati come uint (mentre il long e' di 64 bit)
2-ITA) I parametri passati per memorizzare i valori di ritorno [out], sono passati come puntatori (LP), quindi in c# dobbiamo aggiungere la parola chiave "ref" prima del tipo di dato.
Enjoy.
==========================
Declaration
==========================
[DllImport("kernel32.dll")]
public static extern int GetVolumeInformation
(
string strPathName,
StringBuilder strVolumeNameBuffer,
uint uintVolumeNameSize,
ref uint uintVolumeSerialNumber,
ref uint uintMaximumComponentLength,
ref uint uintFileSystemFlags,
StringBuilder strFileSystemNameBuffer,
uint uintFileSystemNameSize
);
==========================
Using
==========================
string drive = @"C:\";
//receives volume name of drive
StringBuilder volname = new StringBuilder(256);
//receives serial number of drive,not in case of network drive(win95/98)
uint sn= new uint();
uint maxcomplen = new uint();//receives maximum component length
uint sysflags = new uint();//receives file system flags
StringBuilder sysname = new StringBuilder(256);//receives the file system name
int retval= new int();//return value
retval = GetVolumeInformation
(
drive,
volname,
256,
ref sn,
ref maxcomplen,
ref sysflags,
sysname,
256
);
if(retval!=0)
{
label1.Text=volname.ToString() +" " + Convert.ToString(sn, 16);
}
|
|
|
|
 |
|
 |
Is this a good way of programming.... I mean, concerning compatibility issues.....?
Louis
|
|
|
|
 |
|
 |
Hi,
I don't like your solution (Sorry for being so harsh), but it's not acceptable to use your own collection of icons. Instead any application should use the correct system icons. Otherwise your application displays icons incorrectly e.g. for cds with their own icon.
And I have no clue how to make that work correctly on windows xp with .NET. All my attempts failed: The antialiasing didn't work if I converted the information from SHGetFileInfo and the icon look so ugly that I couldn't stand it.
(So you see: I was just that harsh 'cause I couldn't make my own solution work )
Has anyone a clue how to display the correct icons nicely antialiased?
Yours,
Stefan
|
|
|
|
 |
|
 |
You don't like it ??????
Well, I don't either. You are right ,
it should use the icons the shell would
use to represent those drives.
I've already updated my DriveComboBox
so now it use SHGetFileInfo() function
to retrieve those icons.
(I wil post updated demo project very soon,
for those who may not know how to use that
SHGetFileInfo() function exported by Shell32.dll
to retieve information about an objects in the
file system, such as drive roots, folders ,
directories ,or files.)
OK, so I use it, but, as You said, the icons are ugly
,those black pixels around , ,
and the same question :
how to fix those icons?
odah
|
|
|
|
 |
|
 |
Don't be hard on yourself. I really got some usefull info form this program even though I use C++. I had the same problem. Here is the solution in C++, you should be able to adapt it to C#.
#define CX_BITMAP 16
#define CY_BITMAP 16
#define SI_DESKTOP 34
fHiColor = ::GetDeviceCaps(hdc, NUMCOLORS) == -1;
// Create the image list.
if ((himl = ImageList_Create(CX_BITMAP,
CY_BITMAP,
fHiColor ? (ILC_COLOR32|ILC_MASK) : (ILC_COLOR4|ILC_MASK),
NUM_BITMAPS, 0)) == NULL)
return FALSE;
ImageList_SetBkColor(himl, RGB(255,255,255)); //Shell Icons have a black mask
ReleaseDC(hwndTV, hdc);
// Add the bitmaps.
hIcon = ExtractIconEx (_T("SHELL32.DLL"), SI_DESKTOP, NULL, &hIcon, 1);
LoadImage(g_hinst , // small class icon
MAKEINTRESOURCE(5),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
g_nDesktop = ImageList_ReplaceIcon(himl, -1, hIcon); //index = -1 -> append it
DestroyIcon(hIcon);
Setting the background gets rid of teh black pixels.
Cheers, Tim Carpenter (Weariless)
|
|
|
|
 |
|
 |
I saw somewhere (I believe in another article here on CodeProject) that you can get rid of the black pixels by making the color depth be 32-bit (eg in an image list), which allows the alpha channel to work.
|
|
|
|
 |
|
 |
I too didn't like that the control used its own collection of icons.
Second, the first call to GetVolumeInformation is extremely slow.
As both issues wasn't acceptable for me - I chose to hack my own control inspired by this control. You can get it here: http://www.codeproject.com/useritems/FastDriveComboBox.asp[^]
/Michael
|
|
|
|
 |
|
 |
I get the following error when I try to compile this code:
D:\C#Projects\DriveComboBox\Form1.resx Resource transformation for file 'Form1.resx' failed. Invalid ResX input.
|
|
|
|
 |
|
 |
Sorry that's because it is for .NET beta2 ,
sorry, here is the link to updated project:
http://www.megsinet.net/~odach/DriveComboBox2.zip
odah
|
|
|
|
 |
|
 |
How do you get the icon info into the resx file?
|
|
|
|
 |
|
 |
All you have to do is change the guids in the resx file. Microsoft has a tool that can do this for you automatically, it is available at http://go.microsoft.com/fwlink/?LinkId=5888
Soliant soliant@yahoo.com
|
|
|
|
 |
|
 |
Bravo for this article
I've just a question
In C#, long is 64 bits
And you use long for apis GetDriveType and GetVolumeInformation
I'll have to use int which is 32 bits
Could you give me some explications about this ?
Thank's
Xavier
|
|
|
|
 |
|
 |
If you talking about return values:
The function GetDriveType
in Winbase.h is declared like this:
UINT GetDriveType(
LPCTSTR lpRootPathName // root directory
);
so
as you can see the return value is unsigned integer.
The declaration of GetVolumeInformation in the same header
file looks like this:
BOOL GetVolumeInformationW(
IN LPCWSTR lpRootPathName,
OUT LPWSTR lpVolumeNameBuffer,
IN DWORD nVolumeNameSize,
OUT LPDWORD lpVolumeSerialNumber,
OUT LPDWORD lpMaximumComponentLength,
OUT LPDWORD lpFileSystemFlags,
OUT LPWSTR lpFileSystemNameBuffer,
IN DWORD nFileSystemNameSize
);
function returns zero or nonzero value, zero is equivalent to false , and nonzero is equivalent
to true,in C++ this conversion is OK , in C#, there is no conversion between the bool type and other types ,so I could not use BOOL , but I use long instead.
If you use int as return value in this function you would get 1(one) if all the requested information is retrieved .If not all the requested information is retrieved you would get 0(zero).
odah
|
|
|
|
 |