hyprunz

Switch hide flag on Windows with Qt

May 13th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool switchHideFlagOnWindows(const QString file)
  2. {
  3. #ifdef Q_OS_WIN32
  4.     LPCWSTR path = (const wchar_t *)file.utf16();
  5.     DWORD attr = GetFileAttributesW(path);
  6.  
  7.     if(attr == INVALID_FILE_ATTRIBUTES) {
  8.         qDebug() << "Windowssystem error: INVALID_FILE_ATTRIBUTES";
  9.         return false;
  10.     }
  11.  
  12.     DWORD nattr = attr ^ FILE_ATTRIBUTE_HIDDEN;
  13.  
  14.     bool ret = SetFileAttributesW(path, nattr);
  15.  
  16.     if(!ret) {
  17.         qDebug() << "Windowssystem couldn´t switch flag for hide!";
  18.     }
  19.  
  20.     return ret;
  21. #else
  22.     //On non windows os this function will return always true - so that this function don´t block the process
  23.     Q_UNUSED(file);
  24.     return true;
  25. #endif
  26. }
Advertisement
Add Comment
Please, Sign In to add comment