Smartphone pocketpc folder Management source code

Source: Internet
Author: User

I. listviewhelper. CS

Using system;

Namespace RDP
{
/// <Summary>
/// Summary description for helper.
/// </Summary>
Public class listviewhelper
{
Private const uint lvm_getextendedlistviewstyle = 0x1000 + 55;
Private const uint lvm_setextendedlistviewstyle = 0x1000 + 54;
Private const uint lvm_gettopindex = 0x1000 + 39;
Private const int lvs_ex_gridlines = 0x1;
Private const int lvs_ex_gradient = 0x20000000;

Public listviewhelper ()
{
}

Public static void setgradient (system. Windows. Forms. listview)
{
Listview. Capture = true;
Intptr hlist = getcapture ();
Sendmessage (hlist, lvm_setextendedlistviewstyle, 0, lvs_ex_gradient );
Listview. Capture = false;
Listview. Refresh ();
}

Public static int gettopindex (system. Windows. Forms. listview)
{
Listview. Capture = true;
Intptr hwnd = getcapture ();
Int topindex = sendmessage (hwnd, lvm_gettopindex, 0, 0 );
Listview. Capture = false;
Listview. Refresh ();
Return topindex;
}

Public static void setgridlines (system. Windows. Forms. listview)
{
Listview. Capture = true;
Intptr hwnd = getcapture ();
Int extendedstyle = sendmessage (hwnd, lvm_getextendedlistviewstyle, 0, 0 );
Extendedstyle | = lvs_ex_gridlines;
Sendmessage (hwnd, lvm_setextendedlistviewstyle, 0, extendedstyle );
Listview. Capture = false;
Listview. Refresh ();
}

# Region APIs
[System. runtime. interopservices. dllimport ("coredll. dll")]
Private Static extern intptr getcapture ();

[System. runtime. interopservices. dllimport ("coredll. dll")]
Private Static extern int sendmessage (intptr hwnd, uint wmsg, int wparam, int lparam );
# Endregion
}
}
Ii. simplecomparer. CS

Using system;
Using system. collections;

