修复BUG
parent
f8ea83257a
commit
169c445dce
|
@ -5,6 +5,7 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#include "windowsx.h"
|
||||
#pragma comment (lib,"user32.lib")
|
||||
#endif
|
||||
|
||||
|
@ -274,8 +275,10 @@ bool FramelessDialog::nativeEvent(const QByteArray &eventType, void *message, lo
|
|||
return true;
|
||||
} else if (msg->message == WM_NCHITTEST) {
|
||||
//计算鼠标对应的屏幕坐标
|
||||
long x = LOWORD(msg->lParam);
|
||||
long y = HIWORD(msg->lParam);
|
||||
//这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
|
||||
//官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
QPoint pos = mapFromGlobal(QPoint(x, y));
|
||||
|
||||
//判断当前鼠标位置在哪个区域
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#include "windowsx.h"
|
||||
#pragma comment (lib,"user32.lib")
|
||||
#endif
|
||||
|
||||
|
@ -274,8 +275,10 @@ bool FramelessMainWindow::nativeEvent(const QByteArray &eventType, void *message
|
|||
return true;
|
||||
} else if (msg->message == WM_NCHITTEST) {
|
||||
//计算鼠标对应的屏幕坐标
|
||||
long x = LOWORD(msg->lParam);
|
||||
long y = HIWORD(msg->lParam);
|
||||
//这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
|
||||
//官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
QPoint pos = mapFromGlobal(QPoint(x, y));
|
||||
|
||||
//判断当前鼠标位置在哪个区域
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#include "windowsx.h"
|
||||
#pragma comment (lib,"user32.lib")
|
||||
#endif
|
||||
|
||||
|
@ -274,8 +275,10 @@ bool FramelessWidget::nativeEvent(const QByteArray &eventType, void *message, lo
|
|||
return true;
|
||||
} else if (msg->message == WM_NCHITTEST) {
|
||||
//计算鼠标对应的屏幕坐标
|
||||
long x = LOWORD(msg->lParam);
|
||||
long y = HIWORD(msg->lParam);
|
||||
//这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
|
||||
//官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
QPoint pos = mapFromGlobal(QPoint(x, y));
|
||||
|
||||
//判断当前鼠标位置在哪个区域
|
||||
|
|
|
@ -990,24 +990,58 @@ bool QUIHelper::ipLive(const QString &ip, int port, int timeout)
|
|||
timer.setSingleShot(true);
|
||||
timer.start(timeout);
|
||||
|
||||
//主动测试下连接
|
||||
QTcpSocket tcpSocket;
|
||||
QObject::connect(&tcpSocket, SIGNAL(connected()), &eventLoop, SLOT(quit()));
|
||||
tcpSocket.connectToHost(ip, port);
|
||||
eventLoop.exec();
|
||||
|
||||
//判断最终状态
|
||||
bool ok = (tcpSocket.state() == QAbstractSocket::ConnectedState);
|
||||
return ok;
|
||||
}
|
||||
|
||||
QString QUIHelper::getHtml(const QString &url)
|
||||
bool QUIHelper::download(const QString &url, const QString &fileName, int timeout)
|
||||
{
|
||||
QByteArray data = getHtml(url, timeout);
|
||||
if (!data.isEmpty()) {
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
file.write(data);
|
||||
file.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray QUIHelper::getHtml(const QString &url, int timeout)
|
||||
{
|
||||
//初始化网络请求对象
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
|
||||
//局部的事件循环,不卡主界面
|
||||
QEventLoop eventLoop;
|
||||
QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
|
||||
|
||||
//设置超时 5.15开始自带了超时时间函数 默认30秒
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
|
||||
manager.setTransferTimeout(timeout);
|
||||
#else
|
||||
QTimer timer;
|
||||
QObject::connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
|
||||
timer.setSingleShot(true);
|
||||
timer.start(timeout);
|
||||
#endif
|
||||
|
||||
//启动网络请求
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
|
||||
QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
|
||||
eventLoop.exec();
|
||||
|
||||
//读取结果
|
||||
QByteArray data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
return QString(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
QString QUIHelper::getNetIP(const QString &html)
|
||||
|
@ -1091,12 +1125,6 @@ QString QUIHelper::getValue(quint8 value)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool QUIHelper::isWebOk()
|
||||
{
|
||||
//能接通百度IP 115.239.211.112 说明可以通外网
|
||||
return ipLive("www.baidu.com", 80);
|
||||
}
|
||||
|
||||
bool QUIHelper::isCustomUI = false;
|
||||
int QUIHelper::showMessageBox(const QString &info, int type, int closeSec, bool exec)
|
||||
{
|
||||
|
|
|
@ -164,8 +164,11 @@ public:
|
|||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
//下载网络文件
|
||||
static bool download(const QString &url, const QString &fileName, int timeout = 1000);
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
static QByteArray getHtml(const QString &url, int timeout = 1000);
|
||||
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
|
@ -177,8 +180,6 @@ public:
|
|||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
//定义标志位启用系统的还是自定义的对话框
|
||||
static bool isCustomUI;
|
||||
|
|
Loading…
Reference in New Issue