static quint64 getTickCount() { resolveLibs(); // This avoids a division by zero and disables the high performance counter if it's not available if (counterFrequency > 0) { LARGE_INTEGER counter; if (QueryPerformanceCounter(&counter)) { return counter.QuadPart; } else { qWarning("QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded."); return 0; } } #ifndef Q_OS_WINRT if (ptrGetTickCount64) return ptrGetTickCount64(); static quint32 highdword = 0; static quint32 lastval = 0; quint32 val = GetTickCount(); if (val < lastval) ++highdword; lastval = val; return val | (quint64(highdword) << 32); #else // !Q_OS_WINRT // ptrGetTickCount64 is always set on WinRT but GetTickCount is not available return ptrGetTickCount64(); #endif // Q_OS_WINRT }
/*! * ExtendFrameIntoClientArea. * * This controls the rendering of the frame inside the window. * Note that passing margins of -1 (the default value) will completely * remove the frame from the window. * * \note you should not call enableBlurBehindWindow before calling * this functions * * \a enable tells if the blur should be enabled or not */ bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int right, int bottom) { Q_ASSERT(widget); Q_UNUSED(left); Q_UNUSED(top); Q_UNUSED(right); Q_UNUSED(bottom); bool result = false; #ifdef Q_WS_WIN if (resolveLibs()) { QLibrary dwmLib(QString::fromAscii("dwmapi")); HRESULT hr = S_OK; MARGINS m = {left, right, top, bottom}; hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m); if (SUCCEEDED(hr)) { result = true; windowNotifier()->addWidget(widget); } widget->setAttribute(Qt::WA_TranslucentBackground, result); } #endif return result; }
QString QHostInfo::localDomainName() { resolveLibs(); if (ptrGetNetworkParams == NULL) return QString(); // couldn't resolve FIXED_INFO info, *pinfo; ULONG bufSize = sizeof info; pinfo = &info; if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) { pinfo = (FIXED_INFO *)malloc(bufSize); if (!pinfo) return QString(); // try again if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) { free(pinfo); return QString(); // error } } QString domainName = QUrl::fromAce(pinfo->DomainName); if (pinfo != &info) free(pinfo); return domainName; }
QElapsedTimer::ClockType QElapsedTimer::clockType() { resolveLibs(); if (counterFrequency > 0) return PerformanceCounter; else return TickCounter; }
bool QSystemTrayIconSys::trayMessage(DWORD msg) { resolveLibs(); if (!(ptrShell_NotifyIcon)) return false; QT_WA({ return trayMessageW(msg); }, { return trayMessageA(msg);
static QList<QNetworkInterfacePrivate *> interfaceListing() { resolveLibs(); if (ptrGetAdaptersAddresses != NULL) return interfaceListingWinXP(); else if (ptrGetAdaptersInfo != NULL) return interfaceListingWin2k(); // failed return QList<QNetworkInterfacePrivate *>(); }
/*! * 检查 DWM 是否开启 * */ bool QtWin::isCompositionEnabled() { #ifdef Q_WS_WIN if (resolveLibs()) { HRESULT hr = S_OK; BOOL isEnabled = false; hr = pDwmIsCompositionEnabled(&isEnabled); if (SUCCEEDED(hr)) return isEnabled; } #endif return false; }
/*! * 返回当前窗口颜色. */ QColor QtWin::colorizatinColor() { QColor resultColor = QApplication::palette().window().color(); #ifdef Q_WS_WIN if (resolveLibs()) { DWORD color = 0; BOOL opaque = FALSE; QLibrary dwmLib(QString::fromAscii("dwmapi")); HRESULT hr = S_OK; hr = pDwmGetColorizationColor(&color, &opaque); if (SUCCEEDED(hr)) resultColor = QColor(color); } #endif return resultColor; }
/*! * 对一个widget实现Aero效果. * */ bool QtWin::enableAeroWindow(QWidget *widget, bool enable) { Q_ASSERT(widget); bool result = false; #ifdef Q_WS_WIN if (resolveLibs()) { DWM_BLURBEHIND bb = {0}; HRESULT hr = S_OK; bb.fEnable = enable; bb.dwFlags = DWM_BB_ENABLE; bb.hRgnBlur = NULL; widget->setAttribute(Qt::WA_TranslucentBackground, enable); widget->setAttribute(Qt::WA_NoSystemBackground, enable); hr = pDwmenableAeroWindow(widget->winId(), &bb); if (SUCCEEDED(hr)) { result = true; windowNotifier()->addWidget(widget); } } #endif return result; }