Namespace RDP
{
/// <Summary>
/// This is a simple comparer class.
/// </Summary>
Public class simplecomparer: icomparer
{
Int icomparer. Compare (Object X, object y)
{
Return (New caseinsensitivecomparer (). Compare (x, y );
}
}

}

Iii. Folder. CS

Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. IO;

Namespace UI
{
Public Delegate void setnamedelegate (string name );
Public Delegate void setattributesdelegate (fileattributes );

/// <Summary>
/// Summary of folder.
/// </Summary>
Public class Folder: system. Windows. Forms. Form
{
Private system. Windows. Forms. mainmenu mainmenu1;
Private system. Windows. Forms. menuitem mi_main;
Private system. Windows. Forms. menuitem menuitem2;
Private system. Windows. Forms. menuitem mi_play;
Private system. Windows. Forms. menuitem mi_del;
Private system. Windows. Forms. imagelist imagelist1;
Private system. Windows. Forms. menuitem mi_exit;
Private system. Windows. Forms. listview listview1;
Private system. Windows. Forms. columnheader itemscolumnheader;

Private const string updir = "..";
Private string path;

Public folder ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
System. Resources. ResourceManager resources = new system. Resources. ResourceManager (typeof (folder ));
This. mainmenu1 = new system. Windows. Forms. mainmenu ();
This. mi_main = new system. Windows. Forms. menuitem ();
This. menuitem2 = new system. Windows. Forms. menuitem ();
This. mi_play = new system. Windows. Forms. menuitem ();
This. mi_del = new system. Windows. Forms. menuitem ();
This. mi_exit = new system. Windows. Forms. menuitem ();
This. imagelist1 = new system. Windows. Forms. imagelist ();
This. listview1 = new system. Windows. Forms. listview ();
This. itemscolumnheader = new system. Windows. Forms. columnheader ();
//
// Mainmenu1
//
This. mainmenu1.menuitems. Add (this. mi_main );
This. mainmenu1.menuitems. Add (this. menuitem2 );
//
// Mi_main
//
This. mi_main.text = "Main Interface ";
This. mi_main.click + = new system. eventhandler (this. mi_main_click );
//
// Menuitem2
//
This. menuitem2.menuitems. Add (this. mi_play );
This. menuitem2.menuitems. Add (this. mi_del );
This. menuitem2.menuitems. Add (this. mi_exit );
This. menuitem2.text = "option ";
//
// Mi_play
//
This. mi_play.enabled = false;
This. mi_play.text = "playing ";
This. mi_play.click + = new system. eventhandler (this. mi_play_click );
//
// Mi_del
//
This. mi_del.text = "delete ";
This. mi_del.click + = new system. eventhandler (this. mi_del_click );
//
// Mi_exit
//
This. mi_exit.text = "quit ";
This. mi_exit.click + = new system. eventhandler (this. mi_exit_click );
//
// Imagelist1
//
This. imagelist1.images. Add (system. Drawing. Image) (resources. GetObject ("resource "))));
This. imagelist1.images. Add (system. Drawing. Image) (resources. GetObject ("resource1 "))));
This. imagelist1.images. Add (system. Drawing. Image) (resources. GetObject ("resource2 "))));
This. imagelist1.imagesize = new system. Drawing. Size (16, 16 );
//
// Listview1
//
This. listview1.columns. Add (this. itemscolumnheader );
This. listview1.fullrowselect = true;
This. listview1.headerstyle = system. Windows. Forms. columnheaderstyle. None;
This. listview1.smallimagelist = This. imagelist1;
This. listview1.view = system. Windows. Forms. View. details;
This. listview1.itemactivate + = new system. eventhandler (this. listviewincluitemactivate );
This. listview1.keyup + = new system. Windows. Forms. keyeventhandler (this. listview1_keyup );
//
// Itemscolumnheader
//
This. itemscolumnheader. Text = "items ";
This. itemscolumnheader. Length = 170;
//
// Folder
//
This. clientsize = new system. Drawing. Size (170,172 );
This. Controls. Add (this. listview1 );
This. Menu = This. mainmenu1;
This. Text = "folder ";
This. Load + = new system. eventhandler (this. folder_load );

}
# Endregion

# Region setattributes

