첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Reflection;
using System.Runtime.InteropServices;

#region 쉘 변경 통지하기 - SHChangeNotify(eventID, flag, item1, item2)

/// <summary>
/// 쉘 변경 통지하기
/// </summary>
/// <param name="eventID">이벤트 ID</param>
/// <param name="flag">플래그</param>
/// <param name="item1">항목 1</param>
/// <param name="item2">항목 2</param>
[DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventID, int flag, IntPtr item1, IntPtr item2);

#endregion
#region 윈도우즈 데스크톱과 탐색기 갱신하기 - RefreshWindowsDesktopAndExplorer()

/// <summary>
/// 윈도우즈 데스크톱과 탐색기 갱신하기
/// </summary>
public void RefreshWindowsDesktopAndExplorer()
{
    // 데스크탑을 리프레쉬 한다.
    SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);

    // 열려있는 윈도우즈 탐색기 창을 리프레쉬 한다.
    Guid ShellApplicationCLSID = new Guid("13709620-C279-11CE-A49E-444553540000");

    Type shellApplicationType = Type.GetTypeFromCLSID(ShellApplicationCLSID, true);
 
    object shellApplication = Activator.CreateInstance(shellApplicationType);

    object windows = shellApplicationType.InvokeMember("Windows", BindingFlags.InvokeMethod, null, shellApplication, new object[] { });
 
    Type windowsType = windows.GetType();

    object count = windowsType.InvokeMember("Count", BindingFlags.GetProperty, null, windows, null);

    for(int i = 0; i < (int)count; i++)
    {
        object item = windowsType.InvokeMember("Item", BindingFlags.InvokeMethod, null, windows, new object[] { i });

        Type itemType = item.GetType();
 
        string itemName = (string)itemType.InvokeMember("Name", BindingFlags.GetProperty, null, item, null);

        if(itemName == "Windows Explorer")
        {
            itemType.InvokeMember("Refresh", BindingFlags.InvokeMethod, null, item, null);
        }
    }
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요