Pocket PC中资源管理器的实现

在用.net做pocket pc的程序中,我们经常想使用系统的Imagelist来和listview或treeview捆绑来显示不同后缀文件的不同图标。

但在.net编程中对系统的Imagelist的读取比较麻烦,我们需要借助api来实现。主要的办法是P/Invoke.

但在.net编程中对系统的Imagelist的读取比较麻烦,我们需要借助api来实现。主要的办法是P/Invoke.

用sendMessag来改变listview或treeview的IMagelist.

用sendMessag来改变listview或treeview的IMagelist.

public static void SetListViewImageList(

IntPtr hwnd,

ListView listView,

SysImageList sysImageList,

bool forStateImages

)

{

IntPtr wParam = (IntPtr)LVSIL_NORMAL;

if (sysImageList.ImageListSize == SysImageListSize.smallIcons)

{

wParam = (IntPtr)LVSIL_SMALL;

}

if (forStateImages)

{

wParam = (IntPtr)LVSIL_STATE;

}

SendMessage(

hwnd,

LVM_SETIMAGELIST,

wParam,

sysImageList.Handle);

}

public static void SetTreeViewImageList(

IntPtr hwnd,

TreeView treeView,

SysImageList sysImageList,

bool forStateImages

)

{

IntPtr wParam = (IntPtr)TVSIL_NORMAL;

if (forStateImages)

{

wParam = (IntPtr)TVSIL_STATE;

}

SendMessage(

hwnd,

TVM_SETIMAGELIST,

wParam,

sysImageList.Handle);

}

用EVC对“SHgetfileinfo”API函数进行包装,代码如下:

extern "C" __declspec (dllexport) DWORD SHABgetfileinfo(LPCTSTR pszFileName)

{

SHFILEINFO ssfi;

return SHGetFileInfo(pszFileName, 0, &ssfi,

sizeof(SHFILEINFO),

SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

}

extern "C" __declspec (dllexport) int SHIndexfileinfo(LPCTSTR pszFileName)

{

SHFILEINFO ssfi;

SHGetFileInfo(pszFileName, 0, &ssfi, sizeof(SHFILEINFO),

SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

return ssfi.iIcon;

}

extern "C" __declspec (dllexport) int SHIndexfileinfoEx(LPCTSTR pszFileName,DWORD dwAttr, UINT dwFlag)

{

SHFILEINFO ssfi;

SHGetFileInfo(pszFileName, 0, &ssfi, sizeof(SHFILEINFO),

dwFlag);

return ssfi.iIcon;

}

在需要使用系统imagelist的地方作如下的调用:

sysilsSmall = new SysImageList(SysImageListSize.smallIcons);

this .tvFolders.Capture = true ;

IntPtr hwnd1 = GetCapture();

this .tvFolders.Capture = false ;

this .lvFiles.Capture = true ;

IntPtr hwnd2 = GetCapture();

SysImageListHelper.SetTreeViewImageList(

hwnd1,

tvFolders,

sysilsSmall,

false );

SysImageListHelper.SetListViewImageList(

hwnd2,

lvFiles,

sysilsSmall,

false );

this .lvFiles.Capture = false ;

窗体实现分割功能,主要是处理鼠标的down, move, up实践来完成不同部分的分割,这个对于pocket pc这样的屏幕限制系统来说相当有趣。

private void FileExplorer_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e)

{

this .picSplitter.Top=e.Y-4;

this .picSplitter.Visible= true ;

this .Moving= true ;

}

private void FileExplorer_MouseMove( object sender, System.Windows.Forms.MouseEventArgs e)

{

if ( this .Moving)

{

this .picSplitter.Top=e.Y;

}

}

private void FileExplorer_MouseUp( object sender, System.Windows.Forms.MouseEventArgs e)

{

this .tvFolders.Height=e.Y-5;

this .lvFiles.Top= this .tvFolders.Top+ this .tvFolders.Height+10;

this .lvFiles.Height= this .Height- this .lvFiles.Top;

this .picSplitter.Visible= false ;

this .Moving= false ;

this .ModeChange= false ;

}

按照不同的列标头来排序:

按照不同的列标头来排序:

private void Sort( ref ArrayList AL, string SortBy, bool Asc)

{

IComparer myComparer= null ;

switch (SortBy)

{

case "Name":

if (Asc)

myComparer= new SortNameAsc();

else

myComparer= new SortNameDesc();

break ;

case "Size":

if (Asc)

myComparer= new SortSizeAsc();

else

myComparer= new SortSizeDesc();

break ;

case "Type":

if (Asc)

myComparer= new SortTypeAsc();

else

myComparer= new SortTypeDesc();

break ;

case "Modified":

if (Asc)

myComparer= new SortModifiedAsc();

else

myComparer= new SortModifiedDesc();

break ;

}

AL.Sort(myComparer);

}

public class SortNameDesc : IComparer

{

int IComparer.Compare( Object x, Object y )

<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-font-kerning: 0pt; mso-hansi-font-family: "Times

Published At
Categories with Web编程
Tagged with
comments powered by Disqus