Public void setattributes (fileattributes)
{
Listviewitem LVI = This. listview1.items [This. listview1.selectedindices [0];
// Bool isfolder = LVI. imageindex = 1;
If (LVI. imageindex = 0 | LVI. imageindex = 1)
{
Directoryinfo di = new directoryinfo (path + LVI. Text );
Di. Attributes = fileattributes;
}
Else
{
Fileinfo Fi = new fileinfo (path + LVI. Text );
Fi. Attributes = fileattributes;
}
}
# Endregion

// Static void main ()
//{
// Application. Run (new folder ());
//}

Private void folder_load (Object sender, system. eventargs E)
{
RDP. listviewhelper. setgradient (this. listview1 );

// Set the current path
String BS = path. directoryseparatorchar. tostring ();
// This. Path = BS + "Storage" + BS + "My Documents" + BS;
Path = BS;

This. bindlistview ();
}

# Region bindlistview

Private void bindlistview ()
{
Cursor. Current = cursors. waitcursor;
Listviewitem LVI;
This. listview1.beginupdate ();
This. listview1.items. Clear ();

// If it is not the root node
If (path. length> 1)
{
// Add the parent path to be returned
LVI = new listviewitem (updir );
LVI. imageindex = 0;
This. listview1.items. Add (LVI );
}

// Add Directories
String [] dirs = directory. getdirectories (PATH );
Arraylist list = new arraylist (dirs. Length );
For (INT I = 0; I <dirs. length; I ++)
List. Add (dirs [I]);
List. Sort (New RDP. simplecomparer ());
Foreach (string dir in List)
{
LVI = new listviewitem (path. getfilename (DIR ));
LVI. imageindex = 1;
This. listview1.items. Add (LVI );
}

// Add files
String [] files = directory. getfiles (PATH );

List = new arraylist (files. Length );
For (INT I = 0; I <files. length; I ++)
List. Add (files [I]);
List. Sort (New RDP. simplecomparer ());
Foreach (string file in List)
{
If (path. getfilename (file). tostring (). tolower (). endswith (". MP3 "))
{
LVI = new listviewitem (path. getfilename (File ));
LVI. imageindex = 2;
This. listview1.items. Add (LVI );
}
}
This. listview1.endupdate ();

If (this. listview1.items. Count> 0)
{
This. listview1.items [0]. Selected = true;
This. listview1.items [0]. Focused = true;
}

Cursor. Current = cursors. default;
}
# Endregion

# Region listview1_itemactivate

Private void listviewincluitemactivate (Object sender, system. eventargs E)
{
Cursor. Current = cursors. waitcursor;
Listviewitem LVI = This. listview1.items [This. listview1.selectedindices [0];
Bool isfolder = LVI. imageindex = 1;
If (LVI. Text = updir)
{
Path = path. substring (0, path. substring (0, path. Length-1). lastindexof (path. directoryseparatorchar) + 1 );
This. bindlistview ();
}
Else if (isfolder)
{
Path + = LVI. Text + path. directoryseparatorchar;
This. bindlistview ();
}
Else
{
RDP. ShellExecute. Start (path + LVI. Text );
}
Cursor. Current = cursors. default;


}

Private void listview1_keyup (Object sender, keyeventargs E)
{
Int I = 0;
Int lineno = 0;

If (E. keycode = keys. Left) | (E. keycode = keys. Right ))
{
E. Handled = true;
I = RDP. listviewhelper. gettopindex (this. listview1 );
Lineno = This. listview1.selectedindices [0]-I;
}
Switch (E. keycode)
{
Case keys. Right:
I + = 19;
If (I> This. listview1.items. Count)
I = This. listview1.items. Count-1;
Break;

Case keys. left:
I-= 10;
If (I <0)
I = 0;
Break;
}
If (E. Handled)
{
This. listview1.ensurevisible (I );
I = RDP. listviewhelper. gettopindex (this. listview1) + lineno;
Cursor. Current = cursors. waitcursor;
This. listview1.beginupdate ();
This. listview1.items [I]. Selected = true;
This. listview1.items [I]. Focused = true;
This. listview1.endupdate ();
Cursor. Current = cursors. default;
}

}
# Endregion

# Region menu events

Private void mi_main_click (Object sender, system. eventargs E)
{
Ui. Main main = new main ();
Main. Show ();
}

Private void mi_play_click (Object sender, system. eventargs E)
{

}

Private void mi_del_click (Object sender, system. eventargs E)
{
Listviewitem LVI = This. listview1.items [This. listview1.selectedindices [0];
Bool isfile = LVI. imageindex = 2;
If (isfile)
{
Dialogresult result = MessageBox. Show ("are you sure you want to delete it? "," Deletion prompt ", messageboxbuttons. yesno, messageboxicon. Question, messageboxdefaultbutton. button1 );

If (result = dialogresult. Yes)
{
RDP. xml. del_playlistcontent (path + LVI. Text );
RDP. xml. del_content (path + LVI. Text );
File. Delete (path + LVI. Text );
This. bindlistview ();
}
}
 
}

Private void mi_exit_click (Object sender, system. eventargs E)
{
Dialogresult result = MessageBox. Show ("are you sure you want to exit? "," Exit prompt ", messageboxbuttons. yesno, messageboxicon. Question, messageboxdefaultbutton. button1 );

If (result = dialogresult. Yes)
{
Application. Exit ();
}
}

# Endregion


}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.