DEV Community

海前 王
海前 王

Posted on

透明窗体拖动

include // MFC 核心和标准组件

include // Windows API 函数

class CMyFrameWnd : public CFrameWnd {
public:
CMyFrameWnd() {
Create(NULL, _T("Transparent Draggable Window"), WS_POPUP, CRect(0, 0, 300, 200));
}

protected:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) override {
return TRUE; // 不创建子窗口
}

afx_msg void OnPaint() {
    CPaintDC dc(this); // device context for painting
    // 在这里可以进行绘图操作
}

afx_msg LRESULT OnNcHitTest(CPoint point) {
    LRESULT nHitTest = CFrameWnd::OnNcHitTest(point);
    return (nHitTest == HTCLIENT) ? HTCAPTION : nHitTest;
}

afx_msg void OnLButtonDown(UINT nFlags, CPoint point) {
    CFrameWnd::OnLButtonDown(nFlags, point);
    PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}

afx_msg void OnSize(UINT nType, int cx, int cy) {
    CFrameWnd::OnSize(nType, cx, cy);
    Invalidate(); // 使窗口重新绘制
}

DECLARE_MESSAGE_MAP()
Enter fullscreen mode Exit fullscreen mode

};

BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
ON_WM_PAINT()
ON_WM_NCHITTEST()
ON_WM_LBUTTONDOWN()
ON_WM_SIZE()
END_MESSAGE_MAP()

class CMyApp : public CWinApp {
public:
virtual BOOL InitInstance() {
CMyFrameWnd* pFrame = new CMyFrameWnd;
m_pMainWnd = pFrame;

    pFrame->ShowWindow(SW_SHOW);
    pFrame->UpdateWindow();

    return TRUE;
}
Enter fullscreen mode Exit fullscreen mode

};

CMyApp theApp;

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay