Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private int last_file_count = 0;
- private string path_to_current_user_dektop = "";
- [DllImport("shell32.dll", CharSet = CharSet.Auto)]
- static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
- const uint SHCNE_ASSOCCHANGED = 0x08000000;
- const uint SHCNF_IDLIST = 0x0000;
- public Form1()
- {
- // dodać do Form - Label i Timer
- InitializeComponent();
- timer1.Interval = 1000; // 1000ms = 1s.
- // ustawienie Form w prawym górnym rogu ekranu
- // docelowo napisać kod, który pokaże tylko ikone w "zasobniku"
- int screenWidth = Screen.PrimaryScreen.Bounds.Width;
- this.StartPosition = FormStartPosition.Manual;
- this.Location = new Point((screenWidth - this.Width), 0);
- // pobranie ścieżki do pulpitu zalogowanego użytkownika
- path_to_current_user_dektop = Environment.ExpandEnvironmentVariables(@"%userprofile%\Desktop");
- // zainicjowanie ilości plików na pulpicie
- last_file_count = fileCount();
- // właczenie timera, ktory co 1s sprawdzi zawartość pulpitu
- timer1.Enabled = true;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- int current_file_count = fileCount();
- label1.Text = "Number of files on desktop: " + current_file_count;
- if (current_file_count != last_file_count)
- {
- last_file_count = current_file_count;
- // odśwież zawartośc pulpitu użytkownika
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
- }
- }
- private int fileCount()
- {
- return Directory.GetFiles(path_to_current_user_dektop).Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement