windows之鼠标穿透窗口事件

mousePenetrateWindow.pro

#-------------------------------------------------
#
# Project created by QtCreator 2016-09-22T14:25:32
#
#-------------------------------------------------

QT       += core gui

win32{
    LIBS += -luser32
}

linux{
    QT += x11extras
    LIBS += -lX11 -lXext
}

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = mousePenetrateWindow
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

#ifndef Q_OS_WIN
#include <X11/extensions/shape.h>
#include <QtX11Extras/QX11Info>
#else
#include <windows.h>
#endif

#include <QTimer>

//#include <QDebug>
//#include <qdebug.h>
//#include <QCursor>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//    showFullScreen();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QPoint point = QCursor::pos();
    qDebug() << "cursor pos: " << point;

#ifdef Q_OS_LINUX
    XShapeCombineRectangles(QX11Info::display(), winId(), ShapeInput,0,0, NULL, 0, ShapeSet, YXBanded);
#endif
#ifdef Q_OS_WIN
    // SetWindowPos((HWND)winId(), HWND_BOTTOM, 0, 0,width(), height(), SWP_NOREDRAW);//useless?

    m_intExTemp = GetWindowLong((HWND)winId(), GWL_EXSTYLE);

    SetWindowLong((HWND)winId(), GWL_EXSTYLE, m_intExTemp  | WS_EX_TRANSPARENT | WS_EX_LAYERED);
#endif

    QTimer::singleShot(3000, this, SLOT(timerSlot()));
}

void MainWindow::timerSlot()
{
#ifdef Q_OS_LINUX
    XRectangle* myrect = new XRectangle;
    myrect->x = 0;
    myrect->y = 0;
    myrect->width = width();
    myrect->height = height();
    XShapeCombineRectangles(QX11Info::display(), winId(), ShapeInput, 0, 0, myrect,1,ShapeSet,YXBanded);
#endif
#ifdef Q_OS_WIN
    SetWindowLong((HWND)winId(), GWL_EXSTYLE, m_intExTemp);
#endif
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值