VS复制项目
在使用VS的过程中,有的时候我们需要复制我们已经存在的项目.
我们可以先创建一个新的项目.
接着把需要复制的项目的文件复制粘贴到新的项目文件夹中.
不要忘记添加现有项目.
CFrameLessWidgetBase.h
#pragma once
#include <QWidget>
class CFrameLessWidgetBase : public QWidget{
QOBJECT_H
public:
CFrameLessWidgetBase(QWidget* p = nullptr);
~CFrameLessWidgetBase();
private:
protected:
bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override;
private:
int m_nBorderWidth = 10;
};
CFrameLessWidgetBase.cpp
#include "CFrameLessWidgetBase.h"
#include <qt_windows.h>
#include <windows.h>
#include <windowsx.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib,"dwmapi.lib")
CFrameLessWidgetBase::CFrameLessWidgetBase(QWidget* p)
:QWidget(p) {
this->setWindowFlags(Qt::FramelessWindowHint);
}
CFrameLessWidgetBase:: ~CFrameLessWidgetBase() {
};
bool CFrameLessWidgetBase::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) {
MSG* param = static_cast<MSG*>(message);
switch (param->message) {
case WM_NCHITTEST:
{
/*int nX = GET_X_LPARAM(param->lParam) - this->geometry().x();
int nY = GET_Y_LPARAM(param->lParam) - this->geometry().y();*/
QPoint globalPos = QCursor::pos(); // 获取鼠标的全局坐标
QPoint localPos = this->mapFromGlobal(globalPos); // 转换为窗口坐标
int nX = localPos.x(); // 现在的 nX 应该是相对于窗口的坐标
int nY = localPos.y();
//if (childAt(nX, nY) != nullptr)
// return QWidget::nativeEvent(eventType, message, result);
if (nX > m_nBorderWidth && nX < this->width() - m_nBorderWidth &&
nY > m_nBorderWidth && nY < this->height() - m_nBorderWidth) {
if (childAt(nX, nY) != nullptr)
return QWidget::nativeEvent(eventType, message, result);
}
if ((nX > 0) && (nX < m_nBorderWidth))
*result = HTLEFT;
if ((nX > this->width() - m_nBorderWidth) && (nX < this->width()))
*result = HTRIGHT;
if ((nY > 0) && (nY < m_nBorderWidth))
*result = HTTOP;
if ((nY > this->height()