|
i wanna to use the following code to get
hte system imagelist ,but it doesn't works well,the iconCount always equal 5,and so
i can't get the correct imagelist,who can tell me what's wrong with it.
[DllImport("comctl32.dll")]
private static extern int ImageList_GetImageCount( IntPtr himl );
public static ImageList GetSystemImagelist(bool isSmall , bool isSelected )
{
SHFILEINFO info = new SHFILEINFO(true);
int cbInfo = Marshal.SizeOf(info);
SHGFI flags = SHGFI.SHGFI_SYSICONINDEX;
SHIL size ;
if(isSmall == true)
flags |= SHGFI.SHGFI_SMALLICON;
else
flags |= SHGFI.SHGFI_ICON;
if(isSelected == true)
flags |= SHGFI.SHGFI_OPENICON;
ImageList imageList = new ImageList();
IntPtr imageHandle = SHGetFileInfo("C:\\",0,out info, (uint)cbInfo,flags);
IntPtr iconHandle = IntPtr.Zero;
int iconCount = ImageList_GetImageCount(imageHandle);
for (int i = 0; i < iconCount; i++)
{
iconHandle = ImageList_GetIcon(imageHandle, i, 0);
imageList.Images.Add (Icon.FromHandle(iconHandle));
}
return imageList;
}
|
|
|
|
|
FYI, a system image list is the image list kept by the Windows shell for purposes of caching icons. What you're doing is simply getting the associated icon for a file or device.
See my previous reply to a similar thread at http://www.codeproject.com/script/comments/forums.asp?msg=585938&forumid=1649#xx585938xx[^]. This actually uses a fake filename, however. Just set the second parameter to SHGetFileInfo to 0 if you want to get the icon for a real file. This code also inserts into a large and small image list. There is absolutely no reason to P/Invoke any of the Common Control Image List APIs - they are encapsulated by the ImageList already (just as most of the Windows Forms controls encapsulate the Common Controls).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank you very much ,it is so kind of you ; i was confuesd by the usage of c++,in c++ ,i can do it very easily by the following code:
void GetSystemImageList(CImageList * pSmallList, CImageList * pLargeList)
{
SHFILEINFO ssfi, lsfi;
HIMAGELIST hSystemSmallImageList = (HIMAGELIST)
::SHGetFileInfo((LPCTSTR)_T("C:\\"), 0, &ssfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
pSmallList->Attach(hSystemSmallImageList);
HIMAGELIST hSystemLargeImageList = (HIMAGELIST)
::SHGetFileInfo((LPCTSTR)_T("C:\\"), 0, &lsfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_ICON);
pLargeList->Attach(hSystemLargeImageList);
}
|
|
|
|
|
You're still basically doing the same thing with the code I gave you, but to call native APIs in C# or VB.NET you need to P/Invoke native functions and declare the necessary interfaces, structs, and consts. Other languages may require you to do the same thing, but some (like MC++) allow you to call them directly (though in MC++ use of native APIs constitutes a mixed-mode assembly, which has additional CAS restrictions by nature).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Helloz plzz any body help me that ow to capture the desktup and save thi image in a bitmap. plzz guide in a step by step approach.
cheers
Rizwan Ahmed
|
|
|
|
|
jinnbaba wrote:
Helloz plzz any body help me that ow to capture the desktup and save thi image in a bitmap. plzz guide in a step by step approach.
Your english is rough to say the least, however regarding you question there are many articles covering how to P/Invoke the proper GDI functions used to perform this task. In fact a quick search provided this article here on CP: Image Capture[^]
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hello, I have a quick question.
You develop a Windows-based application that enables users to update customer contact information. Your application uses a DataSet object to maintain the customer data while users are reviewing and editing it. When a user finishes updating the data, your application uses the DataSet.WriteXml method to create an XML data file. The tag name of the root element of the XML data file must be <customerinfo>. You need to add code to your application to ensure that this tag name is set correctly. Which code segment should you use?
A . dsCustomer.Namespace = “CustomerInfo”
B . dsCustomer = New DataSet(“CustomerInfo”)
C . dcCustomer.Prefix = “CustomerInfo”
D . dsCustomer.WriteXml(“CustomerInfo”)
I thought it was A, but the book says B.
What do you guys think?
Thank you very much
|
|
|
|
|
I think you just copied and pasted you homework assignment. Try coding it yourself FIRST, then ask specific questions about any C# code issues you run into.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, this is not a homework question.
This is one of the sample questions in one of my books that I'm using to study for the 70-316.
The book said that you use the dataset constructor. However, i saw this question online, and the answer online said to use the namespace property.
I thought the parameter passed to the data set consructor was just the name of the data set. I went to MSDN and looked at the namespace property but I couldnt find anything that it set the root element.
I dont have any coding access right now, and was just wondering if anyone can help me out.
Thank you
|
|
|
|
|
Flack wrote:
The book said that you use the dataset constructor. However, i saw this question online, and the answer online said to use the namespace property.
A namespace can not directly contain a field or method without a class . A namespace provides a way to define scope, thus allowing globally unique types.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Flack wrote:
This is one of the sample questions in one of my books that I'm using to study for the 70-316.
Further proof that certifications don't mean much, huh?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you read the .NET Framework SDK (which will teach you more than a book - especially since certifications typically prove nothing), in order to name the DataSet you pass either the name (which will be the document element, or "root element") to the constructor or instantiate with the default constructor and assign the DataSetName property after its instantiated. Namespace allows you to declare an XML namespace for the DataSet XML document or fragment.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can anyone tell me how can I read from/write to the parallel port in VC#?
Thanx
ahmedadel
|
|
|
|
|
You can't do it directly because Windows abstract the hardware from your app. You'll also not find any support for such operations in the .NET BCL. You'll have to use a specially written .DLL to do the actual writing and reading of ports for you. See http://www.logix4u.net[^] for the .DLL and example code in various languages. IF there is not C# example, you'll have to translate either C++ or VB code to C#.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
NTPort. It has C# examples also.
/\ |_ E X E GG
|
|
|
|
|
i would like to trap the windows state changes when your computer goes into standbye, hibernate, etc., which i believe are defined by ACPI as states S1-S5. can i trap these messages from .NET?
|
|
|
|
|
Implement the IMessageFilter and add your implementation using Application.AddMessageFilter . Each main form is sent the WM_QUERYENDSESSION (0x0011) and WM_ENDSESSION (0x0016) in succession. You can handle these in your IMessageFilter implementation. See the Platform SDK documentation at http://msdn.microsoft.com/library[^] for more information about these messages and what you can (and can't) return (i.e., assign to the Message.Result property), as well as the possible values for the Message.WParam and Message.LParam properties. These values are defined in winuser.h in the Platform SDK, which is downloadable from http://msdn.microsoft.com/platformsdk[^] and is installed by default with Visual Studio.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hmm... maybe i misunderstood your suggestion, but what i am specfically trying to do is have a winform running on a computer, and when that computer goes into stanby or hibernate mode, i want to be able to catch this state change and perform actions based on which state it changed into right before the system goes off into this state.
|
|
|
|
|
And I told you exactly how to do that. You can also use the Microsoft.Win32.SystemEvents.SessionEnding and Microsoft.Win32.SystemEvents.SessionEnded events, but then your code will not be portable to other platforms.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using CultureInfo objects in my application to ensure that the correct localisation is loaded from a set of resources, however I have found that certain cultures are not supported, for example Celtic languages such as "GD" (Scots Gaelic), "CY" (Welsh) or "GA" (Irish Gaelic).
For the moment, I want just to be able to use the CultureInfo object to pull the correct resources from Satellite assemblies. However every route I look at requires a CultureInfo object to be presented somewhere.
Is there any way to extend the CultureInfo so that I can have it accepting cultures that .NET does not intrinsically support? Or is there anyway to pull the resources easily from the correct satellite assembly without having to write lots of addional code mimicking what the existing system does?
CultureInfo does appear to be open to derivation, however I've not seen and indication that it would achieve anything. Can anyone point me in the direction of some links that would get me started on this?
Any help would be appreciated. Thanks.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
You could extend CultureInfo hypothetically, but you'll have to override every virtual member. The CultureInfo ctor won't accept an unrecognized LCID or name.
Getting satellite resources isn't that hard, however. The problem is overriding ResourceManager so that you can tell it which resource assembly to grab for unsupported CultureInfo s.
I have written such code fairly easily (all the power you need is pretty much defined on the Assembly class, like GetSatelliteAssembly ) and have extended the ResourceManager to do so. Either way, you're going to have to write some code. Since the current ResourceManager works with CultureInfo class, you may have the best luck extending CultureInfo and overriding everything necessary (basically, keep your own look-up table of information; currently, localization in .NET P/Invokes some of this functionality from native APIs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I have written such code fairly easily
Rather than re-invent the wheel, do you care to share?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
This code gets a manifest resource stream (identitied by the const StreamResource ) from a satellite assembly. Unfortunately, you'll still need a valid CultureInfo (sorry, it's been a while since I wrote this; it might still help, though):
public static Stream GetZipResourceStream(CultureInfo culture)
{
Assembly asm = typeof(SiteBuilder).Assembly;
CultureInfo neutral = GetNeutralResourcesLanguage(asm);
if (culture == null || !culture.Equals(neutral))
{
Version v = GetSatelliteContractVersion(asm);
if (v == null) v = asm.GetName().Version;
try
{
asm = asm.GetSatelliteAssembly(culture, v);
}
catch
{
try
{
asm = asm.GetSatelliteAssembly(culture.Parent, v);
}
catch {}
}
}
Stream s = asm.GetManifestResourceStream(SiteResource);
return s;
}
internal static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return CultureInfo.InvariantCulture;
NeutralResourcesLanguageAttribute[] attrs =
(NeutralResourcesLanguageAttribute[])
a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false);
if (attrs.Length == 0) return CultureInfo.InvariantCulture;
try
{
return new CultureInfo(attrs[0].CultureName);
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidNeutralResourcesLanguageCulture",
a.ToString(), attrs[0].CultureName), "a", ex);
}
}
internal static Version GetSatelliteContractVersion(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return null;
SatelliteContractVersionAttribute[] attrs =
(SatelliteContractVersionAttribute[])
a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);
if (attrs.Length == 0) return null;
try
{
return new Version(attrs[0].Version);
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidSatelliteContractVersion",
a.ToString(), attrs[0].Version), "a", ex);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Unfortunately, you'll still need a valid CultureInfo
Can't have everything!
Thanks for your help.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hello!
This is my first post. I have a little problem. I have build a small Windows Form application. It has 1 form and a couple of buttons and textboxes and a datagrid. I want to build a simple search. So, if I type a letter "D" in a textbox, I want in a DataGrid a list of all names that starts with a "D". If I type further a letter "a" and "v" for example, I would get a "Dave" names for example.
This is what I programmed so far:
static void FilterData()<br />
{<br />
<br />
try<br />
{<br />
<br />
string strFilter = "SELECT Avtosalon.Ime," + <br />
"Naslov.Ulica, Naslov.PostnaSt, Naslov.Kraj, Avtosalon.Telefon," + <br />
"Avtosalon.EPosta, Avtosalon.Vodja, Avtosalon.OdpiralniCas " +<br />
"FROM Avtosalon INNER JOIN Naslov ON Avtosalon.IDNaslov = Naslov.IDNaslov ";<br />
<br />
if (!MyForm.txtIme.Focused)<br />
{<br />
strFilter = strFilter + "WHERE Avtosalon.Ime LIKE '" + MyForm.txtIme.Text + "%'";<br />
if (MyForm.txtUlica.Focused)<br />
strFilter = strFilter + " AND Naslov.Ulica LIKE '" + MyForm.txtUlica.Text + "%'";<br />
else if (MyForm.txtPostnaSt.Focused)<br />
strFilter = strFilter + " AND Naslov.PostnaSt LIKE '" + MyForm.txtPostnaSt.Text + "%'";<br />
else if (MyForm.txtKraj.Focused)<br />
strFilter = strFilter + " AND Naslov.Kraj LIKE '" + MyForm.txtKraj.Text + "%'";<br />
else if (MyForm.txtTelefon.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Telefon LIKE '" + MyForm.txtTelefon.Text + "%'";<br />
else if (MyForm.txtEPosta.Focused)<br />
strFilter = strFilter + " AND Avtosalon.EPosta LIKE '" + MyForm.txtEPosta.Text + "%'";<br />
else if (MyForm.txtVodja.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Vodja LIKE '" + MyForm.txtVodja.Text + "%'";<br />
else if (MyForm.txtOdpiralniCas.Focused)<br />
strFilter = strFilter + " AND Avtosalon.OdpiralniCas LIKE '" + MyForm.txtOdpiralniCas.Text + "%'";<br />
} <br />
<br />
MyDataSet = new DataSet();<br />
MyDataAdapter = new SqlDataAdapter(strFilter,conn); <br />
MyDataAdapter.Fill(MyDataSet,"Avtosalon"); <br />
MyDataAdapter.Dispose();<br />
MyForm.BeginInvoke(CallDataBindToDataGrid);<br />
strFilter = null;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
static void DataBindToDataGrid()<br />
{<br />
<br />
MyForm.gridAvtosalon.DataMember = "Avtosalon"; <br />
MyForm.gridAvtosalon.DataSource = MyDataSet;<br />
MyDataSet = null;<br />
MyDataAdapter = null;<br />
}
private void txtIme_TextChanged(object sender, System.EventArgs e)<br />
{<br />
try<br />
{<br />
UpdateThread = new Thread(UpdateThreadStart);<br />
UpdateThread.Name = "Update Thread";<br />
UpdateThread.IsBackground = true;<br />
UpdateThread.Start();<br />
<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}
So, the problem is, when I type in a textbox, I get an error message "There is an open DataReader associated with this
Connection wich must be closed first" and I don't use DataReader at all. Could you help me, couse I study this now for
days and I can't see where is a problem. Thank in advance.
|
|
|
|
|