In the previous project, you need to select a photo from mobile and use Microsoft. windows Mobile. forms. the selectpicturedialog component has not found any problems before. However, more and more users have reported that they have not responded by clicking the "select" button and cannot reproduce it by themselves. After looking at the page, I realized that after a period of time, the client's data volume increases and the cached data increases while the program is running. The larger the memory occupied by the system, the dialog box for selecting photos cannot be displayed, A flash. The openfiledialog in CF can only access files under my document due to mobile security restrictions. So I want to find a file selection dialog box component on mobile. Codeproject found a good one. Unfortunately, it was written by a foreigner in C ++ and is not componentized by COM, so CF cannot be used. Write one by yourself. Results:
Considering the performance on mobile, layer-by-layer loading is adopted during the initialization tree, And the next layer of structure is loaded only when a node is expanded.
The getfileinfo API is used to retrieve the folder icon and file icon. This example is available on http://pinvoke.net.
# Region geticonbyfilename
[Dllimport ("coredll. dll", entrypoint = "shgetfileinfo")]
Public static extern int getfileinfo (string pszpath, int dwfileattributes, ref fileinfostruct psfi, int cbfileinfo, int uflags );
[structlayout (layoutkind. sequential)]
public struct fileinfostruct
{< br> Public intptr hicon;
Public int iicon;
Public int dwattributes;
[financialas (unmanagedtype. byvaltstr, sizeconst = 260)]
Public String szdisplayname;
[financialas (unmanagedtype. byvaltstr, sizeconst = 80)]
Public String sztypename;
}
Public Enum fileinfoflags: int
{
Shgfi_icon = 0x000000100, // get icon
Shgfi_displayname = 0x000000200, // get display name
Shgfi_typename = 0x000000400, // get type name
Shgfi_attributes = 0x000000800, // get attributes
Shgfi_iconlocation = 0x000001000, // get icon location
Shgfi_exetype = 0x000002000, // return EXE type
Shgfi_sysiconindex = 0x000004000, // get System icon Index
Shgfi_linkoverlay = 0x000008000, // put a link overlay on icon shgfi_selected = 0x000010000, // show icon in selected state
Shgfi_attr_specified = 0x000020000, // get only specified attributes
Shgfi_largeicon = 0x000000000, // get large icon
Shgfi_smallicon = 0x000000001, // get small icon
Shgfi_openicon = 0x000000002, // get open icon
Shgfi_shelliconsize = 0x000000004, // get shell size icon
Shgfi_pidl = 0x000000008, // pszpath is a pidl
Shgfi_usefileattributes = 0x000000010, // use passed dwfileattribute
Shgfi_addoverlays = 0x000000020, // apply the appropriate Overlays
Shgfi_overlayindex = 0x000000040 // get the index of the overlay
}
Private icon geticonbyfilename (string path)
{
Fileinfostruct _ INFO = new fileinfostruct ();
Getfileinfo (path, 0, ref _ INFO, Marshal. sizeof (_ INFO ),
(INT) (fileinfoflags. shgfi_icon | fileinfoflags. shgfi_smallicon ));
Return icon. fromhandle (_ INFO. hicon );
}
# Endregion
When the node is expanded, the Windows folder is specially processed. It is very slow to open this system folder on mobile. If there are no special requirements, you can
The systemenabled attribute is set to false.
Private void treeviewinclubeforeexpand (Object sender, treeviewcanceleventargs E)
{
If (systemenabled = false & E. node. Text. tolower () = "Windows ")
{
E. Cancel = true;
Return;
}
If (E. Action = treeviewaction. Expand)
{
E. node. nodes. Clear ();
Listview1.items. Clear ();
Imagelist2.images. Clear ();
String Path = E. node. fullpath. Replace ("\\\\",@"\");
Addnode (E. node, new directoryinfo (PATH ));
}
}
Source code download