• 文件或文件夹改变后,发信号让系统刷新


    以下方法都无法刷新 Navigation Pane

    /*
    notifychanges.c - Notify win32 subsystem and running programs of globals
    changes such as system environment variables.
    Copyright (c) 2015, Amit Bakshi <ambakshi at gmail dot com>
    All rights reserved.
    Distributed under the BSD License. See included LICENSE for details.
    */

    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0503
    #endif

    #include <windows.h>
    #include <shlobj.h>
    #include <stdlib.h>

    #ifdef _MSC_VER
    #pragma comment(lib,"user32.lib")
    #pragma comment(lib,"shell32.lib")
    #pragma comment(lib,"kernel32.lib")
    #endif

    int Win32_Notifychanges() {
        DWORD* dwRes;
        const char* lParam = "Environment";
        int timeout = 5, r;

        SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, 0, 0); // Works on both dir and file
        // SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); // Behavior is same as the above
        // SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, 0, 0); // No effect

         //Both no effects.
        r = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)lParam, SMTO_BLOCK, timeout * 1000, NULL);
        printf("r %d ", r);
        if (r != 0) {
            r = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_BLOCK, timeout * 1000, NULL) != 0;
            printf("r again %d ", r);
        }
        return r;
        return 0;
    }

    int main()
    {
        Win32_Notifychanges();
        return 0;
    }


  • 相关阅读:
    C#中,对Equals()、ReferenceEquals()、==的理解
    C#语言中的Main()可以返回int值
    C#中支持的运算符
    C#中,对象格式化的理解
    正则表达式
    .NET三年
    C#中,可重载的运算符
    c#中,const成员和readonly成员的区别
    c#中,struct和class的区别
    jQuery制作图片旋转效果
  • 原文地址:https://www.cnblogs.com/liujx2019/p/12530981.html
Copyright © 2020-2023  润新知